Skip to content

Commit 6cbbdc7

Browse files
authored
Remove unused calledMain global. NFC (#17478)
This was only used by `proxyWorker.js` so move it there and use the existing `postRun` mechanism to set it. The motivation for this change is that it simplifies `callMain` in a way that should allow us to use `callUserCallback` there rather than the current/local try/catch. `calledMain` is not references anywhere else in the codebase or in any documentation so I think removing it should be safe.
1 parent ab96ffb commit 6cbbdc7

6 files changed

+11
-7
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ See docs/process.md for more on how version tagging works.
2424
removed (and replaced with an assert) as it had no uses internally and was
2525
removed (and replaced with an assert) as it had now uses internally and was
2626
untested.
27+
- Removed unused `calledMain` global variable from the JS runtime. Folks who
28+
want to know when main is done can use `Module[postRun]`.
2729

2830
3.1.16 - 07/14/2022
2931
-------------------

src/postamble.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ function runMemoryInitializer() {
9292

9393
var calledRun;
9494

95-
var calledMain = false;
96-
9795
#if STANDALONE_WASM && MAIN_READS_PARAMS
9896
var mainArgs = undefined;
9997
#endif
@@ -189,8 +187,6 @@ function callMain(args) {
189187
return handleException(e);
190188
#endif // !PROXY_TO_PTHREAD
191189
} finally {
192-
calledMain = true;
193-
194190
#if ABORT_ON_WASM_EXCEPTIONS
195191
// See abortWrapperDepth in preamble.js!
196192
abortWrapperDepth -= 2;

src/proxyWorker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ if (!ENVIRONMENT_IS_PTHREAD) {
395395

396396
var messageBuffer = null;
397397
var messageResenderTimeout = null;
398+
var calledMain = false;
399+
400+
// Set calledMain to true during postRun which happens onces main returns
401+
if (!Module['postRun']) Module['postRun'] = [];
402+
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
403+
Module['postRun'].push(() => { calledMain = true; });
398404

399405
function messageResender() {
400406
if (calledMain) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
84065
1+
84016
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56607
1+
56558
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
66130
1+
66081

0 commit comments

Comments
 (0)