From 77048390392a30640ab1fb386a3a4a33094dac5e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 22:43:25 +0100 Subject: [PATCH] fix: align AbortSignal to spec using WPT (#9007) --- cli/tests/wpt.jsonc | 13 +++++++++++-- op_crates/web/01_event.js | 10 ++++++++++ op_crates/web/02_abort_signal.js | 6 +++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 3e151b95458390..479b6a74757f8d 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -22,7 +22,13 @@ "api-invalid-label", "api-replacement-encodings", "api-surrogates-utf8", - // TODO(lucacasonato): enable encodeInto. It is buggy at the moment. + // TODO(lucacasonato): enable encodeInto. We have a bug in implementaiton. + // { + // "name": "encodeInto", + // "expectFail": [ + // "encodeInto() and a detached output buffer" + // ] + // }, // "encodeInto", // TODO(lucacasonato): enable when we support iso-2022-jp // "iso-2022-jp-decoder", @@ -110,7 +116,7 @@ "utf-16le => UTF-16LE", "x-user-defined => x-user-defined" ] - } + }, // TODO(lucacasonato): enable when we have stream support // "textdecoder-streaming", // TODO(lucacasonato): enable when we support utf-16 @@ -134,5 +140,8 @@ // "textencoder-utf16-surrogates", // TODO(lucacasonato): uses XMLHttpRequest unnecessarily. should be fixed upstream before enabling // "unsupported-encodings", + ], + "dom": [ + "abort/event" ] } diff --git a/op_crates/web/01_event.js b/op_crates/web/01_event.js index 35b269ea4bf057..fb80ea4a6862da 100644 --- a/op_crates/web/01_event.js +++ b/op_crates/web/01_event.js @@ -42,6 +42,13 @@ event.currentTarget = value; } + function setIsTrusted(event, value) { + const data = eventData.get(event); + if (data) { + data.isTrusted = value; + } + } + function setDispatched(event, value) { const data = eventData.get(event); if (data) { @@ -1185,4 +1192,7 @@ window.__bootstrap.eventTarget = { setEventTargetData, }; + window.__bootstrap.event = { + setIsTrusted, + }; })(this); diff --git a/op_crates/web/02_abort_signal.js b/op_crates/web/02_abort_signal.js index 5ee047c360eac8..412dab8357e8b7 100644 --- a/op_crates/web/02_abort_signal.js +++ b/op_crates/web/02_abort_signal.js @@ -1,6 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. ((window) => { + const { setIsTrusted } = window.__bootstrap.event; + const add = Symbol("add"); const signalAbort = Symbol("signalAbort"); const remove = Symbol("remove"); @@ -24,7 +26,9 @@ algorithm(); } this.#abortAlgorithms.clear(); - this.dispatchEvent(new Event("abort")); + const event = new Event("abort"); + setIsTrusted(event, true); + this.dispatchEvent(event); } [remove](algorithm) {