Skip to content

Commit 452e7db

Browse files
authored
Move preInit handling to processModuleArgs. NFC (#25093)
This simplifies the startup code and paves the way for the removal of the use of `addRunDependency`/`removeRunDependency` for `wasm-instantiation`.
1 parent 8e66cb1 commit 452e7db

35 files changed

+102
-115
lines changed

src/postamble.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,6 @@ function checkUnflushedContent() {
288288
#endif // EXIT_RUNTIME
289289
#endif // ASSERTIONS
290290

291-
function preInit() {
292-
#if expectToReceiveOnModule('preInit')
293-
if (Module['preInit']) {
294-
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
295-
while (Module['preInit'].length > 0) {
296-
Module['preInit'].shift()();
297-
}
298-
}
299-
#if ASSERTIONS
300-
consumedModuleProp('preInit');
301-
#endif
302-
#endif
303-
}
304-
305291
var wasmExports;
306292

307293
#if MODULARIZE == 'instance'
@@ -329,7 +315,6 @@ export default async function init(moduleArg = {}) {
329315
#else
330316
wasmExports = await createWasm();
331317
#endif
332-
preInit();
333318
run();
334319
}
335320

@@ -378,13 +363,12 @@ createWasm();
378363
wasmExports = createWasm();
379364
#endif
380365

366+
run();
367+
381368
#if WASM_WORKERS || PTHREADS
382369
}
383370
#endif
384371

385-
preInit();
386-
{{{ runIfMainThread('run();') }}}
387-
388372
#endif // MODULARIZE != instance
389373

390374
#if BUILD_AS_WORKER

src/postlibrary.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ function processModuleArgs()
4040
#endif
4141
#endif // ASSERTIONS
4242

43+
#if expectToReceiveOnModule('preInit')
44+
if (Module['preInit']) {
45+
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
46+
while (Module['preInit'].length > 0) {
47+
Module['preInit'].shift()();
48+
}
49+
}
50+
#if ASSERTIONS
51+
consumedModuleProp('preInit');
52+
#endif
53+
#endif
4354
}
4455

4556
{{{ exportJSSymbols() }}}

test/code_size/test_codesize_cxx_ctors1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19753,
3-
"a.out.js.gz": 8160,
2+
"a.out.js": 19754,
3+
"a.out.js.gz": 8162,
44
"a.out.nodebug.wasm": 129508,
55
"a.out.nodebug.wasm.gz": 49240,
6-
"total": 149261,
7-
"total_gz": 57400,
6+
"total": 149262,
7+
"total_gz": 57402,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_ctors2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"a.out.js": 19731,
2+
"a.out.js": 19732,
33
"a.out.js.gz": 8148,
44
"a.out.nodebug.wasm": 128935,
55
"a.out.nodebug.wasm.gz": 48881,
6-
"total": 148666,
6+
"total": 148667,
77
"total_gz": 57029,
88
"sent": [
99
"__cxa_throw",

test/code_size/test_codesize_cxx_except.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23414,
3-
"a.out.js.gz": 9144,
2+
"a.out.js": 23415,
3+
"a.out.js.gz": 9145,
44
"a.out.nodebug.wasm": 171270,
55
"a.out.nodebug.wasm.gz": 57331,
6-
"total": 194684,
7-
"total_gz": 66475,
6+
"total": 194685,
7+
"total_gz": 66476,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/code_size/test_codesize_cxx_except_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19642,
3-
"a.out.js.gz": 8109,
2+
"a.out.js": 19643,
3+
"a.out.js.gz": 8112,
44
"a.out.nodebug.wasm": 144629,
55
"a.out.nodebug.wasm.gz": 54892,
6-
"total": 164271,
7-
"total_gz": 63001,
6+
"total": 164272,
7+
"total_gz": 63004,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/code_size/test_codesize_cxx_except_wasm_legacy.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19642,
3-
"a.out.js.gz": 8109,
2+
"a.out.js": 19643,
3+
"a.out.js.gz": 8112,
44
"a.out.nodebug.wasm": 142218,
55
"a.out.nodebug.wasm.gz": 54353,
6-
"total": 161860,
7-
"total_gz": 62462,
6+
"total": 161861,
7+
"total_gz": 62465,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/code_size/test_codesize_cxx_lto.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19081,
3-
"a.out.js.gz": 7838,
2+
"a.out.js": 19082,
3+
"a.out.js.gz": 7841,
44
"a.out.nodebug.wasm": 106464,
55
"a.out.nodebug.wasm.gz": 42600,
6-
"total": 125545,
7-
"total_gz": 50438,
6+
"total": 125546,
7+
"total_gz": 50441,
88
"sent": [
99
"a (emscripten_resize_heap)",
1010
"b (_setitimer_js)",

test/code_size/test_codesize_cxx_noexcept.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19753,
3-
"a.out.js.gz": 8160,
2+
"a.out.js": 19754,
3+
"a.out.js.gz": 8162,
44
"a.out.nodebug.wasm": 131925,
55
"a.out.nodebug.wasm.gz": 50235,
6-
"total": 151678,
7-
"total_gz": 58395,
6+
"total": 151679,
7+
"total_gz": 58397,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_wasmfs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7143,
3-
"a.out.js.gz": 3337,
3+
"a.out.js.gz": 3338,
44
"a.out.nodebug.wasm": 169796,
55
"a.out.nodebug.wasm.gz": 63083,
66
"total": 176939,
7-
"total_gz": 66420,
7+
"total_gz": 66421,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

0 commit comments

Comments
 (0)