@@ -383,6 +383,7 @@ def decorated(self, textdecoder, *args, **kwargs):
383383
384384no_minimal_runtime = make_no_decorator_for_setting ('MINIMAL_RUNTIME' )
385385no_safe_heap = make_no_decorator_for_setting ('SAFE_HEAP' )
386+ no_strict = make_no_decorator_for_setting ('STRICT' )
386387
387388
388389def is_sanitizing (args ):
@@ -646,6 +647,8 @@ def test_sha1(self):
646647 self .do_runf ('third_party/sha1.c' , 'SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6' )
647648
648649 def test_core_types (self ):
650+ if self .get_setting ('STRICT' ):
651+ self .emcc_args += ['-DIN_STRICT_MODE=1' ]
649652 self .do_runf ('core/test_core_types.c' )
650653
651654 def test_cube2md5 (self ):
@@ -2649,6 +2652,7 @@ def test_pthread_abort(self):
26492652 # handler will only be present in the main thread (much like it would if it
26502653 # was passed in by pre-populating the module object on prior to loading).
26512654 self .add_pre_run ("Module.onAbort = () => console.log('onAbort called');" )
2655+ self .emcc_args += ['-sINCOMING_MODULE_JS_API=[preRun,onAbort]' ]
26522656 self .do_run_in_out_file_test ('pthread/test_pthread_abort.c' , assert_returncode = NON_ZERO )
26532657
26542658 @node_pthreads
@@ -4159,7 +4163,7 @@ def test_dylink_locate_file(self):
41594163 }
41604164 };
41614165 ''' % (so_name , so_dir ))
4162- self .do_basic_dylink_test (so_dir = so_dir , so_name = so_name , main_emcc_args = ['--pre-js' , 'pre.js' ])
4166+ self .do_basic_dylink_test (so_dir = so_dir , so_name = so_name , main_emcc_args = ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[locateFile]' ])
41634167
41644168 @with_dylink_reversed
41654169 def test_dylink_function_pointer_equality (self ):
@@ -5209,7 +5213,7 @@ class Bar : public Foo {
52095213 @needs_dylink
52105214 def test_dylink_argv_argc (self ):
52115215 # Verify that argc and argv can be sent to main when main is in a side module
5212- self .emcc_args += ['--pre-js' , 'pre.js' ]
5216+ self .emcc_args += ['--pre-js' , 'pre.js' , '--no-entry' , '-sINCOMING_MODULE_JS_API=[arguments]' ]
52135217 create_file ('pre.js' , "Module['arguments'] = ['hello', 'world!']" )
52145218 self .dylink_test (
52155219 '' , # main module is empty.
@@ -5424,6 +5428,7 @@ def test_langinfo(self):
54245428 self .do_core_test ('test_langinfo.c' )
54255429
54265430 @no_modularize_instance ('uses Module object directly' )
5431+ @no_strict ('TODO: Fails in -sSTRICT mode due to an unknown reason.' )
54275432 def test_files (self ):
54285433 # Use closure here, to test we don't break FS stuff
54295434 if '-O3' in self .emcc_args and self .is_wasm2js ():
@@ -5435,7 +5440,7 @@ def test_files(self):
54355440 else :
54365441 self .maybe_closure ()
54375442
5438- self .emcc_args += ['--pre-js' , 'pre.js' ]
5443+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[preRun]' ]
54395444 self .set_setting ('FORCE_FILESYSTEM' )
54405445
54415446 create_file ('pre.js' , '''
@@ -5467,7 +5472,7 @@ def test_module_stdin(self):
54675472 stdout: (x) => out('got: ' + x)
54685473 };
54695474 ''' )
5470- self .emcc_args += ['--pre-js' , 'pre.js' ]
5475+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[stdin,stdout]' ]
54715476
54725477 src = r'''
54735478 #include <stdio.h>
@@ -5916,7 +5921,7 @@ def test_fs_no_main(self):
59165921''' )
59175922 self .set_setting ('EXPORTED_FUNCTIONS' , '_foo' )
59185923 self .set_setting ('FORCE_FILESYSTEM' )
5919- self .emcc_args += ['--pre-js' , 'pre.js' ]
5924+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[preRun, onRuntimeInitialized]' ]
59205925 self .do_run ('int foo() { return 42; }' , '' , force_c = True )
59215926
59225927 @also_with_noderawfs
@@ -6160,6 +6165,8 @@ def test_posixtime(self):
61606165 self .do_core_test ('test_posixtime.c' )
61616166
61626167 def test_uname (self ):
6168+ if self .get_setting ('STRICT' ):
6169+ self .emcc_args += ['-lstubs' ]
61636170 self .do_core_test ('test_uname.c' , regex = True )
61646171
61656172 def test_unary_literal (self ):
@@ -6189,6 +6196,8 @@ def test_stddef(self):
61896196 self .do_core_test ('test_stddef.cpp' , force_c = True )
61906197
61916198 def test_getloadavg (self ):
6199+ if self .get_setting ('STRICT' ):
6200+ self .emcc_args += ['-lstubs' ]
61926201 self .do_core_test ('test_getloadavg.c' )
61936202
61946203 def test_nl_types (self ):
@@ -6718,17 +6727,17 @@ def test_gcc_unmangler(self):
67186727 @needs_make ('configure script' )
67196728 @is_slow_test
67206729 def test_freetype (self ):
6730+ # Not needed for js, but useful for debugging
6731+ shutil .copy (test_file ('freetype/LiberationSansBold.ttf' ), 'font.ttf' )
6732+ ftlib = self .get_freetype_library ()
6733+
67216734 if self .get_setting ('WASMFS' ):
67226735 self .emcc_args += ['-sFORCE_FILESYSTEM' ]
67236736
67246737 self .add_pre_run ("FS.createDataFile('/', 'font.ttf', %s, true, false, false);" % str (
67256738 list (bytearray (read_binary (test_file ('freetype/LiberationSansBold.ttf' )))),
67266739 ))
67276740
6728- # Not needed for js, but useful for debugging
6729- shutil .copy (test_file ('freetype/LiberationSansBold.ttf' ), 'font.ttf' )
6730- ftlib = self .get_freetype_library ()
6731-
67326741 # Main
67336742 self .do_run_in_out_file_test ('freetype/main.c' ,
67346743 args = ['font.ttf' , 'test!' , '150' , '120' , '25' ],
@@ -6764,6 +6773,8 @@ def test_freetype(self):
67646773 'pthreads' : (True ,),
67656774 })
67666775 def test_sqlite (self , use_pthreads ):
6776+ if self .get_setting ('STRICT' ):
6777+ self .emcc_args += ['-lstubs' ]
67676778 if use_pthreads :
67686779 self .emcc_args .append ('-pthread' )
67696780 self .setup_node_pthreads ()
@@ -6848,7 +6859,7 @@ def test_poppler(self):
68486859 out("Data: " + JSON.stringify(FileData.map(function(x) { return unSign(x, 8) })));
68496860 };
68506861 ''' )
6851- self .emcc_args += ['--pre-js' , 'pre.js' , '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$unSign' ]
6862+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$unSign' , '-sINCOMING_MODULE_JS_API=[preRun, postRun]' ]
68526863
68536864 ppm_data = str (list (bytearray (read_binary (test_file ('poppler/ref.ppm' )))))
68546865 self .do_run ('' , ppm_data .replace (' ' , '' ),
@@ -6936,7 +6947,7 @@ def image_compare(output):
69366947 assert diff_mean < 0.01 , diff_mean
69376948
69386949 self .emcc_args += ['--minify=0' ] # to compare the versions
6939- self .emcc_args += ['--pre-js' , 'pre.js' ]
6950+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[preRun,postRun]' ]
69406951
69416952 output = self .do_runf ('third_party/openjpeg/codec/j2k_to_image.c' ,
69426953 'Successfully generated' , # The real test for valid output is in image_compare
@@ -7136,6 +7147,7 @@ def test(output_prefix='', args=None, assert_returncode=0):
71367147 test (args = ['-sFORCE_FILESYSTEM' ])
71377148
71387149 @no_modularize_instance ('uses Module object directly' )
7150+ @no_strict ('This test verifies legacy behavior that does not apply to -sSTRICT builds.' )
71397151 def test_legacy_exported_runtime_numbers (self ):
71407152 # these used to be exported, but no longer are by default
71417153 def test (expected , args = None , assert_returncode = 0 ):
@@ -7574,7 +7586,7 @@ def test_embind_val_coro(self):
75747586 create_file ('pre.js' , r'''Module.onRuntimeInitialized = () => {
75757587 Module.asyncCoro().then(console.log);
75767588 }''' )
7577- self .emcc_args += ['-std=c++20' , '--bind' , '--pre-js=pre.js' ]
7589+ self .emcc_args += ['-std=c++20' , '--bind' , '--pre-js=pre.js' , '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' , '--no-entry' ]
75787590 self .do_runf ('embind/test_val_coro.cpp' , '34\n ' )
75797591
75807592 def test_embind_val_coro_caught (self ):
@@ -7585,7 +7597,7 @@ def test_embind_val_coro_caught(self):
75857597 err => console.error(`rejected with: ${err.stack}`)
75867598 );
75877599 }''' )
7588- self .emcc_args += ['-std=c++20' , '--bind' , '--pre-js=pre.js' , '-fexceptions' ]
7600+ self .emcc_args += ['-std=c++20' , '--bind' , '--pre-js=pre.js' , '-fexceptions' , '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' , '--no-entry' ]
75897601 self .do_runf ('embind/test_val_coro.cpp' , 'rejected with: std::runtime_error: bang from throwingCoro!\n ' )
75907602
75917603 def test_embind_dynamic_initialization (self ):
@@ -7689,6 +7701,7 @@ def test_embind_wasm_workers(self):
76897701 'all_growth' : ('ALL' , True ),
76907702 })
76917703 @no_modularize_instance ('uses Module global' )
7704+ @no_strict ('TODO: Fails in -sSTRICT mode due to an unknown reason.' )
76927705 def test_webidl (self , mode , allow_memory_growth ):
76937706 self .set_setting ('WASM_ASYNC_COMPILATION' , 0 )
76947707 if self .maybe_closure ():
@@ -8057,7 +8070,7 @@ def test_exit_status(self):
80578070 assert(status == EXITSTATUS);
80588071 };
80598072 ''' )
8060- self .emcc_args += ['--pre-js' , 'pre.js' ]
8073+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[onExit]' ]
80618074 print ('.. exit' )
80628075 self .do_runf ('exit.c' , 'hello, world!\n cleanup\n I see exit status: 117' , assert_returncode = 117 , emcc_args = ['-DNORMAL_EXIT' ])
80638076 print ('.. _exit' )
@@ -8174,7 +8187,7 @@ def test_async_ccall_bad(self):
81748187 }
81758188};
81768189''' )
8177- self .emcc_args += ['--pre-js' , 'pre.js' ]
8190+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' ]
81788191 self .do_runf ('main.c' , 'The call to main is running asynchronously.' )
81798192
81808193 @with_asyncify_and_jspi
@@ -8199,7 +8212,7 @@ def test_async_ccall_good(self):
81998212 ccall('main', null, ['number', 'string'], [2, 'waka'], { async: true });
82008213};
82018214''' )
8202- self .emcc_args += ['--pre-js' , 'pre.js' ]
8215+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' ]
82038216 self .do_runf ('main.c' , 'HelloWorld' )
82048217
82058218 @parameterized ({
@@ -8244,7 +8257,7 @@ def test_async_ccall_promise(self, exit_runtime):
82448257 });
82458258};
82468259''' )
8247- self .emcc_args += ['--pre-js' , 'pre.js' ]
8260+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' ]
82488261 self .do_runf ('main.c' , 'stringf: first\n second\n 6.4' )
82498262
82508263 @no_esm_integration ('WASM_ESM_INTEGRATION is not compatible with ASYNCIFY=1' )
@@ -8585,7 +8598,7 @@ def test_fs_dict(self):
85858598 out(typeof NODEFS);
85868599 };
85878600 ''' )
8588- self .emcc_args += ['--pre-js' , 'pre.js' ]
8601+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[preRun]' ]
85898602 self .do_run ('int main() { return 0; }' , 'object\n object\n object\n object\n object\n object' )
85908603
85918604 def test_fs_dict_none (self ):
@@ -8609,7 +8622,7 @@ def test_fs_dict_none(self):
86098622 }
86108623 };
86118624 ''' )
8612- self .emcc_args += ['--pre-js' , 'pre.js' ]
8625+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[preRun]' ]
86138626 expected = '''\
86148627 object
86158628undefined
@@ -8718,7 +8731,7 @@ def test_postrun_exception(self):
87188731 def test_postrun_exit_runtime (self ):
87198732 create_file ('pre.js' , "Module['postRun'] = () => err('post run\\ n');" )
87208733 self .set_setting ('EXIT_RUNTIME' )
8721- self .emcc_args . append ( '--pre-js=pre.js' )
8734+ self .emcc_args += [ '--pre-js=pre.js' , '-sINCOMING_MODULE_JS_API=[postRun]' ]
87228735 self .do_runf ('hello_world.c' , 'post run' )
87238736
87248737 # Tests that building with -sDECLARE_ASM_MODULE_EXPORTS=0 works
@@ -9236,7 +9249,7 @@ def test_pthread_exceptions(self):
92369249 def test_pthread_exit_process (self ):
92379250 self .set_setting ('PROXY_TO_PTHREAD' )
92389251 self .set_setting ('EXIT_RUNTIME' )
9239- self .emcc_args += ['-DEXIT_RUNTIME' , '--pre-js' , test_file ('core/pthread/test_pthread_exit_runtime.pre.js' )]
9252+ self .emcc_args += ['-DEXIT_RUNTIME' , '--pre-js' , test_file ('core/pthread/test_pthread_exit_runtime.pre.js' ), '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized, onExit]' ]
92409253 self .do_run_in_out_file_test ('core/pthread/test_pthread_exit_runtime.c' , assert_returncode = 42 )
92419254
92429255 @node_pthreads
@@ -9404,6 +9417,10 @@ def test_pthread_dylink_longjmp(self):
94049417 @needs_dylink
94059418 @node_pthreads
94069419 def test_pthread_dylink_main_module_1 (self ):
9420+ # TODO: For some reason, -lhtml5 must be passed in -sSTRICT mode, but can NOT
9421+ # be passed when not compiling in -sSTRICT mode. That does not seem intentional?
9422+ if self .get_setting ('STRICT' ):
9423+ self .emcc_args += ['-lhtml5' ]
94079424 self .emcc_args += ['-Wno-experimental' , '-pthread' ]
94089425 self .set_setting ('MAIN_MODULE' )
94099426 self .do_runf ('hello_world.c' )
@@ -9416,7 +9433,7 @@ def test_pthread_dylink_main_module_1(self):
94169433 def test_Module_dynamicLibraries (self , args ):
94179434 # test that Module.dynamicLibraries works with pthreads
94189435 self .emcc_args += args
9419- self .emcc_args += ['--pre-js' , 'pre.js' ]
9436+ self .emcc_args += ['--pre-js' , 'pre.js' , '-sINCOMING_MODULE_JS_API=[dynamicLibraries]' ]
94209437 self .emcc_args += ['--js-library' , 'lib.js' ]
94219438 # This test is for setting dynamicLibraries at runtime, so we don't
94229439 # want emscripten loading `liblib.so` automatically (which it would
@@ -9537,7 +9554,7 @@ def test_abort_on_exceptions(self):
95379554 self .set_setting ('ABORT_ON_WASM_EXCEPTIONS' )
95389555 self .set_setting ('ALLOW_TABLE_GROWTH' )
95399556 self .set_setting ('EXPORTED_RUNTIME_METHODS' , ['ccall' , 'cwrap' ])
9540- self .set_setting ('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE' , ['$addFunction' ])
9557+ self .set_setting ('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE' , ['$addFunction' , '$addOnPostRun' ])
95419558 self .emcc_args += ['-lembind' , '--post-js' , test_file ('core/test_abort_on_exceptions_post.js' )]
95429559 self .do_core_test ('test_abort_on_exceptions.cpp' , interleaved_output = False )
95439560
@@ -9564,6 +9581,10 @@ def test_abort_on_exceptions_pthreads(self):
95649581
95659582 @needs_dylink
95669583 def test_gl_main_module (self ):
9584+ # TODO: For some reason, -lGL must be passed in -sSTRICT mode, but can NOT
9585+ # be passed when not compiling in -sSTRICT mode. That does not seem intentional?
9586+ if self .get_setting ('STRICT' ):
9587+ self .emcc_args += ['-lGL' ]
95679588 self .set_setting ('MAIN_MODULE' )
95689589 self .emcc_args += ['-sGL_ENABLE_GET_PROC_ADDRESS' ]
95699590 self .do_runf ('core/test_gl_get_proc_address.c' )
@@ -9592,6 +9613,8 @@ def test_embind_lib_with_asyncify(self, args):
95929613 '-sASYNCIFY_IMPORTS=sleep_and_return' ,
95939614 '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$ASSERTIONS' ,
95949615 '--post-js' , test_file ('core/embind_lib_with_asyncify.test.js' ),
9616+ '--no-entry' ,
9617+ '-sINCOMING_MODULE_JS_API=[onRuntimeInitialized]' ,
95959618 ]
95969619 self .emcc_args += args
95979620 self .do_core_test ('embind_lib_with_asyncify.cpp' )
0 commit comments