Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use import.meta when strictly necessary #8940

Merged
merged 6 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
VirtualTim marked this conversation as resolved.
Show resolved Hide resolved
script_url = "import.meta.url"
else:
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
Expand Down
4 changes: 4 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down