Skip to content

Commit c0575ef

Browse files
authored
file_packager: Fix regression in --separate-metadata output (#22802)
This reverts commit 483cdcd. This also adds some testing of the `--separate-metadata` file_packager options where we actually run the generated code. As part of adding this test I also made the code work under node. Fixes: #22790
1 parent 48d9bc0 commit c0575ef

File tree

82 files changed

+154
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+154
-118
lines changed

src/library.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,8 +1946,10 @@ addToLibrary({
19461946

19471947
$callRuntimeCallbacks__internal: true,
19481948
$callRuntimeCallbacks: (callbacks) => {
1949-
// Pass the module as the first argument.
1950-
callbacks.forEach((f) => f(Module));
1949+
while (callbacks.length > 0) {
1950+
// Pass the module as the first argument.
1951+
callbacks.shift()(Module);
1952+
}
19511953
},
19521954

19531955
#if SHRINK_LEVEL == 0 || ASYNCIFY == 2

src/postamble.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ if (ENVIRONMENT_IS_WORKER) {
2727
{{{ exportRuntime() }}}
2828

2929
var calledRun;
30-
var calledPrerun;
3130

3231
#if STANDALONE_WASM && MAIN_READS_PARAMS
3332
var mainArgs = undefined;
@@ -47,7 +46,7 @@ function callMain() {
4746
#endif
4847
#if ASSERTIONS
4948
assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])');
50-
assert(calledPrerun, 'cannot call main without calling preRun first');
49+
assert(__ATPRERUN__.length == 0, 'cannot call main when preRun functions remain to be called');
5150
#endif
5251

5352
var entryFunction = {{{ getEntryFunction() }}};
@@ -189,25 +188,22 @@ function run() {
189188
stackCheckInit();
190189
#endif
191190

192-
if (!calledPrerun) {
193-
calledPrerun = 1;
194-
preRun();
191+
preRun();
195192

196-
// a preRun added a dependency, run will be called later
197-
if (runDependencies > 0) {
193+
// a preRun added a dependency, run will be called later
194+
if (runDependencies > 0) {
198195
#if RUNTIME_DEBUG
199-
dbg('run() called, but dependencies remain, so not running');
196+
dbg('run() called, but dependencies remain, so not running');
200197
#endif
201-
return;
202-
}
198+
return;
203199
}
204200

205201
function doRun() {
206202
// run may have just been called through dependencies being fulfilled just in this very frame,
207203
// or while the async setStatus time below was happening
208204
if (calledRun) return;
209-
calledRun = 1;
210-
Module['calledRun'] = 1;
205+
calledRun = true;
206+
Module['calledRun'] = true;
211207

212208
if (ABORT) return;
213209

src/preamble.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,11 @@ function preRun() {
195195
assert(!ENVIRONMENT_IS_PTHREAD); // PThreads reuse the runtime from the main thread.
196196
#endif
197197
#if expectToReceiveOnModule('preRun')
198-
var preRuns = Module['preRun'];
199-
if (preRuns) {
200-
if (typeof preRuns == 'function') preRuns = [preRuns];
201-
preRuns.forEach(addOnPreRun);
198+
if (Module['preRun']) {
199+
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
200+
while (Module['preRun'].length) {
201+
addOnPreRun(Module['preRun'].shift());
202+
}
202203
}
203204
#endif
204205
callRuntimeCallbacks(__ATPRERUN__);
@@ -288,10 +289,11 @@ function postRun() {
288289
#endif
289290

290291
#if expectToReceiveOnModule('postRun')
291-
var postRuns = Module['postRun'];
292-
if (postRuns) {
293-
if (typeof postRuns == 'function') postRuns = [postRuns];
294-
postRuns.forEach(addOnPostRun);
292+
if (Module['postRun']) {
293+
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
294+
while (Module['postRun'].length) {
295+
addOnPostRun(Module['postRun'].shift());
296+
}
295297
}
296298
#endif
297299

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8472
1+
8465
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20767
1+
20821
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8453
1+
8449
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20735
1+
20789
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9499
1+
9487
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24611
1+
24665
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8431
1+
8427

0 commit comments

Comments
 (0)