加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mozilla_docs.txt 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
xdmal 提交于 2022-03-14 10:09 . format repair
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
The definitions of some interfaces implemented in jsapi/workers/worker.cpp are released under Mozilla license.
The definitions and functions of these interfaces are consistent with the standard interfaces under mozila license,
but the implementation of specific functions is independent and self-developed.
All interfaces are described in d.ts, the following is the interface written in d.ts under to Mozilla license
export interface WorkerOptions {
type?: "classic" | "module";
name?: string;
shared?: boolean;
}
export interface Event {
readonly type: string;
readonly timeStamp: number;
}
interface ErrorEvent extends Event {
readonly message: string;
readonly filename: string;
readonly lineno: number;
readonly colno: number;
readonly error: Object;
}
declare interface MessageEvent<T = Object> extends Event {
readonly data: T;
}
export interface PostMessageOptions {
transfer?: Object[];
}
export interface EventListener {
(evt: Event): void | Promise<void>;
}
type MessageType = "message" | "messageerror";
declare interface EventTarget {
addEventListener(
type: string,
listener: EventListener
): void;
dispatchEvent(event: Event): boolean;
removeEventListener(
type: string,
callback?: EventListener
): void;
removeAllListener(): void;
}
declare interface WorkerGlobalScope extends EventTarget {
readonly name: string;
onerror?: (ev: ErrorEvent) => void;
readonly self: WorkerGlobalScope & typeof globalThis;
}
declare interface DedicatedWorkerGlobalScope extends WorkerGlobalScope {
onmessage?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
onmessageerror?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) => void;
close(): void;
postMessage(messageObject: Object, transfer: Transferable[]): void;
postMessage(messageObject: Object, options?: PostMessageOptions): void;
}
declare namespace worker {
class Worker extends EventTarget {
constructor(scriptURL: string, options?: WorkerOptions);
onexit?: (code: number) => void;
onerror?: (err: ErrorEvent) => void;
onmessage?: (event: MessageEvent) => void;
onmessageerror?: (event: MessageEvent) => void;
postMessage(message: Object, transfer: ArrayBuffer[]): void;
postMessage(message: Object, options?: PostMessageOptions): void;
terminate(): void;
}
const parentPort: DedicatedWorkerGlobalScope;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化