Skip to content

Commit b8c634a

Browse files
committed
Allow mutation of EXPORTED_RUNTIME_METHODS in JS libraries
This used to work in the past but regressed at some point. Fixes: #23057
1 parent f45d48c commit b8c634a

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ function getWasmImports() {
768768
updateGOT(origExports);
769769
#endif
770770

771-
#if EXPORTED_RUNTIME_METHODS.includes('wasmExports')
771+
#if EXPORTED_RUNTIME_METHODS.has('wasmExports')
772772
Module['wasmExports'] = wasmExports;
773773
#endif
774774

src/runtime_common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var runtimeExited = false;
126126
let shouldExport = false;
127127
if (MODULARIZE && EXPORT_ALL) {
128128
shouldExport = true;
129-
} else if (EXPORTED_RUNTIME_METHODS.includes(x)) {
129+
} else if (EXPORTED_RUNTIME_METHODS.has(x)) {
130130
shouldExport = true;
131131
}
132132
return shouldExport;

src/utility.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,19 @@ export function addToCompileTimeContext(object) {
332332
}
333333

334334
export function applySettings(obj) {
335+
// Convert certain settings to sets
336+
for (const key of ['EXPORTED_FUNCTIONS',
337+
'WASM_EXPORTS',
338+
'SIDE_MODULE_EXPORTS',
339+
'INCOMING_MODULE_JS_API',
340+
'ALL_INCOMING_MODULE_JS_API',
341+
'EXPORTED_RUNTIME_METHODS',
342+
'WEAK_IMPORTS']) {
343+
if (typeof obj[key] !== 'undefined') {
344+
obj[key] = new Set(obj[key]);
345+
}
346+
}
347+
335348
// Make settings available both in the current / global context
336349
// and also in the macro execution contexted.
337350
Object.assign(globalThis, obj);

test/jslib/test_export.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
EXPORTED_RUNTIME_METHODS.add("myFunc");
2+
3+
addToLibrary({
4+
$myFunc__postset: 'console.log("myFunc included")',
5+
$myFunc: () => {
6+
console.log("myFunc called");
7+
},
8+
})

test/test_jslib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,3 +757,7 @@ class ParentClass {}
757757
})
758758
def test_multiline_string(self, args):
759759
self.do_run_in_out_file_test('jslib/test_multiline_string.c', cflags=['--js-library', test_file('jslib/test_multiline_string.js')] + args)
760+
761+
def test_export(self):
762+
create_file('post.js', 'Module.myFunc();');
763+
self.do_runf(test_file('hello_world.c'), 'myFunc included\nmyFunc called\n', cflags=['--js-library', test_file('jslib/test_export.js'), '--extern-post-js=post.js'])

tools/compiler.mjs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,9 @@ process.env['EMCC_BUILD_DIR'] = process.cwd();
6060

6161
// In case compiler.mjs is run directly (as in gen_sig_info)
6262
// ALL_INCOMING_MODULE_JS_API might not be populated yet.
63-
if (!ALL_INCOMING_MODULE_JS_API.length) {
63+
if (!ALL_INCOMING_MODULE_JS_API.size) {
6464
ALL_INCOMING_MODULE_JS_API = INCOMING_MODULE_JS_API;
6565
}
66-
67-
EXPORTED_FUNCTIONS = new Set(EXPORTED_FUNCTIONS);
68-
WASM_EXPORTS = new Set(WASM_EXPORTS);
69-
SIDE_MODULE_EXPORTS = new Set(SIDE_MODULE_EXPORTS);
70-
INCOMING_MODULE_JS_API = new Set(INCOMING_MODULE_JS_API);
71-
ALL_INCOMING_MODULE_JS_API = new Set(ALL_INCOMING_MODULE_JS_API);
72-
EXPORTED_RUNTIME_METHODS = new Set(EXPORTED_RUNTIME_METHODS);
73-
WEAK_IMPORTS = new Set(WEAK_IMPORTS);
7466
if (symbolsOnly) {
7567
INCLUDE_FULL_LIBRARY = 1;
7668
}

0 commit comments

Comments
 (0)