diff --git a/emcc.py b/emcc.py index 66e58c65bfcae..e55c0a24d8294 100755 --- a/emcc.py +++ b/emcc.py @@ -2991,7 +2991,9 @@ def modularize(): # after document.currentScript is gone, so we save it. # (when MODULARIZE_INSTANCE, an instance is created # immediately anyhow, like in non-modularize mode) - if shared.Settings.EXPORT_ES6: + # In EXPORT_ES6 + USE_PTHREADS the 'thread' is actually an ES6 module webworker running in strict mode, + # so doesn't have access to 'document'. In this case use 'import.meta' instead. + if shared.Settings.EXPORT_ES6 and shared.Settings.USE_PTHREADS: script_url = "import.meta.url" else: script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined" diff --git a/src/shell.js b/src/shell.js index d7c17226ab3b1..0e25079035d7b 100644 --- a/src/shell.js +++ b/src/shell.js @@ -89,8 +89,12 @@ if (Module['ENVIRONMENT']) { #if USE_PTHREADS && (!MODULARIZE || MODULARIZE_INSTANCE) // In MODULARIZE mode _scriptDir needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there // before the page load. In non-MODULARIZE modes generate it here. +#if EXPORT_ES6 +var _scriptDir = import.meta.url; +#else var _scriptDir = (typeof document !== 'undefined' && document.currentScript) ? document.currentScript.src : undefined; #endif +#endif // `/` should be present at the end if `scriptDirectory` is not empty var scriptDirectory = '';