Skip to content

Commit 7787d7a

Browse files
authored
Reverse order of execution of runtime callbacks (#24012)
This makes the `addOn<X>` functions use `[].push()` instead of `[].unshift()` for enqueueing callbacks properly (hooks were processed in the correct order, but runtime callbacks in each hook were enqueued and executed in reverse compared to the order of registration). The `AT<X>.unshift('callRuntimeCallbacks(on<X>);')` lines ensure runtime callbacks are always executed before compile time callbacks. Related tests updated accordingly.
1 parent 49c6358 commit 7787d7a

File tree

62 files changed

+130
-103
lines changed

Some content is hidden

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

62 files changed

+130
-103
lines changed

src/lib/libcore.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ addToLibrary({
23002300
ATPRERUNS.unshift('callRuntimeCallbacks(onPreRuns);');
23012301
},
23022302
$addOnPreRun__deps: ['$onPreRuns'],
2303-
$addOnPreRun: (cb) => onPreRuns.unshift(cb),
2303+
$addOnPreRun: (cb) => onPreRuns.push(cb),
23042304
// See ATINITS in parseTools.mjs for more information.
23052305
$onInits: [],
23062306
$onInits__internal: true,
@@ -2309,7 +2309,7 @@ addToLibrary({
23092309
ATINITS.unshift('callRuntimeCallbacks(onInits);');
23102310
},
23112311
$addOnInit__deps: ['$onInits'],
2312-
$addOnInit: (cb) => onInits.unshift(cb),
2312+
$addOnInit: (cb) => onInits.push(cb),
23132313
// See ATPOSTCTORS in parseTools.mjs for more information.
23142314
$onPostCtors: [],
23152315
$onPostCtors__internal: true,
@@ -2318,7 +2318,7 @@ addToLibrary({
23182318
ATPOSTCTORS.unshift('callRuntimeCallbacks(onPostCtors);');
23192319
},
23202320
$addOnPostCtor__deps: ['$onPostCtors'],
2321-
$addOnPostCtor: (cb) => onPostCtors.unshift(cb),
2321+
$addOnPostCtor: (cb) => onPostCtors.push(cb),
23222322
// See ATMAINS in parseTools.mjs for more information.
23232323
$onMains: [],
23242324
$onMains__internal: true,
@@ -2327,7 +2327,7 @@ addToLibrary({
23272327
ATMAINS.unshift('callRuntimeCallbacks(onMains);');
23282328
},
23292329
$addOnPreMain__deps: ['$onMains'],
2330-
$addOnPreMain: (cb) => onMains.unshift(cb),
2330+
$addOnPreMain: (cb) => onMains.push(cb),
23312331
// See ATEXITS in parseTools.mjs for more information.
23322332
$onExits: [],
23332333
$onExits__internal: true,
@@ -2336,7 +2336,7 @@ addToLibrary({
23362336
ATEXITS.unshift('callRuntimeCallbacks(onExits);');
23372337
},
23382338
$addOnExit__deps: ['$onExits'],
2339-
$addOnExit: (cb) => onExits.unshift(cb),
2339+
$addOnExit: (cb) => onExits.push(cb),
23402340
// See ATPOSTRUNS in parseTools.mjs for more information.
23412341
$onPostRuns: [],
23422342
$onPostRuns__internal: true,
@@ -2345,7 +2345,7 @@ addToLibrary({
23452345
ATPOSTRUNS.unshift('callRuntimeCallbacks(onPostRuns);');
23462346
},
23472347
$addOnPostRun__deps: ['$onPostRuns'],
2348-
$addOnPostRun: (cb) => onPostRuns.unshift(cb),
2348+
$addOnPostRun: (cb) => onPostRuns.push(cb),
23492349

23502350
// We used to define these globals unconditionally in support code.
23512351
// Instead, we now define them here so folks can pull it in explicitly, on

src/postamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function checkUnflushedContent() {
291291
if (Module['preInit']) {
292292
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
293293
while (Module['preInit'].length > 0) {
294-
Module['preInit'].pop()();
294+
Module['preInit'].shift()();
295295
}
296296
}
297297
#if ASSERTIONS
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8232
1+
8233
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19993
1+
19989
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8221
1+
8220
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19971
1+
19967
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23730
1+
23726
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8177
1+
8176
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19885
1+
19881
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8177
1+
8176

0 commit comments

Comments
 (0)