abrupt-completion.html (1689B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title></title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <script> 7 8 // Tests that a {Dedicated,Shared}Worker keeps running even if its script 9 // evaluation results in an abrupt completion. This corresponds to the "run a 10 // worker" algorithm disregarding the return value of "run the {classic,module} 11 // script" in its step 24: 12 // 13 // "If script is a classic script, then run the classic script script. 14 // Otherwise, it is a module script; run the module script script." 15 16 async function testWorker(worker) { 17 await new Promise(resolve => { 18 worker.onerror = e => { 19 assert_not_equals(e.message.search("uncaught-exception"), -1, 20 "Correct uncaught exception thrown by worker"); 21 22 // Suppress the exception. 23 e.preventDefault(); 24 25 resolve(); 26 } 27 }); 28 29 return new Promise(resolve => { 30 const channel = new MessageChannel(); 31 32 channel.port1.onmessage = e => { 33 assert_equals(e.data, "handler-before-throw", "Correct message handler."); 34 resolve(); 35 }; 36 37 if ('onmessage' in worker) { // dedicated worker 38 worker.postMessage("", [channel.port2]); 39 } else { // shared worker 40 worker.port.postMessage("", [channel.port2]); 41 } 42 }); 43 } 44 45 promise_test(async t => { 46 const worker = new Worker("support/abrupt-completion.js"); 47 return testWorker(worker); 48 }, "DedicatedWorker should correctly handle abrupt completion"); 49 50 promise_test(async t => { 51 const worker = new SharedWorker("support/abrupt-completion.js"); 52 return testWorker(worker); 53 }, "SharedWorker should correctly handle abrupt completion"); 54 55 </script>