test_exception.html (1809B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for Exception in Worklet script</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 <script type="application/javascript" src="common.js"></script> 8 </head> 9 <body> 10 11 <script type="application/javascript"> 12 // This function is called into an iframe. 13 function runTestInIframe() { 14 let error; 15 16 // This loading should fail 17 var audioContext = new AudioContext(); 18 audioContext.audioWorklet.addModule("404.js") 19 .then(() => { 20 ok(false, "We should not be called!"); 21 }, () => { 22 ok(true, "The script thrown but we are still here."); 23 }) 24 25 // This should throw from JS 26 .then(() => { 27 return audioContext.audioWorklet.addModule("worklet_exception.js") 28 }) 29 .then(() => { 30 ok(true, "The script threw but we are still here."); 31 }, () => { 32 ok(false, "We should not be called!"); 33 }) 34 35 // invalid_specifier.mjs will throw a TypeError. 36 .then(() => { 37 return audioContext.audioWorklet.addModule("invalid_specifier.mjs") 38 }) 39 .then(() => { 40 ok(false, "We should not be called!"); 41 }, (e) => { 42 ok(true, "The script thrown but we are still here."); 43 ok(e instanceof TypeError, "The error should be a TypeError."); 44 error = e; 45 }) 46 47 // import "invalid_specifier.mjs" again, this will reuse the response from the 48 // previous addModule("invalid_specifier.mjs") call. 49 .then(() => { 50 return audioContext.audioWorklet.addModule("invalid_specifier.mjs") 51 }) 52 .then(() => { 53 ok(false, "We should not be called!"); 54 }, (e) => { 55 ok(true, "The script thrown but we are still here."); 56 ok (e === error, "The TypeError object should be reused."); 57 }) 58 59 .then(() => { 60 SimpleTest.finish(); 61 }); 62 } 63 64 </script> 65 </body> 66 </html>