-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: align DedicatedWorkerGlobalScope event handlers to spec (#11353)
- Loading branch information
Andreu Botella
authored
Jul 10, 2021
1 parent
67c9937
commit eea6000
Showing
6 changed files
with
81 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const w = new Worker( | ||
new URL("./workers/worker_event_handlers.js", import.meta.url).href, | ||
{ type: "module" }, | ||
); | ||
w.postMessage({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Target from self.onmessage: [object DedicatedWorkerGlobalScope] | ||
Target from message event listener: [object DedicatedWorkerGlobalScope] | ||
Arguments from self.onerror: [ | ||
"Some error message", | ||
"", | ||
0, | ||
0, | ||
Error: Some error message | ||
at [WILDCARD] | ||
] | ||
Is event canceled?: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
self.onmessage = (evt) => { | ||
console.log("Target from self.onmessage:", String(evt.target)); | ||
}; | ||
|
||
self.addEventListener("message", (evt) => { | ||
console.log("Target from message event listener:", String(evt.target)); | ||
|
||
// Throw an error here so the global's error event will fire. | ||
throw new Error("Some error message"); | ||
}); | ||
|
||
self.onerror = (...args) => { | ||
console.log("Arguments from self.onerror:", args); | ||
return true; | ||
}; | ||
|
||
self.addEventListener("error", (evt) => { | ||
// Returning true from self.onerror means that subsequent event listeners | ||
// should see the event as canceled. | ||
console.log("Is event canceled?:", evt.defaultPrevented); | ||
|
||
self.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters