@@ -5395,21 +5395,39 @@ def test_fetch_polyfill_preload(self):
53955395        fread(buf, 1, 20, f); 
53965396        buf[20] = 0; 
53975397        fclose(f); 
5398-         printf("| %%s| \n", buf); 
5399-         return 42 ; 
5398+         printf("%%s\n", buf); 
5399+         return 0 ; 
54005400      } 
54015401      '''  %  path )
5402+     create_file ('on_window_error_shell.html' , r''' 
5403+       <html> 
5404+           <center><canvas id='canvas' width='256' height='256'></canvas></center> 
5405+           <hr><div id='output'></div><hr> 
5406+           <script type='text/javascript'> 
5407+             window.addEventListener('error', event => { 
5408+               const error = String(event.message); 
5409+               console.log({error}); 
5410+               window.disableErrorReporting = true; 
5411+               window.onerror = null; 
5412+               var xhr = new XMLHttpRequest(); 
5413+               xhr.open('GET', 'http://localhost:8888/report_result?exception:' + error.substr(-23), true); 
5414+               xhr.send(); 
5415+               setTimeout(function() { window.close() }, 1000); 
5416+             }); 
5417+           </script> 
5418+           {{{ SCRIPT }}} 
5419+         </body>''' )
54025420
54035421    def  test (args , expect_fail ):
5404-       self .compile_btest ('main.cpp' , ['-sEXIT_RUNTIME' , '--preload-file' , path , '-o' , 'a.out.html' ] +  args )
5422+       self .compile_btest ('main.cpp' , ['-sEXIT_RUNTIME' , '--preload-file' , path , '--shell-file'  ,  'on_window_error_shell.html' ,  '- o''a.out.html' ] +  args )
54055423      if  expect_fail :
54065424        js  =  read_file ('a.out.js' )
54075425        create_file ('a.out.js' , 'let origFetch = fetch; fetch = undefined;\n '  +  js )
54085426        return  self .run_browser ('a.out.html' , '/report_result?exception:fetch is not a function' )
54095427      else :
5410-         return  self .run_browser ('a.out.html' , '/report_result?exit:42 ' )
5428+         return  self .run_browser ('a.out.html' , '/report_result?exit:0 ' )
54115429
5412-     test ([], expect_fail = False )
5430+     test ([], expect_fail = True )
54135431    test (['-sLEGACY_VM_SUPPORT' ], expect_fail = False )
54145432    test (['-sLEGACY_VM_SUPPORT' , '-sNO_POLYFILL' ], expect_fail = True )
54155433
0 commit comments