Skip to content

Commit 90ca76f

Browse files
committed
Fix regression with Safari and EXPORT_NAME
Fixes: #18357
1 parent 22f1d6a commit 90ca76f

14 files changed

+56
-30
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ jobs:
601601
echo "JSC_ENGINE = [os.path.expanduser('~/.jsvu/bin/javascriptcore')]" >> ~/emsdk/.emscripten
602602
echo "JS_ENGINES = [JSC_ENGINE]" >> ~/emsdk/.emscripten
603603
- run-tests:
604-
test_targets: "core0.test_hello_world"
604+
test_targets: "core0.test_hello_world other.test_modularize_incoming other.test_modularize_incoming_export_name"
605605
test-spidermonkey:
606606
executor: linux-python
607607
steps:

emcc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,8 +3229,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
32293229

32303230
if settings.MODULARIZE:
32313231
modularize()
3232-
3233-
if settings.USE_CLOSURE_COMPILER:
3232+
elif settings.USE_CLOSURE_COMPILER:
32343233
module_export_name_substitution()
32353234

32363235
# Run a final optimization pass to clean up items that were not possible to
@@ -3863,7 +3862,10 @@ def modularize():
38633862
shared.target_environment_may_be('web'):
38643863
async_emit = 'async '
38653864

3866-
return_value = settings.EXPORT_NAME
3865+
# Return ths incoming moduleArg. This is is equeivielt to the `Module` var within the
3866+
# generated code is not effected by closure minifiection so we can references in the
3867+
# the return statement.
3868+
return_value = 'moduleArg'
38673869
if settings.WASM_ASYNC_COMPILATION:
38683870
return_value += '.ready'
38693871
if not settings.EXPORT_READY_PROMISE:
@@ -3874,7 +3876,7 @@ def modularize():
38743876
diagnostics.warning('emcc', 'EXPORT_NAME should not be named "config" when targeting Safari')
38753877

38763878
src = '''
3877-
%(maybe_async)sfunction(%(EXPORT_NAME)s = {}) {
3879+
%(maybe_async)sfunction(moduleArg = {}) {
38783880
38793881
%(src)s
38803882
@@ -3883,7 +3885,6 @@ def modularize():
38833885
%(capture_module_function_for_audio_worklet)s
38843886
''' % {
38853887
'maybe_async': async_emit,
3886-
'EXPORT_NAME': settings.EXPORT_NAME,
38873888
'src': src,
38883889
'return_value': return_value,
38893890
# Given the async nature of how the Module function and Module object come into existence in AudioWorkletGlobalScope,
@@ -3945,6 +3946,7 @@ def modularize():
39453946

39463947

39473948
def module_export_name_substitution():
3949+
assert not settings.MODULARIZE
39483950
global final_js
39493951
logger.debug(f'Private module export name substitution with {settings.EXPORT_NAME}')
39503952
src = read_file(final_js)

src/closure-externs/closure-externs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,5 @@ var sampleRate;
261261
* Avoid closure minifying anything to "id". See #13965
262262
*/
263263
var id;
264+
265+
var moduleArg;

src/preamble.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ if (Module['locateFile']) {
630630
}
631631
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE // in single-file mode, repeating WASM_BINARY_FILE would emit the contents again
632632
} else {
633+
#if ENVIRONMENT_MAY_BE_SHELL
634+
if (ENVIRONMENT_IS_SHELL)
635+
wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
636+
else
637+
#endif
633638
// Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
634639
wasmBinaryFile = new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href;
635640
}

src/shell.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
// after the generated code, you will need to define var Module = {};
2121
// before the code. Then that object will be used in the code, and you
2222
// can continue to use Module afterwards as well.
23-
#if USE_CLOSURE_COMPILER
23+
#if MODULARIZE
24+
var Module = moduleArg;
25+
#elif USE_CLOSURE_COMPILER
2426
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
2527
var /** @type {{
2628
noImageDecoding: boolean,
@@ -318,19 +320,16 @@ if (ENVIRONMENT_IS_SHELL) {
318320
return data;
319321
};
320322

323+
// This shell version of readAsync is not techically async, since we don't
324+
// have an async `read()` available.
321325
readAsync = (f, onload, onerror) => {
322-
setTimeout(() => onload(readBinary(f)));
326+
onload(readBinary(f));
323327
};
324328

325329
if (typeof clearTimeout == 'undefined') {
326330
globalThis.clearTimeout = (id) => {};
327331
}
328332

329-
if (typeof setTimeout == 'undefined') {
330-
// spidermonkey lacks setTimeout but we use it above in readAsync.
331-
globalThis.setTimeout = (f) => (typeof f == 'function') ? f() : abort();
332-
}
333-
334333
if (typeof scriptArgs != 'undefined') {
335334
arguments_ = scriptArgs;
336335
} else if (typeof arguments != 'undefined') {

src/shell_minimal.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
#if USE_CLOSURE_COMPILER
8-
7+
#if MODULARIZE
8+
var Module = moduleArg;
9+
#elif USE_CLOSURE_COMPILER
910
// if (!Module)` is crucial for Closure Compiler here as it will
1011
// otherwise replace every `Module` occurrence with the object below
1112
var /** @type{Object} */ Module;
@@ -15,7 +16,7 @@ if (!Module) /** @suppress{checkTypes}*/Module =
1516
#endif
1617
{"__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__":1};
1718

18-
#elif !MODULARIZE && (ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL)
19+
#elif ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
1920

2021
// When running on the web we expect Module to be defined externally, in the
2122
// HTML. Otherwise we must define it here before its first use
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 18209,
5-
"a.js.gz": 8055,
4+
"a.js": 18218,
5+
"a.js.gz": 8059,
66
"a.mem": 3171,
77
"a.mem.gz": 2713,
8-
"total": 21947,
9-
"total_gz": 11147
8+
"total": 21956,
9+
"total_gz": 11151
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17681,
5-
"a.js.gz": 7872,
4+
"a.js": 17689,
5+
"a.js.gz": 7874,
66
"a.mem": 3171,
77
"a.mem.gz": 2713,
8-
"total": 21419,
9-
"total_gz": 10964
8+
"total": 21427,
9+
"total_gz": 10966
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23635
1+
23614
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20062
1+
20041

0 commit comments

Comments
 (0)