Skip to content

Commit 2a7164d

Browse files
authored
Make EXPORTED_RUNTIME_METHODS into a Set within the JS compiler. NFC (#21880)
1 parent 33881ed commit 2a7164d

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/compiler.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ WASM_EXPORTS = new Set(WASM_EXPORTS);
5555
SIDE_MODULE_EXPORTS = new Set(SIDE_MODULE_EXPORTS);
5656
INCOMING_MODULE_JS_API = new Set(INCOMING_MODULE_JS_API);
5757
ALL_INCOMING_MODULE_JS_API = new Set(ALL_INCOMING_MODULE_JS_API);
58+
EXPORTED_RUNTIME_METHODS = new Set(EXPORTED_RUNTIME_METHODS);
5859
WEAK_IMPORTS = new Set(WEAK_IMPORTS);
5960
if (symbolsOnly) {
6061
INCLUDE_FULL_LIBRARY = 1;

src/modules.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,11 @@ function addMissingLibraryStubs(unusedLibSymbols) {
368368

369369
// export parts of the JS runtime that the user asked for
370370
function exportRuntime() {
371-
const EXPORTED_RUNTIME_METHODS_SET = new Set(EXPORTED_RUNTIME_METHODS);
372-
373371
// optionally export something.
374372
function maybeExport(name) {
375373
// If requested to be exported, export it. HEAP objects are exported
376374
// separately in updateMemoryViews
377-
if (EXPORTED_RUNTIME_METHODS_SET.has(name) && !name.startsWith('HEAP')) {
375+
if (EXPORTED_RUNTIME_METHODS.has(name) && !name.startsWith('HEAP')) {
378376
return `Module['${name}'] = ${name};`;
379377
}
380378
}
@@ -449,7 +447,7 @@ function exportRuntime() {
449447
// dynCall_* methods are not hardcoded here, as they
450448
// depend on the file being compiled. check for them
451449
// and add them.
452-
for (const name of EXPORTED_RUNTIME_METHODS_SET) {
450+
for (const name of EXPORTED_RUNTIME_METHODS) {
453451
if (/^dynCall_/.test(name)) {
454452
// a specific dynCall; add to the list
455453
runtimeElements.push(name);
@@ -472,7 +470,7 @@ function exportRuntime() {
472470

473471
// check all exported things exist, warn about typos
474472
runtimeElementsSet = new Set(runtimeElements);
475-
for (const name of EXPORTED_RUNTIME_METHODS_SET) {
473+
for (const name of EXPORTED_RUNTIME_METHODS) {
476474
if (!runtimeElementsSet.has(name)) {
477475
warn(`invalid item in EXPORTED_RUNTIME_METHODS: ${name}`);
478476
}
@@ -491,7 +489,7 @@ function exportRuntime() {
491489

492490
const unexported = [];
493491
for (const name of runtimeElements) {
494-
if (!EXPORTED_RUNTIME_METHODS_SET.has(name) && !unusedLibSymbols.has(name)) {
492+
if (!EXPORTED_RUNTIME_METHODS.has(name) && !unusedLibSymbols.has(name)) {
495493
unexported.push(name);
496494
}
497495
}

src/parseTools.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ function isSymbolNeeded(symName) {
808808
if (DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.includes(symName)) {
809809
return true;
810810
}
811-
if (symName.startsWith('$') && symName.slice(1) in EXPORTED_RUNTIME_METHODS) {
811+
if (symName.startsWith('$') && EXPORTED_RUNTIME_METHODS.has(symName.slice(1))) {
812812
return true;
813813
}
814814
return false;
@@ -913,7 +913,7 @@ function hasExportedSymbol(sym) {
913913
// wasmTable are set. In this case we maybe need to re-export them on the
914914
// Module object.
915915
function receivedSymbol(sym) {
916-
if (EXPORTED_RUNTIME_METHODS.includes(sym)) {
916+
if (EXPORTED_RUNTIME_METHODS.has(sym)) {
917917
return `Module['${sym}'] = ${sym};`;
918918
}
919919
return '';

0 commit comments

Comments
 (0)