Skip to content

Commit ab4f042

Browse files
authored
Add node check to pthread_esm_startup. NFC (#25948)
This is not strictly necessary today since node is the only place we can currently use full ESM Wasm integration, but still better to be correct here.
1 parent 8f1e949 commit ab4f042

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/pthread_esm_startup.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ console.log("Running pthread_esm_startup");
1414
#endif
1515

1616
#if ENVIRONMENT_MAY_BE_NODE
17-
// Create as web-worker-like an environment as we can.
18-
var worker_threads = await import('worker_threads');
19-
global.Worker = worker_threads.Worker;
20-
var parentPort = worker_threads['parentPort'];
21-
parentPort.on('message', (msg) => global.onmessage?.({ data: msg }));
22-
Object.assign(globalThis, {
23-
self: global,
24-
postMessage: (msg) => parentPort['postMessage'](msg),
25-
});
17+
if ({{{ nodeDetectionCode() }}}) {
18+
// Create as web-worker-like an environment as we can.
19+
var worker_threads = await import('worker_threads');
20+
global.Worker = worker_threads.Worker;
21+
var parentPort = worker_threads['parentPort'];
22+
parentPort.on('message', (msg) => global.onmessage?.({ data: msg }));
23+
Object.assign(globalThis, {
24+
self: global,
25+
postMessage: (msg) => parentPort['postMessage'](msg),
26+
});
27+
}
2628
#endif
2729

2830
self.onmessage = async (msg) => {

0 commit comments

Comments
 (0)