Skip to content

Commit f530ed0

Browse files
authored
Append worker id to web worker names. (#22644)
Simplifies picking a web worker when using browser debug tools.
1 parent 4db36c1 commit f530ed0

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/library_pthread.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ var LibraryPThread = {
405405
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
406406
// This is the way that we signal to the Web Worker that it is hosting
407407
// a pthread.
408+
#if ASSERTIONS
409+
'name': 'em-pthread-' + PThread.nextWorkerID,
410+
#else
408411
'name': 'em-pthread',
412+
#endif
409413
#endif
410414
};
411415
#if EXPORT_ES6 && USE_ES6_IMPORT_META

src/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR
112112

113113
// The way we signal to a worker that it is hosting a pthread is to construct
114114
// it with a specific name.
115-
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread';
115+
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread');
116116

117117
#if MODULARIZE && ASSERTIONS
118118
if (ENVIRONMENT_IS_PTHREAD) {

src/shell_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function ready() {
138138
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
139139
// coincide.
140140
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
141-
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread';
141+
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread');
142142

143143
#if !MODULARIZE
144144
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@ def modularize():
24582458
# when running in MODULARIZE mode we need use this to know if we should
24592459
# run the module constructor on startup (true only for pthreads).
24602460
if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER:
2461-
src += "var isPthread = globalThis.self?.name === 'em-pthread';\n"
2461+
src += "var isPthread = globalThis.self?.name?.startsWith('em-pthread');\n"
24622462
# In order to support both web and node we also need to detect node here.
24632463
if settings.ENVIRONMENT_MAY_BE_NODE:
24642464
src += "var isNode = typeof globalThis.process?.versions?.node == 'string';\n"

0 commit comments

Comments
 (0)