diff --git a/emcc.py b/emcc.py index 564a10468b747..6c1a7d433b88d 100644 --- a/emcc.py +++ b/emcc.py @@ -3920,15 +3920,10 @@ def modularize(): return %(return_value)s } -%(capture_module_function_for_audio_worklet)s ''' % { 'maybe_async': async_emit, 'src': src, 'return_value': return_value, - # Given the async nature of how the Module function and Module object come into existence in AudioWorkletGlobalScope, - # store the Module function under a different variable name so that AudioWorkletGlobalScope will be able to reference - # it without aliasing/conflicting with the Module variable name. - 'capture_module_function_for_audio_worklet': 'globalThis.AudioWorkletModule = Module;' if settings.AUDIO_WORKLET and settings.MODULARIZE else '' } if settings.MINIMAL_RUNTIME and not settings.PTHREADS: @@ -3953,6 +3948,7 @@ def modularize(): %(script_url_node)s return (%(src)s); })(); +globalThis.AudioWorkletModule = %(EXPORT_NAME)s; ''' % { 'node_imports': node_es6_imports(), 'EXPORT_NAME': settings.EXPORT_NAME, diff --git a/test/test_browser.py b/test/test_browser.py index 12bd6420e3d21..2b32e5381d874 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5611,6 +5611,13 @@ def test_audio_worklet(self, args): def test_audio_worklet_post_function(self, args): self.btest('webaudio/audioworklet_post_function.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'] + args, expected='1') + @parameterized({ + '': ([],), + 'closure': (['--closure', '1', '-Oz'],), + }) + def test_audio_worklet_modularize(self, args): + self.btest_exit('webaudio/audioworklet.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sMODULARIZE=1', '-sEXPORT_NAME=MyModule', '--shell-file', test_file('shell_that_launches_modularize.html')] + args) + def test_error_reporting(self): # Test catching/reporting Error objects create_file('post.js', 'throw new Error("oops");')