Skip to content

Commit 143249e

Browse files
authored
Rename the exports variable in preamble.js to instExports (#20231)
This avoids a bug (or limitation) in Google's Closure compiler that does not allow any variable named exports to be reassigned. Without this change, some build configurations result in an error message like this: [JSC_EXPORT_NOT_AT_MODULE_SCOPE] Exports must be at the top-level of a module 543| exports = Asyncify.instrumentWasmExports(exports); Since the exports variable used in the preamble is not related to Closure modules, simply renaming the variable does the trick.
1 parent dd4777b commit 143249e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/preamble.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,18 @@ function createWasm() {
948948
// performing other necessary setup
949949
/** @param {WebAssembly.Module=} module*/
950950
function receiveInstance(instance, module) {
951-
var exports = instance.exports;
951+
wasmExports = instance.exports;
952952

953953
#if RELOCATABLE
954-
exports = relocateExports(exports, {{{ GLOBAL_BASE }}});
954+
wasmExports = relocateExports(wasmExports, {{{ GLOBAL_BASE }}});
955955
#endif
956956

957957
#if ASYNCIFY
958-
exports = Asyncify.instrumentWasmExports(exports);
958+
wasmExports = Asyncify.instrumentWasmExports(wasmExports);
959959
#endif
960960

961961
#if ABORT_ON_WASM_EXCEPTIONS
962-
exports = instrumentWasmExportsWithAbort(exports);
962+
wasmExports = instrumentWasmExportsWithAbort(wasmExports);
963963
#endif
964964

965965
#if MAIN_MODULE
@@ -969,7 +969,7 @@ function createWasm() {
969969
dynamicLibraries = metadata.neededDynlibs.concat(dynamicLibraries);
970970
}
971971
#endif
972-
mergeLibSymbols(exports, 'main')
972+
mergeLibSymbols(wasmExports, 'main')
973973
#if '$LDSO' in addedLibraryItems
974974
LDSO.init();
975975
#endif
@@ -979,10 +979,9 @@ function createWasm() {
979979
#endif
980980

981981
#if MEMORY64 || CAN_ADDRESS_2GB
982-
exports = applySignatureConversions(exports);
982+
wasmExports = applySignatureConversions(wasmExports);
983983
#endif
984984

985-
wasmExports = exports;
986985
{{{ receivedSymbol('wasmExports') }}}
987986

988987
#if PTHREADS
@@ -1039,15 +1038,15 @@ function createWasm() {
10391038
#if !DECLARE_ASM_MODULE_EXPORTS
10401039
// If we didn't declare the asm exports as top level enties this function
10411040
// is in charge of programatically exporting them on the global object.
1042-
exportWasmSymbols(exports);
1041+
exportWasmSymbols(wasmExports);
10431042
#endif
10441043

10451044
#if PTHREADS || WASM_WORKERS
10461045
// We now have the Wasm module loaded up, keep a reference to the compiled module so we can post it to the workers.
10471046
wasmModule = module;
10481047
#endif
10491048
removeRunDependency('wasm-instantiate');
1050-
return exports;
1049+
return wasmExports;
10511050
}
10521051
// wait for the pthread pool (if any)
10531052
addRunDependency('wasm-instantiate');

0 commit comments

Comments
 (0)