Skip to content

Commit f9204c2

Browse files
authored
Ensure ENVIRONMENT_IS_PTHREAD/WASM_WORKER are defined before pre-js file (#21721)
Its useful for pre-js files to be able to depend on these variables, and this is specifically necessary for #21701 which removes the default export of `ENVIRONMENT_IS_PTHREAD`. Note that this also fixes an inconsistency between the regular runtime and the minimal runtime where minimal runtime was defining some `ENVIRONMENT_IS_XX` var before pre-js but the regular runtime was not.
1 parent d3fca85 commit f9204c2

29 files changed

+59
-56
lines changed

src/runtime_debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function dbg(...args) {
165165
#if ENVIRONMENT_MAY_BE_NODE && PTHREADS
166166
// Avoid using the console for debugging in multi-threaded node applications
167167
// See https://github.com/emscripten-core/emscripten/issues/14804
168-
if (ENVIRONMENT_IS_NODE) {
168+
if (ENVIRONMENT_IS_NODE && fs) {
169169
fs.writeSync(2, args.join(' ') + '\n');
170170
} else
171171
#endif

src/shell.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,6 @@ var readyPromise = new Promise((resolve, reject) => {
7575
#endif
7676
#endif
7777

78-
// --pre-jses are emitted after the Module integration code, so that they can
79-
// refer to Module (if they choose; they can also define Module)
80-
{{{ preJS() }}}
81-
82-
// Sometimes an existing Module object exists with properties
83-
// meant to overwrite the default module functionality. Here
84-
// we collect those properties and reapply _after_ we configure
85-
// the current environment's defaults to avoid having to be so
86-
// defensive during initialization.
87-
var moduleOverrides = Object.assign({}, Module);
88-
89-
var arguments_ = [];
90-
var thisProgram = './this.program';
91-
var quit_ = (status, toThrow) => {
92-
throw toThrow;
93-
};
94-
9578
// Determine the runtime environment we are in. You can customize this by
9679
// setting the ENVIRONMENT setting at compile time (see settings.js).
9780

@@ -143,6 +126,23 @@ var ENVIRONMENT_IS_PTHREAD = Module['ENVIRONMENT_IS_PTHREAD'] || false;
143126
var ENVIRONMENT_IS_WASM_WORKER = Module['$ww'];
144127
#endif
145128

129+
// --pre-jses are emitted after the Module integration code, so that they can
130+
// refer to Module (if they choose; they can also define Module)
131+
{{{ preJS() }}}
132+
133+
// Sometimes an existing Module object exists with properties
134+
// meant to overwrite the default module functionality. Here
135+
// we collect those properties and reapply _after_ we configure
136+
// the current environment's defaults to avoid having to be so
137+
// defensive during initialization.
138+
var moduleOverrides = Object.assign({}, Module);
139+
140+
var arguments_ = [];
141+
var thisProgram = './this.program';
142+
var quit_ = (status, toThrow) => {
143+
throw toThrow;
144+
};
145+
146146
#if SHARED_MEMORY && !MODULARIZE
147147
// In MODULARIZE mode _scriptDir needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
148148
// before the page load. In non-MODULARIZE modes generate it here.

src/shell_minimal.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ function ready() {
134134
#endif
135135
#endif
136136

137+
#if PTHREADS
138+
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
139+
// coincide.
140+
#if WASM_WORKERS
141+
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
142+
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_WASM_WORKER;
143+
#else
144+
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
145+
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER;
146+
#endif
147+
#endif
148+
137149
// --pre-jses are emitted after the Module integration code, so that they can
138150
// refer to Module (if they choose; they can also define Module)
139151
{{{ preJS() }}}
@@ -146,16 +158,6 @@ function ready() {
146158
var _scriptDir = (typeof document != 'undefined') ? document.currentScript?.src : undefined;
147159
#endif
148160

149-
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
150-
// coincide.
151-
#if WASM_WORKERS
152-
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
153-
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_WASM_WORKER;
154-
#else
155-
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
156-
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER;
157-
#endif
158-
159161
if (ENVIRONMENT_IS_WORKER) {
160162
_scriptDir = self.location.href;
161163
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9852
1+
9851
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10942
1+
10941
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9852
1+
9851
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5214
1+
5212
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3134
1+
3133
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8159
1+
8162
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2975
1+
2974

0 commit comments

Comments
 (0)