-
Notifications
You must be signed in to change notification settings - Fork 10
/
emscripten.patch
48 lines (46 loc) · 2.71 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 0010048cf..6304b367b 100644
--- a/src/shell.js
+++ b/src/shell.js
@@ -154,7 +154,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) {
@@ -350,7 +350,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 9e8b30392..2a4ea8178 100644
--- a/src/shell_minimal.js
+++ b/src/shell_minimal.js
@@ -137,7 +137,7 @@ var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-
#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 76b6e521b..367c36de5 100644
--- a/tools/link.py
+++ b/tools/link.py
@@ -2445,7 +2445,7 @@ export default async function init(moduleArg = {}) {
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;"
if settings.MODULARIZE == 'instance':