1
0
Fork 0
firefox/dom/serviceworkers/test/abrupt_completion_worker.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

18 lines
660 B
JavaScript

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"));