summaryrefslogtreecommitdiff
path: root/op_crates/web/01_event.js
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2020-12-04 19:47:08 +0200
committerGitHub <noreply@github.com>2020-12-04 12:47:08 -0500
commit71ef5a9cd33390f7f41b80cdb57862b7f7507f76 (patch)
treee67a19826c27c41ea50919030b9b54d49a145cf1 /op_crates/web/01_event.js
parentae21a9569b87411f863fa5194c873be69d8bee93 (diff)
feat(op_crates/web) EventTarget signal support (#8616)
Fixes: https://github.com/denoland/deno/issues/8606
Diffstat (limited to 'op_crates/web/01_event.js')
-rw-r--r--op_crates/web/01_event.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/op_crates/web/01_event.js b/op_crates/web/01_event.js
index ed76a4281..35b269ea4 100644
--- a/op_crates/web/01_event.js
+++ b/op_crates/web/01_event.js
@@ -693,7 +693,7 @@
for (let i = 0; i < handlers.length; i++) {
const listener = handlers[i];
- let capture, once, passive;
+ let capture, once, passive, signal;
if (typeof listener.options === "boolean") {
capture = listener.options;
once = false;
@@ -895,7 +895,19 @@
return;
}
}
-
+ if (options?.signal) {
+ const signal = options?.signal;
+ if (signal.aborted) {
+ // If signal is not null and its aborted flag is set, then return.
+ return;
+ } else {
+ // If listener’s signal is not null, then add the following abort
+ // abort steps to it: Remove an event listener.
+ signal.addEventListener("abort", () => {
+ this.removeEventListener(type, callback, options);
+ });
+ }
+ }
listeners[type].push({ callback, options });
}