@@ -27,6 +27,7 @@ if (ENVIRONMENT_IS_WORKER) {
2727{ { { exportRuntime ( ) } } }
2828
2929var calledRun ;
30+ var calledPrerun ;
3031
3132#if STANDALONE_WASM && MAIN_READS_PARAMS
3233var mainArgs = undefined ;
@@ -46,7 +47,7 @@ function callMain() {
4647#endif
4748#if ASSERTIONS
4849 assert ( runDependencies == 0 , 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])' ) ;
49- assert ( __ATPRERUN__ . length == 0 , 'cannot call main when preRun functions remain to be called ' ) ;
50+ assert ( calledPrerun , 'cannot call main without calling preRun first ' ) ;
5051#endif
5152
5253 var entryFunction = { { { getEntryFunction( ) } } } ;
@@ -191,22 +192,25 @@ function run() {
191192 }
192193#endif
193194
194- preRun ( ) ;
195+ if ( ! calledPrerun ) {
196+ calledPrerun = 1 ;
197+ preRun ( ) ;
195198
196- // a preRun added a dependency, run will be called later
197- if ( runDependencies > 0 ) {
199+ // a preRun added a dependency, run will be called later
200+ if ( runDependencies > 0 ) {
198201#if RUNTIME_DEBUG
199- dbg ( 'run() called, but dependencies remain, so not running' ) ;
202+ dbg ( 'run() called, but dependencies remain, so not running' ) ;
200203#endif
201- return ;
204+ return ;
205+ }
202206 }
203207
204208 function doRun ( ) {
205209 // run may have just been called through dependencies being fulfilled just in this very frame,
206210 // or while the async setStatus time below was happening
207211 if ( calledRun ) return ;
208- calledRun = true ;
209- Module [ 'calledRun' ] = true ;
212+ calledRun = 1 ;
213+ Module [ 'calledRun' ] = 1 ;
210214
211215 if ( ABORT ) return ;
212216
0 commit comments