Skip to content

Commit

Permalink
feat(ext/web): add AbortSignal.reason (denoland#12697)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Nov 8, 2021
1 parent 82dd133 commit ccd730a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
63 changes: 44 additions & 19 deletions ext/web/03_abort_signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,49 @@
const webidl = window.__bootstrap.webidl;
const { setIsTrusted, defineEventHandler } = window.__bootstrap.event;
const {
Boolean,
Set,
SetPrototypeAdd,
SetPrototypeDelete,
Symbol,
TypeError,
} = window.__bootstrap.primordials;

const add = Symbol("add");
const signalAbort = Symbol("signalAbort");
const remove = Symbol("remove");
const aborted = Symbol("aborted");
const abortAlgos = Symbol("abortAlgos");
const add = Symbol("[[add]]");
const signalAbort = Symbol("[[signalAbort]]");
const remove = Symbol("[[remove]]");
const abortReason = Symbol("[[abortReason]]");
const abortAlgos = Symbol("[[abortAlgos]]");
const signal = Symbol("[[signal]]");

const illegalConstructorKey = Symbol("illegalConstructorKey");

class AbortSignal extends EventTarget {
static abort() {
static abort(reason = undefined) {
if (reason !== undefined) {
reason = webidl.converters.any(reason);
}
const signal = new AbortSignal(illegalConstructorKey);
signal[signalAbort]();
signal[signalAbort](reason);
return signal;
}

[add](algorithm) {
if (this.aborted) {
return;
}
if (this[abortAlgos] === null) {
this[abortAlgos] = new Set();
}
SetPrototypeAdd(this[abortAlgos], algorithm);
}

[signalAbort]() {
if (this[aborted]) {
[signalAbort](
reason = new DOMException("The signal has been aborted", "AbortError"),
) {
if (this.aborted) {
return;
}
this[aborted] = true;
this[abortReason] = reason;
if (this[abortAlgos] !== null) {
for (const algorithm of this[abortAlgos]) {
algorithm();
Expand All @@ -63,28 +71,40 @@
throw new TypeError("Illegal constructor.");
}
super();
this[aborted] = false;
this[abortReason] = undefined;
this[abortAlgos] = null;
this[webidl.brand] = webidl.brand;
}

get aborted() {
return Boolean(this[aborted]);
webidl.assertBranded(this, AbortSignal);
return this[abortReason] !== undefined;
}

get reason() {
webidl.assertBranded(this, AbortSignal);
return this[abortReason];
}
}
defineEventHandler(AbortSignal.prototype, "abort");

webidl.configurePrototype(AbortSignal);

class AbortController {
#signal = new AbortSignal(illegalConstructorKey);
[signal] = new AbortSignal(illegalConstructorKey);

constructor() {
this[webidl.brand] = webidl.brand;
}

get signal() {
return this.#signal;
webidl.assertBranded(this, AbortController);
return this[signal];
}

abort() {
this.#signal[signalAbort]();
abort(reason) {
webidl.assertBranded(this, AbortController);
this[signal][signalAbort](reason);
}
}

Expand All @@ -100,10 +120,15 @@
}

function follow(followingSignal, parentSignal) {
if (followingSignal.aborted) {
return;
}
if (parentSignal.aborted) {
followingSignal[signalAbort]();
followingSignal[signalAbort](parentSignal.reason);
} else {
parentSignal[add](() => followingSignal[signalAbort]());
parentSignal[add](() =>
followingSignal[signalAbort](parentSignal.reason)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test_util/wpt
Submodule wpt updated 75 files
+11 −0 css/css-backgrounds/box-shadow-calc-ref.html
+15 −0 css/css-backgrounds/box-shadow-calc.html
+51 −0 css/css-content/content-animation.html
+5 −0 css/css-text-decor/reference/text-decoration-wavy-covers-whole-line-length-001-notref.html
+38 −0 css/css-text-decor/text-decoration-line-through-wavy-covers-whole-line-length-001.html
+39 −0 css/css-text-decor/text-decoration-overline-wavy-covers-whole-line-length-001.html
+38 −0 css/css-text-decor/text-decoration-underline-wavy-covers-whole-line-length-001.html
+1 −1 css/css-transforms/animation/translate-interpolation.html
+4 −0 css/css-transforms/parsing/scale-parsing-invalid.html
+17 −0 css/css-transforms/transform-and-individual-transform-properties-computed-style.html
+9 −1 delegated-ink/requestPresenter-returns-valid-promise.tentative.window.js
+62 −0 dom/abort/event.any.js
+22 −17 html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js
+79 −58 idle-detection/interceptor.https.html
+68 −0 page-visibility/minimize.html
+5 −7 resources/chromium/mock-idle-detection.js
+45 −1 resources/testdriver.js
+1 −1 tools/requirements_pytest.txt
+5 −0 tools/webdriver/webdriver/client.py
+25 −0 tools/wptrunner/wptrunner/executors/actions.py
+12 −0 tools/wptrunner/wptrunner/executors/executormarionette.py
+14 −0 tools/wptrunner/wptrunner/executors/executorselenium.py
+13 −0 tools/wptrunner/wptrunner/executors/executorwebdriver.py
+15 −0 tools/wptrunner/wptrunner/executors/protocol.py
+8 −0 tools/wptrunner/wptrunner/testdriver-extra.js
+ wasm/webapi/resources/incrementer.no_mime_type.wasm
+ wasm/webapi/resources/incrementer.wasm
+2 −0 wasm/webapi/resources/incrementer.wasm.headers
+ wasm/webapi/resources/incrementer.wrong_mime_type.wasm
+2 −0 wasm/webapi/resources/incrementer.wrong_mime_type.wasm.headers
+115 −0 wasm/webapi/wasm_stream_compile_test.html
+115 −0 wasm/webapi/wasm_stream_instantiate_test.html
+102 −0 web-animations/responsive/assorted-lengths.html
+25 −0 web-animations/responsive/backgroundPosition.html
+22 −0 web-animations/responsive/backgroundSize.html
+43 −0 web-animations/responsive/baselineShift.html
+22 −0 web-animations/responsive/borderImageWidth.html
+39 −0 web-animations/responsive/borderRadius.html
+33 −0 web-animations/responsive/borderWidth.html
+30 −0 web-animations/responsive/boxShadow.html
+45 −0 web-animations/responsive/clip.html
+32 −0 web-animations/responsive/columnCount.html
+49 −0 web-animations/responsive/columnGap.html
+27 −0 web-animations/responsive/d.html
+32 −0 web-animations/responsive/font-size-adjust.html
+72 −0 web-animations/responsive/fontSize.html
+42 −0 web-animations/responsive/fontWeight.html
+80 −0 web-animations/responsive/lineHeight.html
+31 −0 web-animations/responsive/minHeight.html
+27 −0 web-animations/responsive/offset-path.html
+57 −0 web-animations/responsive/offsetDistance.html
+43 −0 web-animations/responsive/offsetRotate.html
+48 −0 web-animations/responsive/opacity.html
+49 −0 web-animations/responsive/perspective.html
+22 −0 web-animations/responsive/rotate.html
+49 −0 web-animations/responsive/rowGap.html
+24 −0 web-animations/responsive/shapeMargin.html
+59 −0 web-animations/responsive/shapeOutside.html
+28 −0 web-animations/responsive/strokeDasharray.html
+29 −0 web-animations/responsive/text-size-adjust.html
+59 −0 web-animations/responsive/textIndent.html
+253 −0 web-animations/responsive/to-color-change.html
+56 −0 web-animations/responsive/to-inherited-change.html
+44 −0 web-animations/responsive/to-style-change.html
+22 −0 web-animations/responsive/transform.html
+22 −0 web-animations/responsive/translate.html
+22 −0 web-animations/responsive/verticalAlign.html
+15 −2 web-locks/bfcache/abort.tentative.https.html
+9 −0 web-locks/bfcache/held.tentative.https.html
+12 −0 web-locks/bfcache/release-across-thread.tentative.https.html
+10 −0 web-locks/bfcache/release.tentative.https.html
+69 −0 web-locks/bfcache/sharedworker-multiple.tentative.https.html
+11 −2 web-locks/resources/worker.js
+21 −0 webdriver/tests/print/__init__.py
+53 −2 webdriver/tests/print/printcmd.py

0 comments on commit ccd730a

Please sign in to comment.