Skip to content

Commit 12a447b

Browse files
committed
Simplify
1 parent e9bb8de commit 12a447b

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

emcc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3916,9 +3916,9 @@ def modularize():
39163916
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
39173917
script_url = 'import.meta.url'
39183918
else:
3919-
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined"
3919+
script_url = "typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : ''"
39203920
if shared.target_environment_may_be('node'):
3921-
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;"
3921+
script_url_node = "if (typeof __filename !== 'undefined') _scriptDir = __filename;"
39223922
src = '''%(node_imports)s
39233923
var %(EXPORT_NAME)s = (() => {
39243924
var _scriptDir = %(script_url)s;

src/shell.js

+11-23
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,15 @@ var ENVIRONMENT_IS_WASM_WORKER = Module['$ww'];
144144
#if SHARED_MEMORY && !MODULARIZE
145145
// 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
146146
// before the page load. In non-MODULARIZE modes generate it here.
147-
var _scriptDir;
148-
147+
#if EXPORT_ES6 && USE_ES6_IMPORT_META
148+
var _scriptDir = import.meta.url;
149+
#else
150+
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : '';
149151
#if ENVIRONMENT_MAY_BE_NODE
150-
if (ENVIRONMENT_IS_NODE) {
151-
_scriptDir = __filename;
152-
} else
152+
if (typeof __filename !== 'undefined') _scriptDir = __filename;
153153
#endif // ENVIRONMENT_MAY_BE_NODE
154-
#if ENVIRONMENT_MAY_BE_WORKER
155-
if (ENVIRONMENT_IS_WORKER) {
156-
_scriptDir = self.location.href;
157-
} else
158-
#endif // ENVIRONMENT_MAY_BE_WORKER
159-
#if ENVIRONMENT_MAY_BE_WEB
160-
if (typeof document != 'undefined' && document.currentScript) { // web
161-
_scriptDir = document.currentScript.src;
162-
} else
163-
#endif // ENVIRONMENT_MAY_BE_WEB
164-
_scriptDir = undefined;
165-
#endif // SHARED_MEMORY && !MODULARIZE
154+
#endif // EXPORT_ES6 && USE_ES6_IMPORT_META
155+
#endif // !MODULARIZE
166156

167157
// `/` should be present at the end if `scriptDirectory` is not empty
168158
var scriptDirectory = '';
@@ -383,14 +373,13 @@ if (ENVIRONMENT_IS_SHELL) {
383373
// ENVIRONMENT_IS_NODE.
384374
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
385375
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
386-
if (typeof document != 'undefined' && document.currentScript) { // web
387-
scriptDirectory = document.currentScript.src;
388-
}
389376
#if MODULARIZE
390377
// When MODULARIZE, this JS may be executed later, after document.currentScript
391378
// is gone, so we saved it, and we use it here instead of any other info.
392-
if (_scriptDir) {
393-
scriptDirectory = _scriptDir;
379+
scriptDirectory = _scriptDir;
380+
#else
381+
if (typeof document !== 'undefined' && document.currentScript) { // web
382+
scriptDirectory = document.currentScript.src;
394383
}
395384
#endif
396385
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
@@ -402,7 +391,6 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
402391
if (scriptDirectory.indexOf('blob:') !== 0) {
403392
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/')+1);
404393
} else {
405-
// TODO: Why? Does this mean that the previous `scriptDirectory`-logic is only for `blob:` URLs?
406394
scriptDirectory = '';
407395
}
408396

src/shell_minimal.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ function ready() {
162162
#if !MODULARIZE
163163
// 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
164164
// before the page load. In non-MODULARIZE modes generate it here.
165-
var _scriptDir = (typeof document != 'undefined' && document.currentScript) ? document.currentScript.src : undefined;
166-
#endif
165+
#if EXPORT_ES6 && USE_ES6_IMPORT_META
166+
var _scriptDir = import.meta.url;
167+
#else
168+
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : '';
169+
#if ENVIRONMENT_MAY_BE_NODE
170+
if (typeof __filename !== 'undefined') _scriptDir = __filename;
171+
#endif // ENVIRONMENT_MAY_BE_NODE
172+
#endif // EXPORT_ES6 && USE_ES6_IMPORT_META
173+
#endif // !MODULARIZE
167174

168175
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
169176
// coincide.
@@ -174,5 +181,4 @@ var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
174181
var ENVIRONMENT_IS_WORKER = ENVIRONMENT_IS_PTHREAD = typeof importScripts == 'function';
175182
#endif
176183

177-
var currentScriptUrl = typeof _scriptDir != 'undefined' ? _scriptDir : ((typeof document != 'undefined' && document.currentScript) ? document.currentScript.src : undefined);
178184
#endif // PTHREADS

0 commit comments

Comments
 (0)