Skip to content

Commit e13ee98

Browse files
authored
Minor cleanup and refactoring in src/jsifier.mjs. NFC (#27997)
- Skip scanning `PRE_JS_FILES`, `POST_JS_FILES`, and `EM_JS_SNIPPETS` in `--symbols-only` mode, and use `getIncludeFile` so preprocessed files are handled consistently. - Avoid mutating `LibraryManager.library[symbol]` when creating stub functions and remove the unused `original` variable. - Add `timer.start`/`timer.stop` around the `symbolHandler` loop. Split out from #27995
1 parent d726e5d commit e13ee98

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

‎src/jsifier.mjs‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,16 @@ export async function runJSify(outputFile, symbolsOnly) {
438438
const symbolsNeeded = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE;
439439
symbolsNeeded.push(...extraLibraryFuncs);
440440

441-
for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) {
442-
const content = readFile(fileName);
443-
addImplicitDeps(content, symbolsNeeded);
444-
}
445-
for (const snippet of EM_JS_SNIPPETS) {
446-
addImplicitDeps(snippet, symbolsNeeded);
441+
if (!symbolsOnly) {
442+
for (const fileName of [...PRE_JS_FILES, ...POST_JS_FILES]) {
443+
const content = getIncludeFile(fileName);
444+
if (!errorOccured()) {
445+
addImplicitDeps(content, symbolsNeeded);
446+
}
447+
}
448+
for (const snippet of EM_JS_SNIPPETS) {
449+
addImplicitDeps(snippet, symbolsNeeded);
450+
}
447451
}
448452
for (const sym of EXPORTED_RUNTIME_METHODS) {
449453
if ('$' + sym in LibraryManager.library) {
@@ -640,6 +644,7 @@ function(${args}) {
640644
let isStub = false;
641645

642646
const mangled = mangleCSymbolName(symbol);
647+
let snippet = LibraryManager.library[symbol];
643648

644649
if (!LibraryManager.library.hasOwnProperty(symbol)) {
645650
const isWeakImport = WEAK_IMPORTS.has(symbol);
@@ -692,17 +697,14 @@ function(${args}) {
692697
stubFunctionBody = assertion + `return ${target}(...args);`;
693698
}
694699
isStub = true;
695-
LibraryManager.library[symbol] = new Function('...args', stubFunctionBody);
700+
snippet = new Function('...args', stubFunctionBody);
696701
}
697702

698703
librarySymbols.push(mangled);
699704

700705
if (!isStub && LibraryManager.library[symbol + '__export']) {
701706
extraExports.add(mangled);
702707
}
703-
704-
const original = LibraryManager.library[symbol];
705-
let snippet = original;
706708
const isUserSymbol = LibraryManager.library[symbol + '__user'];
707709
// Check for dependencies on `__internal` symbols from user libraries.
708710
for (const dep of deps) {
@@ -988,9 +990,11 @@ var proxiedFunctionTable = [
988990
);
989991
}
990992

993+
timer.start('symbolHandler');
991994
for (const sym of symbolsNeeded) {
992995
symbolHandler(sym);
993996
}
997+
timer.stop('symbolHandler');
994998

995999
if (symbolsOnly) {
9961000
writeOutput(

0 commit comments

Comments
 (0)