summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/abrupt_completion_worker.js
blob: 7afebc6d45227b6119827dc0b0c4cc80973f356f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function setMessageHandler(response) {
  onmessage = e => {
    e.source.postMessage(response);
  };
}

setMessageHandler("handler-before-throw");

// importScripts will throw when the ServiceWorker is past the "intalling" state.
importScripts(`empty.js?${Date.now()}`);

// When importScripts throws an uncaught exception, these calls should never be
// made and the message handler should remain responding "handler-before-throw".
setMessageHandler("handler-after-throw");

// There needs to be a fetch handler to avoid the no-fetch optimizaiton,
// which will skip starting up this worker.
onfetch = e => e.respondWith(new Response("handler-after-throw"));