@@ -3950,46 +3950,53 @@ def test_browser_run_from_different_directory(self):
3950
3950
src = open ('test.html' ).read ()
3951
3951
# Make sure JS is loaded from subdirectory
3952
3952
open ('test-subdir.html' , 'w' ).write (src .replace ('test.js' , 'subdir/test.js' ))
3953
-
3954
3953
self .run_browser ('test-subdir.html' , None , '/report_result?0' )
3955
3954
3956
3955
# Similar to `test_browser_run_from_different_directory`, but asynchronous because of `-s MODULARIZE=1`
3957
3956
def test_browser_run_from_different_directory_async (self ):
3958
3957
src = open (path_from_root ('tests' , 'browser_test_hello_world.c' )).read ()
3959
3958
open ('test.c' , 'w' ).write (self .with_report_result (src ))
3960
- # compile the code with the modularize feature and the preload-file option enabled
3961
- Popen ([PYTHON , EMCC , 'test.c' , '-o' , 'test.js' , '-s' , 'MODULARIZE=1' , '-O3' ]).communicate ()
3962
- if not os .path .exists ('subdir' ):
3963
- os .mkdir ('subdir' )
3964
- shutil .move ('test.js' , os .path .join ('subdir' , 'test.js' ))
3965
- shutil .move ('test.wasm' , os .path .join ('subdir' , 'test.wasm' ))
3966
- # Make sure JS is loaded from subdirectory
3967
- open ('test-subdir.html' , 'w' ).write ('''
3968
- <script src="subdir/test.js"></script>
3969
- <script>
3970
- Module();
3971
- </script>
3972
- ''' )
3973
-
3974
- self .run_browser ('test-subdir.html' , None , '/report_result?0' )
3959
+ for args , creations in [
3960
+ (['-s' , 'MODULARIZE=1' ], [
3961
+ 'Module();' , # documented way for using modularize
3962
+ 'new Module();' # not documented as working, but we support it
3963
+ ]),
3964
+ (['-s' , 'MODULARIZE_INSTANCE=1' ], ['' ]) # instance: no need to create anything
3965
+ ]:
3966
+ print (args )
3967
+ # compile the code with the modularize feature and the preload-file option enabled
3968
+ Popen ([PYTHON , EMCC , 'test.c' , '-o' , 'test.js' , '-O3' ] + args ).communicate ()
3969
+ if not os .path .exists ('subdir' ):
3970
+ os .mkdir ('subdir' )
3971
+ shutil .move ('test.js' , os .path .join ('subdir' , 'test.js' ))
3972
+ shutil .move ('test.wasm' , os .path .join ('subdir' , 'test.wasm' ))
3973
+ for creation in creations :
3974
+ print (creation )
3975
+ # Make sure JS is loaded from subdirectory
3976
+ open ('test-subdir.html' , 'w' ).write ('''
3977
+ <script src="subdir/test.js"></script>
3978
+ <script>
3979
+ %s
3980
+ </script>
3981
+ ''' % creation )
3982
+ self .run_browser ('test-subdir.html' , None , '/report_result?0' )
3975
3983
3976
3984
# Similar to `test_browser_run_from_different_directory`, but
3977
3985
# also also we eval the initial code, so currentScript is not present. That prevents us
3978
3986
# from finding the file in a subdir, but here we at least check we do not regress compared to the
3979
3987
# normal case of finding in the current dir.
3980
- # In addition, check for new Module(), which overrides the bind() and replaces the object
3981
- # which saved the _scriptDir. Again, we can't get the script dir that way, but at least we
3982
- # should not regress compared to the normal case.
3983
3988
def test_browser_modularize_no_current_script (self ):
3984
3989
src = open (path_from_root ('tests' , 'browser_test_hello_world.c' )).read ()
3985
3990
open ('test.c' , 'w' ).write (self .with_report_result (src ))
3986
- # compile the code with the modularize feature and the preload-file option enabled
3987
- Popen ([PYTHON , EMCC , 'test.c' , '-o' , 'test.js' , '-s' , 'MODULARIZE=1' ]).communicate ()
3988
- for creation in (
3989
- 'Module();' ,
3990
- 'new Module();'
3991
- ):
3992
- print (creation )
3991
+ # test both modularize (and creating an instance) and modularize-instance
3992
+ # (which creates by itself)
3993
+ for args , creation in [
3994
+ (['-s' , 'MODULARIZE=1' ], 'Module();' ),
3995
+ (['-s' , 'MODULARIZE_INSTANCE=1' ], '' )
3996
+ ]:
3997
+ print (args , creation )
3998
+ # compile the code with the modularize feature and the preload-file option enabled
3999
+ Popen ([PYTHON , EMCC , 'test.c' , '-o' , 'test.js' ] + args ).communicate ()
3993
4000
open ('test.html' , 'w' ).write ('''
3994
4001
<script>
3995
4002
setTimeout(function() {
0 commit comments