diff options
author | Michaël Zasso <targos@protonmail.com> | 2021-09-18 17:49:05 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-09-26 10:42:07 +0200 |
commit | 0eb3420febc1d6b44390f4b929d500255edc7dfb (patch) | |
tree | f7798280e70e496060d8e6375b79d4155de183ad /typings | |
parent | 2b02d2f844439f4a131eae9bc394ec1bd5ba4755 (diff) | |
download | node-new-0eb3420febc1d6b44390f4b929d500255edc7dfb.tar.gz |
typings: define types for worker and messaging bindings
PR-URL: https://github.com/nodejs/node/pull/40143
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'typings')
-rw-r--r-- | typings/internalBinding/messaging.d.ts | 32 | ||||
-rw-r--r-- | typings/internalBinding/worker.d.ts | 32 |
2 files changed, 64 insertions, 0 deletions
diff --git a/typings/internalBinding/messaging.d.ts b/typings/internalBinding/messaging.d.ts new file mode 100644 index 0000000000..ca5be84848 --- /dev/null +++ b/typings/internalBinding/messaging.d.ts @@ -0,0 +1,32 @@ +declare namespace InternalMessagingBinding { + class MessageChannel { + port1: MessagePort; + port2: MessagePort; + } + + class MessagePort { + private constructor(); + postMessage(message: any, transfer?: any[] | null): void; + start(): void; + close(): void; + ref(): void; + unref(): void; + } + + class JSTransferable {} +} + + +declare function InternalBinding(binding: 'messaging'): { + DOMException: typeof import('internal/per_context/domexception').DOMException; + MessageChannel: typeof InternalMessagingBinding.MessageChannel; + MessagePort: typeof InternalMessagingBinding.MessagePort; + JSTransferable: typeof InternalMessagingBinding.JSTransferable; + stopMessagePort(port: typeof InternalMessagingBinding.MessagePort): void; + checkMessagePort(port: unknown): boolean; + drainMessagePort(port: typeof InternalMessagingBinding.MessagePort): void; + receiveMessageOnPort(port: typeof InternalMessagingBinding.MessagePort): any; + moveMessagePortToContext(port: typeof InternalMessagingBinding.MessagePort, context: any): typeof InternalMessagingBinding.MessagePort; + setDeserializerCreateObjectFunction(func: (deserializeInfo: string) => any): void; + broadcastChannel(name: string): typeof InternalMessagingBinding.MessagePort; +}; diff --git a/typings/internalBinding/worker.d.ts b/typings/internalBinding/worker.d.ts new file mode 100644 index 0000000000..2fc7f9272d --- /dev/null +++ b/typings/internalBinding/worker.d.ts @@ -0,0 +1,32 @@ +declare namespace InternalWorkerBinding { + class Worker { + constructor( + url: string | URL | null, + env: object | null | undefined, + execArgv: string[] | null | undefined, + resourceLimits: Float64Array, + trackUnmanagedFds: boolean); + startThread(): void; + stopThread(): void; + ref(): void; + unref(): void; + getResourceLimits(): Float64Array; + takeHeapSnapshot(): object; + loopIdleTime(): number; + loopStartTime(): number; + } +} + +declare function InternalBinding(binding: 'worker'): { + Worker: typeof InternalWorkerBinding.Worker; + getEnvMessagePort(): InternalMessagingBinding.MessagePort; + threadId: number; + isMainThread: boolean; + ownsProcessState: boolean; + resourceLimits?: Float64Array; + kMaxYoungGenerationSizeMb: number; + kMaxOldGenerationSizeMb: number; + kCodeRangeSizeMb: number; + kStackSizeMb: number; + kTotalResourceLimitCount: number; +}; |