mirror of
https://github.com/openharmony/js_api_module.git
synced 2026-07-19 18:23:43 -04:00
dc83af0525
For internal issues raised by Huawei, modify README files, related copyright information, etc. Related issue: https://gitee.com/openharmony/js_worker_module/issues/I4XAYE Signed-off-by: xdmal <maxiaodong16@huawei.com>
95 lines
2.9 KiB
Plaintext
95 lines
2.9 KiB
Plaintext
/*
|
|
* 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;
|
|
} |