Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings: define types for worker and messaging bindings #40143

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tsconfig.json
Expand Up @@ -4,9 +4,11 @@
"files": [
"./typings/internalBinding/fs.d.ts",
"./typings/internalBinding/http_parser.d.ts",
"./typings/internalBinding/messaging.d.ts",
"./typings/internalBinding/options.d.ts",
"./typings/internalBinding/serdes.d.ts",
"./typings/internalBinding/util.d.ts",
"./typings/internalBinding/worker.d.ts",
"./typings/internalBinding.d.ts",
"./typings/primordials.d.ts"
],
Expand Down
3 changes: 3 additions & 0 deletions typings/internalBinding.d.ts
Expand Up @@ -439,3 +439,6 @@ declare function InternalBinding(binding: 'config'): {
bits: number,
hasDtrace: boolean
}
declare function InternalBinding(binding: 'symbols'): {
[name: string]: symbol;
}
32 changes: 32 additions & 0 deletions 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;
};
32 changes: 32 additions & 0 deletions 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;
};