@@ -81,45 +81,31 @@ if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) {
81
81
}
82
82
#endif
83
83
84
- #if ! SINGLE_FILE
85
- #if ENVIRONMENT_MAY_BE_NODE && ( ( WASM == 1 && ! WASM2JS ) || WASM == 2 )
86
- // Wasm or Wasm2JS loading:
87
-
88
- if ( ENVIRONMENT_IS_NODE ) {
89
- var fs = require ( 'fs' ) ;
90
- #if WASM == 2
91
- if ( typeof WebAssembly != 'undefined' ) Module [ 'wasm' ] = fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm' ) ;
92
- else eval ( fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm.js' ) + '' ) ;
93
- #else
94
- #if ! WASM2JS
95
- Module [ 'wasm' ] = fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm' ) ;
96
- #endif
97
- #endif
98
- }
99
- #endif
100
-
101
- #if ENVIRONMENT_MAY_BE_SHELL && ( ( WASM == 1 && ! WASM2JS ) || WASM == 2 )
102
- if ( ENVIRONMENT_IS_SHELL ) {
103
- #if WASM == 2
104
- if ( typeof WebAssembly != 'undefined ') Module [ 'wasm '] = read ( '{{{ TARGET_BASENAME }}}.wasm' , 'binary' ) ;
105
- else eval ( read ( '{{{ TARGET_BASENAME }}}.wasm.js' ) + '' ) ;
106
- #else
107
- #if ! WASM2JS
108
- Module [ 'wasm' ] = read ( '{{{ TARGET_BASENAME }}}.wasm' , 'binary' ) ;
109
- #endif
110
- #endif
111
- }
112
- #endif
113
-
114
- #endif // !SINGLE_FILE
115
-
116
84
// Redefine these in a --pre-js to override behavior. If you would like to
117
85
// remove out() or err() altogether, you can no-op it out to function() {},
118
86
// and build with --closure 1 to get Closure optimize out all the uses
119
87
// altogether.
120
88
89
+ #if ENVIRONMENT_MAY_BE_NODE && PTHREADS
90
+ // Set up the out() and err() hooks, which are how we can print to stdout or
91
+ // stderr, respectively.
92
+ // Normally just binding console.log/console.error here works fine, but
93
+ // under node (with workers) we see missing/out-of-order messages so route
94
+ // directly to stdout and stderr.
95
+ // See https://github.com/emscripten-core/emscripten/issues/14804
96
+ var defaultPrint = console . log . bind ( console ) ;
97
+ var defaultPrintErr = console . error . bind ( console ) ;
98
+ if ( ENVIRONMENT_IS_NODE ) {
99
+ var fs = require ( 'fs' ) ;
100
+ defaultPrint = ( ...args ) = > fs . writeSync ( 1 , args . join ( ' ' ) + '\n' ) ;
101
+ defaultPrintErr = ( ...args ) = > fs . writeSync ( 2 , args . join ( ' ' ) + '\n' ) ;
102
+ }
103
+ var out = defaultPrint ;
104
+ var err = defaultPrintErr ;
105
+ #else
121
106
var out = ( text ) = > console . log ( text ) ;
122
107
var err = ( text ) = > console . error ( text ) ;
108
+ #endif
123
109
124
110
// Override this function in a --pre-js file to get a signal for when
125
111
// compilation is ready. In that callback, call the function run() to start
@@ -170,5 +156,61 @@ var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function',
170
156
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER ;
171
157
#endif
172
158
159
+ if ( ENVIRONMENT_IS_WORKER ) {
160
+ _scriptDir = self . location . href ;
161
+ }
162
+ #if ENVIRONMENT_MAY_BE_NODE
163
+ else if ( ENVIRONMENT_IS_NODE ) {
164
+ _scriptDir = __filename ;
165
+ }
166
+ #endif
167
+
168
+ #if ENVIRONMENT_MAY_BE_NODE
169
+ if ( ENVIRONMENT_IS_NODE ) {
170
+ global . Worker = require ( 'worker_threads' ) . Worker ;
171
+ }
172
+ #endif
173
+
173
174
var currentScriptUrl = typeof _scriptDir != 'undefined' ? _scriptDir : ( ( typeof document != 'undefined' && document . currentScript ) ? document . currentScript . src : undefined ) ;
174
175
#endif // PTHREADS
176
+
177
+ #if ! SINGLE_FILE
178
+
179
+ #if PTHREADS
180
+ if ( ! ENVIRONMENT_IS_PTHREAD ) {
181
+ #endif
182
+
183
+ #if ENVIRONMENT_MAY_BE_NODE && ( ( WASM == 1 && ! WASM2JS ) || WASM == 2 )
184
+ // Wasm or Wasm2JS loading:
185
+
186
+ if ( ENVIRONMENT_IS_NODE ) {
187
+ var fs = require ( 'fs' ) ;
188
+ #if WASM == 2
189
+ if ( typeof WebAssembly != 'undefined' ) Module [ 'wasm' ] = fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm' ) ;
190
+ else eval ( fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm.js' ) + '' ) ;
191
+ #else
192
+ #if ! WASM2JS
193
+ Module [ 'wasm' ] = fs . readFileSync ( __dirname + '/{{{ TARGET_BASENAME }}}.wasm' ) ;
194
+ #endif
195
+ #endif
196
+ }
197
+ #endif
198
+
199
+ #if ENVIRONMENT_MAY_BE_SHELL && ( ( WASM == 1 && ! WASM2JS ) || WASM == 2 )
200
+ if ( ENVIRONMENT_IS_SHELL ) {
201
+ #if WASM == 2
202
+ if ( typeof WebAssembly != 'undefined ') Module [ 'wasm '] = read ( '{{{ TARGET_BASENAME }}}.wasm' , 'binary' ) ;
203
+ else eval ( read ( '{{{ TARGET_BASENAME }}}.wasm.js' ) + '' ) ;
204
+ #else
205
+ #if ! WASM2JS
206
+ Module [ 'wasm' ] = read ( '{{{ TARGET_BASENAME }}}.wasm' , 'binary' ) ;
207
+ #endif
208
+ #endif
209
+ }
210
+ #endif
211
+
212
+ #if PTHREADS
213
+ }
214
+ #endif
215
+
216
+ #endif // !SINGLE_FILE
0 commit comments