dedicated-worker-parse-error-failure.html (2155B)
1 <!DOCTYPE html> 2 <title>DedicatedWorker: parse error failure</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> setup({allow_uncaught_exception: true}); </script> 6 <script src="../support/check-error-arguments.js"></script> 7 <script> 8 9 // Check if module scripts are supported on dedicated workers. There is no 10 // direct way to detect it, so we assume it's supported when static import is 11 // available on the workers. 12 // 13 // This check is necessary to appropriately test parse error handling because 14 // we need to distinguish the parse error invoked by unsupported "import" in 15 // the top-level script from the parse error invoked by the statically imported 16 // script which is the one we want to check in this test. 17 promise_setup(async () => { 18 const scriptURL = 'resources/static-import-worker.js'; 19 const worker = new Worker(scriptURL, { type: 'module' }); 20 worker.postMessage('Send message for tests from main script.'); 21 const supportsModuleWorkers = await new Promise((resolve, reject) => { 22 worker.onmessage = e => { 23 resolve(e.data.length == 1 && e.data[0] == 'export-on-load-script.js'); 24 }; 25 worker.onerror = () => resolve(false); 26 }); 27 assert_implements( 28 supportsModuleWorkers, 29 "Static import must be supported on module dedicated worker to run this test." 30 ); 31 }); 32 33 promise_test(async () => { 34 const scriptURL = 'resources/syntax-error.js'; 35 const worker = new Worker(scriptURL, { type: 'module' }); 36 const args = await new Promise(resolve => 37 worker.onerror = (...args) => resolve(args)); 38 window.checkErrorArguments(args); 39 }, 'Module worker construction for script with syntax error should dispatch ' + 40 'an event named error.'); 41 42 promise_test(async () => { 43 const scriptURL = 'resources/static-import-syntax-error.js'; 44 const worker = new Worker(scriptURL, { type: 'module' }); 45 const args = await new Promise(resolve => 46 worker.onerror = (...args) => resolve(args)); 47 window.checkErrorArguments(args); 48 }, 'Static import on module worker for script with syntax error should ' + 49 'dispatch an event named error.'); 50 51 </script>