From 1fab77c071277bdb06fe598fd42bf1ebcdf3adfe Mon Sep 17 00:00:00 2001 From: Moritz Duge Date: Thu, 26 Sep 2024 18:13:31 +0200 Subject: [PATCH] Append em-pthread id to the web worker name. Simplifies picking a web worker when using browser debug tools. --- src/library_pthread.js | 4 ++++ src/shell.js | 2 +- src/shell_minimal.js | 2 +- tools/link.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/library_pthread.js b/src/library_pthread.js index dda54a72c37e..f0b2ee0a0e77 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -405,7 +405,11 @@ var LibraryPThread = { #if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER // This is the way that we signal to the Web Worker that it is hosting // a pthread. +#if ASSERTIONS + 'name': 'em-pthread-' + PThread.nextWorkerID, +#else 'name': 'em-pthread', +#endif #endif }; #if EXPORT_ES6 && USE_ES6_IMPORT_META diff --git a/src/shell.js b/src/shell.js index b8c9f71854d2..909222d4a18e 100644 --- a/src/shell.js +++ b/src/shell.js @@ -112,7 +112,7 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR // The way we signal to a worker that it is hosting a pthread is to construct // it with a specific name. -var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread'; +var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread'); #if MODULARIZE && ASSERTIONS if (ENVIRONMENT_IS_PTHREAD) { diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 7567843242bf..97214e1eba36 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -138,7 +138,7 @@ function ready() { // MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments // coincide. var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function'; -var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread'; +var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread'); #if !MODULARIZE // 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 diff --git a/tools/link.py b/tools/link.py index b7cb3c77ddcc..d98e74fd0955 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2458,7 +2458,7 @@ def modularize(): # when running in MODULARIZE mode we need use this to know if we should # run the module constructor on startup (true only for pthreads). if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER: - src += "var isPthread = globalThis.self?.name === 'em-pthread';\n" + src += "var isPthread = globalThis.self?.name?.startsWith('em-pthread');\n" # In order to support both web and node we also need to detect node here. if settings.ENVIRONMENT_MAY_BE_NODE: src += "var isNode = typeof globalThis.process?.versions?.node == 'string';\n"