Skip to content

Commit 9d98f81

Browse files
authored
[jsifier] Simplify stub function handling (#25519)
1 parent ea5e4e0 commit 9d98f81

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/jsifier.mjs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ function(${args}) {
601601
warn('To build in STANDALONE_WASM mode without a main(), use emcc --no-entry');
602602
}
603603
}
604+
605+
// emit a stub that will fail at runtime
606+
var stubFunctionBody = `abort('missing function: ${symbol}');`
604607
if (RELOCATABLE) {
605608
// Create a stub for this symbol which can later be replaced by the
606609
// dynamic linker. If this stub is called before the symbol is
@@ -615,18 +618,10 @@ function(${args}) {
615618
if (ASSERTIONS) {
616619
assertion += `if (!${target} || ${target}.stub) abort("external symbol '${symbol}' is missing. perhaps a side module was not linked in? if this function was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment");\n`;
617620
}
618-
const functionBody = assertion + `return ${target}(...args);`;
619-
LibraryManager.library[symbol] = new Function('...args', functionBody);
620-
isStub = true;
621-
} else {
622-
// emit a stub that will fail at runtime
623-
LibraryManager.library[symbol] = new Function(`abort('missing function: ${symbol}');`);
624-
// We have already warned/errored about this function, so for the purposes of Closure use, mute all type checks
625-
// regarding this function, marking ot a variadic function that can take in anything and return anything.
626-
// (not useful to warn/error multiple times)
627-
LibraryManager.library[symbol + '__docs'] = '/** @type {function(...*):?} */';
628-
isStub = true;
621+
stubFunctionBody = assertion + `return ${target}(...args);`;
629622
}
623+
isStub = true;
624+
LibraryManager.library[symbol] = new Function('...args', stubFunctionBody);
630625
}
631626

632627
librarySymbols.push(mangled);
@@ -636,11 +631,11 @@ function(${args}) {
636631

637632
// Check for dependencies on `__internal` symbols from user libraries.
638633
const isUserSymbol = LibraryManager.library[symbol + '__user'];
639-
deps.forEach((dep) => {
634+
for (const dep of deps) {
640635
if (isUserSymbol && LibraryManager.library[dep + '__internal']) {
641636
warn(`user library symbol '${symbol}' depends on internal symbol '${dep}'`);
642637
}
643-
});
638+
}
644639

645640
const isFunction = typeof snippet == 'function';
646641
let isNativeAlias = false;

0 commit comments

Comments
 (0)