@@ -751,24 +751,26 @@ def test_custom_file_package_url(self):
751751    self .run_browser ('test.html' , '/report_result?exit:0' )
752752
753753  def  test_missing_data_throws_error (self ):
754+     create_file ('data.txt' , 'data' )
755+     create_file ('main.c' , r''' 
756+       #include <stdio.h> 
757+       #include <string.h> 
758+       #include <emscripten.h> 
759+       int main() { 
760+         // This code should never be executed in terms of missing required dependency file. 
761+         return 0; 
762+       } 
763+     ''' )
764+ 
754765    def  setup (assetLocalization ):
755-       self .clear ()
756-       create_file ('data.txt' , 'data' )
757-       create_file ('main.c' , r''' 
758-         #include <stdio.h> 
759-         #include <string.h> 
760-         #include <emscripten.h> 
761-         int main() { 
762-           // This code should never be executed in terms of missing required dependency file. 
763-           return 0; 
764-         } 
765-       ''' )
766766      create_file ('on_window_error_shell.html' , r''' 
767767      <html> 
768+         <body> 
768769          <center><canvas id='canvas' width='256' height='256'></canvas></center> 
769770          <hr><div id='output'></div><hr> 
770771          <script type='text/javascript'> 
771-             const handler = async (event) => { 
772+             const errorHandler = async (event) => { 
773+               if (window.disableErrorReporting) return; 
772774              event.stopImmediatePropagation(); 
773775              const error = String(event instanceof ErrorEvent ? event.message : (event.reason || event)); 
774776              window.disableErrorReporting = true; 
@@ -777,39 +779,42 @@ def setup(assetLocalization):
777779              await fetch('http://localhost:8888/report_result?' + result); 
778780              window.close(); 
779781            } 
780-             window.addEventListener('error', handler); 
781-             window.addEventListener('unhandledrejection', handler); 
782+             window.addEventListener('error', errorHandler); 
783+             window.addEventListener('unhandledrejection', errorHandler); 
784+             const outputElem = document.getElementById('output'); 
782785            var Module = { 
783-               locateFile: function (path, prefix) {if (path.endsWith(".wasm")) {return prefix + path;} else {return "'''  +  assetLocalization  +  r'''" + path;}}, 
784-               print: (function() { 
785-                 var element = document.getElementById('output'); 
786-                 return function(text) { element.innerHTML += text.replace('\n', '<br>', 'g') + '<br>';}; 
787-               })(), 
786+               locateFile: (path, prefix) => { 
787+                 if (path.endsWith('.wasm')) { 
788+                   return prefix + path; 
789+                 } else { 
790+                   return "'''  +  assetLocalization  +  r'''" + path; 
791+                 } 
792+               }, 
793+               print: () => { 
794+                 outputElem.innerHTML += text.replace('\n', '<br>', 'g') + '<br>'; 
795+               }, 
788796              canvas: document.getElementById('canvas') 
789797            }; 
790798          </script> 
791799          {{{ SCRIPT }}} 
792800        </body> 
793801      </html>''' )
794802
795-     def  test ():
796-       # test test missing file should run xhr.onload with status different than 200, 304 or 206 
797-       setup ("" )
798-       self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
799-       shutil .move ('test.data' , 'missing.data' )
800-       self .run_browser ('test.html' , '/report_result?1' )
801- 
802-       # test unknown protocol should go through xhr.onerror 
803-       setup ("unknown_protocol://" )
804-       self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
805-       self .run_browser ('test.html' , '/report_result?1' )
806- 
807-       # test wrong protocol and port 
808-       setup ("https://localhost:8800/" )
809-       self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
810-       self .run_browser ('test.html' , '/report_result?1' )
811- 
812-     test ()
803+     # test test missing file should run xhr.onload with status different than 200, 304 or 206 
804+     setup ("" )
805+     self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
806+     shutil .move ('test.data' , 'missing.data' )
807+     self .run_browser ('test.html' , '/report_result?1' )
808+ 
809+     # test unknown protocol should go through xhr.onerror 
810+     setup ("unknown_protocol://" )
811+     self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
812+     self .run_browser ('test.html' , '/report_result?1' )
813+ 
814+     # test wrong protocol and port 
815+     setup ("https://localhost:8800/" )
816+     self .compile_btest ('main.c' , ['--shell-file' , 'on_window_error_shell.html' , '--preload-file' , 'data.txt' , '-o' , 'test.html' ])
817+     self .run_browser ('test.html' , '/report_result?1' )
813818
814819    # TODO: CORS, test using a full url for locateFile 
815820    # create_file('shell.html', read_file(path_from_root('src/shell.html')).replace('var Module = {', 'var Module = { locateFile: function (path) {return "http:/localhost:8888/cdn/" + path;}, ')) 
0 commit comments