Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/jsifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export async function runJSify(outputFile, symbolsOnly) {
}
}

function processLibraryFunction(snippet, symbol, mangled, deps, isStub) {
function processLibraryFunction(snippet, symbol, mangled, deps) {
// It is possible that when printing the function as a string on Windows,
// the js interpreter we are in returns the string with Windows line endings
// \r\n. This is undesirable, since line endings are managed in the form \n
Expand All @@ -402,10 +402,6 @@ export async function runJSify(outputFile, symbolsOnly) {
snippet = 'function ' + snippet;
}

if (isStub) {
return snippet;
}

// apply LIBRARY_DEBUG if relevant
if (LIBRARY_DEBUG && !isJsOnlySymbol(symbol)) {
snippet = modifyJSFunction(snippet, (args, body, _async, oneliner) => {
Expand Down Expand Up @@ -601,6 +597,8 @@ function(${args}) {
warn('To build in STANDALONE_WASM mode without a main(), use emcc --no-entry');
}
}
// Create a stub that we can include in lieu of the missing function.
isStub = true;
if (RELOCATABLE) {
// Create a stub for this symbol which can later be replaced by the
// dynamic linker. If this stub is called before the symbol is
Expand All @@ -617,15 +615,13 @@ function(${args}) {
}
const functionBody = assertion + `return ${target}(...args);`;
LibraryManager.library[symbol] = new Function('...args', functionBody);
isStub = true;
} else {
// emit a stub that will fail at runtime
LibraryManager.library[symbol] = new Function(`abort('missing function: ${symbol}');`);
// We have already warned/errored about this function, so for the purposes of Closure use, mute all type checks
// regarding this function, marking ot a variadic function that can take in anything and return anything.
// (not useful to warn/error multiple times)
LibraryManager.library[symbol + '__docs'] = '/** @type {function(...*):?} */';
isStub = true;
}
}

Expand All @@ -642,7 +638,7 @@ function(${args}) {
}
});

let isFunction = false;
let isFunction = typeof snippet == 'function';
let isNativeAlias = false;

const postsetId = symbol + '__postset';
Expand Down Expand Up @@ -680,9 +676,8 @@ function(${args}) {
} else if (typeof snippet == 'object') {
snippet = stringifyWithFunctions(snippet);
addImplicitDeps(snippet, deps);
} else if (typeof snippet == 'function') {
isFunction = true;
snippet = processLibraryFunction(snippet, symbol, mangled, deps, isStub);
} else if (isFunction && !isStub) {
snippet = processLibraryFunction(snippet, symbol, mangled, deps);
addImplicitDeps(snippet, deps);
if (CHECK_DEPS && !isUserSymbol) {
checkDependencies(symbol, snippet, deps, postset?.toString());
Expand Down