Skip to content

Commit ced8467

Browse files
committed
typings: define types for worker and messaging bindings
PR-URL: #40143 Reviewed-By: James M Snell <[email protected]>
1 parent 9a2b94a commit ced8467

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"files": [
55
"./typings/internalBinding/fs.d.ts",
66
"./typings/internalBinding/http_parser.d.ts",
7+
"./typings/internalBinding/messaging.d.ts",
78
"./typings/internalBinding/options.d.ts",
89
"./typings/internalBinding/serdes.d.ts",
910
"./typings/internalBinding/util.d.ts",
11+
"./typings/internalBinding/worker.d.ts",
1012
"./typings/internalBinding.d.ts",
1113
"./typings/primordials.d.ts"
1214
],
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
declare namespace InternalMessagingBinding {
2+
class MessageChannel {
3+
port1: MessagePort;
4+
port2: MessagePort;
5+
}
6+
7+
class MessagePort {
8+
private constructor();
9+
postMessage(message: any, transfer?: any[] | null): void;
10+
start(): void;
11+
close(): void;
12+
ref(): void;
13+
unref(): void;
14+
}
15+
16+
class JSTransferable {}
17+
}
18+
19+
20+
declare function InternalBinding(binding: 'messaging'): {
21+
DOMException: typeof import('internal/per_context/domexception').DOMException;
22+
MessageChannel: typeof InternalMessagingBinding.MessageChannel;
23+
MessagePort: typeof InternalMessagingBinding.MessagePort;
24+
JSTransferable: typeof InternalMessagingBinding.JSTransferable;
25+
stopMessagePort(port: typeof InternalMessagingBinding.MessagePort): void;
26+
checkMessagePort(port: unknown): boolean;
27+
drainMessagePort(port: typeof InternalMessagingBinding.MessagePort): void;
28+
receiveMessageOnPort(port: typeof InternalMessagingBinding.MessagePort): any;
29+
moveMessagePortToContext(port: typeof InternalMessagingBinding.MessagePort, context: any): typeof InternalMessagingBinding.MessagePort;
30+
setDeserializerCreateObjectFunction(func: (deserializeInfo: string) => any): void;
31+
broadcastChannel(name: string): typeof InternalMessagingBinding.MessagePort;
32+
};

typings/internalBinding/worker.d.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
declare namespace InternalWorkerBinding {
2+
class Worker {
3+
constructor(
4+
url: string | URL | null,
5+
env: object | null | undefined,
6+
execArgv: string[] | null | undefined,
7+
resourceLimits: Float64Array,
8+
trackUnmanagedFds: boolean);
9+
startThread(): void;
10+
stopThread(): void;
11+
ref(): void;
12+
unref(): void;
13+
getResourceLimits(): Float64Array;
14+
takeHeapSnapshot(): object;
15+
loopIdleTime(): number;
16+
loopStartTime(): number;
17+
}
18+
}
19+
20+
declare function InternalBinding(binding: 'worker'): {
21+
Worker: typeof InternalWorkerBinding.Worker;
22+
getEnvMessagePort(): InternalMessagingBinding.MessagePort;
23+
threadId: number;
24+
isMainThread: boolean;
25+
ownsProcessState: boolean;
26+
resourceLimits?: Float64Array;
27+
kMaxYoungGenerationSizeMb: number;
28+
kMaxOldGenerationSizeMb: number;
29+
kCodeRangeSizeMb: number;
30+
kStackSizeMb: number;
31+
kTotalResourceLimitCount: number;
32+
};

0 commit comments

Comments
 (0)