shared-worker-parse-error-failure.html (2320B)
1 <!DOCTYPE html> 2 <title>SharedWorker: parse error failure</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="../support/check-error-arguments.js"></script> 6 <script> 7 8 // Use a unique URL fragment to prevent potential interference from other tests 9 // which might use the same SharedWorker URL. 10 const uniqueFragment = '#shared-worker-parse-error-failure'; 11 12 // Check if module shared worker is supported. 13 // In this test scope, we only use simple non-nested static import as a feature 14 // of module shared worker, so we only check if static import is supported. 15 // 16 // This check is necessary to appropriately test parse error handling because 17 // we need to distingusih the parse error invoked by unsupported "import" in 18 // the top-level script from the parse error invoked by the statically imported 19 // script which is the one we want to check in this test. 20 promise_setup(async () => { 21 const scriptURL = 'resources/static-import-worker.js' + uniqueFragment; 22 const worker = new SharedWorker(scriptURL, { type: 'module' }); 23 const supportsModuleWorkers = await new Promise((resolve, reject) => { 24 worker.port.onmessage = e => { 25 resolve(e.data.length == 1 && e.data[0] == 'export-on-load-script.js'); 26 }; 27 worker.onerror = () => resolve(false); 28 }); 29 assert_implements( 30 supportsModuleWorkers, 31 "Static import must be supported on module shared worker to run this test." 32 ); 33 }); 34 35 promise_test(async () => { 36 const scriptURL = 'resources/syntax-error.js' + uniqueFragment; 37 const worker = new SharedWorker(scriptURL, { type: 'module' }); 38 const args = await new Promise(resolve => 39 worker.onerror = (...args) => resolve(args)); 40 window.checkErrorArguments(args); 41 }, 'Module shared worker construction for script with syntax error should ' + 42 'dispatch an event named error.'); 43 44 promise_test(async () => { 45 const scriptURL = 'resources/static-import-syntax-error.js' + uniqueFragment; 46 const worker = new SharedWorker(scriptURL, { type: 'module' }); 47 const args = await new Promise(resolve => 48 worker.onerror = (...args) => resolve(args)); 49 window.checkErrorArguments(args); 50 }, 'Static import on module shared worker for script with syntax error ' + 51 'should dispatch an event named error.'); 52 53 </script>