Skip to content

Commit f3a80b9

Browse files
committed
Group JS library exports together, along with JS runtime exports. NFC
This is in preparation for emscripten-core#24005 which delays the processing and creation of Module object itself until later in some cases.
1 parent 9dbd397 commit f3a80b9

7 files changed

+33
-20
lines changed

src/jsifier.mjs

-9
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,6 @@ function(${args}) {
734734
}
735735
contentText = `var ${mangled} = ${snippet};`;
736736
}
737-
// asm module exports are done in emscripten.py, after the asm module is ready. Here
738-
// we also export library methods as necessary.
739-
if ((EXPORT_ALL || EXPORTED_FUNCTIONS.has(mangled)) && !isStub) {
740-
if (MODULARIZE === 'instance') {
741-
contentText += `\n__exp_${mangled} = ${mangled};`;
742-
} else {
743-
contentText += `\nModule['${mangled}'] = ${mangled};`;
744-
}
745-
}
746737
// Relocatable code needs signatures to create proper wrappers.
747738
if (sig && RELOCATABLE) {
748739
if (!WASM_BIGINT) {

src/modules.mjs

+28-6
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,21 @@ function addMissingLibraryStubs(unusedLibSymbols) {
405405
return rtn;
406406
}
407407

408+
function exportSymbol(name) {
409+
if (MODULARIZE === 'instance') {
410+
return `__exp_${name} = ${name};`;
411+
}
412+
return `Module['${name}'] = ${name};`;
413+
}
414+
408415
// export parts of the JS runtime that the user asked for
409-
function exportRuntime() {
416+
function exportRuntimeSymbols() {
410417
// optionally export something.
411418
function maybeExport(name) {
412419
// If requested to be exported, export it. HEAP objects are exported
413420
// separately in updateMemoryViews
414421
if (EXPORTED_RUNTIME_METHODS.has(name) && !name.startsWith('HEAP')) {
415-
if (MODULARIZE === 'instance') {
416-
return `__exp_${name} = ${name};`;
417-
}
418-
return `Module['${name}'] = ${name};`;
422+
return exportSymbol(name);
419423
}
420424
}
421425

@@ -509,6 +513,7 @@ function exportRuntime() {
509513
}
510514

511515
const exports = runtimeElements.map(maybeExport);
516+
exports.unshift('// Begin runtime exports')
512517
const results = exports.filter((name) => name);
513518

514519
if (ASSERTIONS && !EXPORT_ALL) {
@@ -540,8 +545,25 @@ function exportRuntime() {
540545
return results.join('\n') + '\n';
541546
}
542547

548+
function exportLibrarySymbols() {
549+
const results = ['// Begin JS library exports'];
550+
for (const ident of librarySymbols) {
551+
if (!isDecorator(ident) && !isInternalSymbol(ident)) {
552+
if (EXPORT_ALL || EXPORTED_FUNCTIONS.has(ident)) {
553+
results.push(exportSymbol(ident));
554+
}
555+
}
556+
}
557+
558+
return results.join('\n') + '\n';
559+
}
560+
561+
function exportJSSymbols() {
562+
return exportRuntimeSymbols() + exportLibrarySymbols();
563+
}
564+
543565
addToCompileTimeContext({
544-
exportRuntime,
566+
exportJSSymbols,
545567
loadStructInfo,
546568
LibraryManager,
547569
librarySymbols,

src/postamble.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (ENVIRONMENT_IS_WORKER) {
2424
#include "deterministic.js"
2525
#endif
2626

27-
{{{ exportRuntime() }}}
27+
{{{ exportJSSymbols() }}}
2828

2929
#if ASSERTIONS
3030
var calledRun;

src/postamble_minimal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// === Auto-generated postamble setup entry stuff ===
8-
{{{ exportRuntime() }}}
8+
{{{ exportJSSymbols() }}}
99

1010
#if HAS_MAIN // Only if user is exporting a C main(), we will generate a run() function that can be used to launch main.
1111
function run() {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51566
1+
51619
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27275
1+
27327
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
49720
1+
49773

0 commit comments

Comments
 (0)