-
Notifications
You must be signed in to change notification settings - Fork 10
/
emscripten.patch
48 lines (46 loc) · 2.66 KB
/
emscripten.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
diff --git a/src/shell.js b/src/shell.js
index b8c9f7185..f760f752f 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -175,7 +175,7 @@ var quit_ = (status, toThrow) => {
#if SHARED_MEMORY && !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
// before the page load. In non-MODULARIZE modes generate it here.
-var _scriptName = (typeof document != 'undefined') ? document.currentScript?.src : undefined;
+var _scriptName = (typeof document != 'undefined' && document.currentScript?.tagName.toUpperCase() === 'SCRIPT') ? document.currentScript.src : undefined;
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
@@ -375,7 +375,7 @@ if (ENVIRONMENT_IS_SHELL) {
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
scriptDirectory = self.location.href;
- } else if (typeof document != 'undefined' && document.currentScript) { // web
+ } else if (typeof document != 'undefined' && document.currentScript?.tagName.toUpperCase() === 'SCRIPT') { // web
scriptDirectory = document.currentScript.src;
}
#if MODULARIZE
diff --git a/src/shell_minimal.js b/src/shell_minimal.js
index 756784324..77225acce 100644
--- a/src/shell_minimal.js
+++ b/src/shell_minimal.js
@@ -143,7 +143,7 @@ var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == '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
// before the page load. In non-MODULARIZE modes generate it here.
-var _scriptName = (typeof document != 'undefined') ? document.currentScript?.src : undefined;
+var _scriptName = (typeof document != 'undefined' && document.currentScript?.tagName.toUpperCase() === 'SCRIPT') ? document.currentScript.src : undefined;
#endif
#if ENVIRONMENT_MAY_BE_NODE
diff --git a/tools/link.py b/tools/link.py
index b7cb3c77d..f869ea991 100644
--- a/tools/link.py
+++ b/tools/link.py
@@ -2414,7 +2414,7 @@ def modularize():
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
script_url = 'import.meta.url'
else:
- script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"
+ script_url = "(typeof document != 'undefined' && document.currentScript?.tagName.toUpperCase() === 'SCRIPT') ? document.currentScript.src : undefined"
if shared.target_environment_may_be('node'):
script_url_node = "if (typeof __filename != 'undefined') _scriptName = _scriptName || __filename;"
src = '''%(node_imports)s