mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
fix(op_crate/web): make onabort event handler web compatible (#8225)
This commit is contained in:
parent
c3dd19c5d3
commit
1c1889851d
2 changed files with 31 additions and 7 deletions
|
@ -36,12 +36,23 @@
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor.");
|
||||||
}
|
}
|
||||||
super();
|
super();
|
||||||
this.onabort = null;
|
// HTML specification section 8.1.5.1
|
||||||
this.addEventListener("abort", (evt) => {
|
let eventHandler = null;
|
||||||
const { onabort } = this;
|
Object.defineProperty(this, "onabort", {
|
||||||
if (typeof onabort === "function") {
|
get() {
|
||||||
onabort.call(this, evt);
|
return eventHandler;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
if (eventHandler) {
|
||||||
|
this.removeEventListener("abort", eventHandler);
|
||||||
}
|
}
|
||||||
|
eventHandler = value;
|
||||||
|
if (typeof eventHandler === "function") {
|
||||||
|
this.addEventListener("abort", value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function assertThrows(fn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function basicAbortController() {
|
function basicAbortController() {
|
||||||
controller = new AbortController();
|
const controller = new AbortController();
|
||||||
assert(controller);
|
assert(controller);
|
||||||
const { signal } = controller;
|
const { signal } = controller;
|
||||||
assert(signal);
|
assert(signal);
|
||||||
|
@ -83,6 +83,18 @@ function abortSignalIllegalConstructor() {
|
||||||
assertEquals(error.message, "Illegal constructor.");
|
assertEquals(error.message, "Illegal constructor.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function abortSignalEventOrder() {
|
||||||
|
const arr = [];
|
||||||
|
const controller = new AbortController();
|
||||||
|
const { signal } = controller;
|
||||||
|
signal.addEventListener("abort", () => arr.push(1));
|
||||||
|
signal.onabort = () => arr.push(2);
|
||||||
|
signal.addEventListener("abort", () => arr.push(3));
|
||||||
|
controller.abort();
|
||||||
|
assertEquals(arr[0], 1);
|
||||||
|
assertEquals(arr[1], 2);
|
||||||
|
assertEquals(arr[2], 3);
|
||||||
|
}
|
||||||
function main() {
|
function main() {
|
||||||
basicAbortController();
|
basicAbortController();
|
||||||
signalCallsOnabort();
|
signalCallsOnabort();
|
||||||
|
@ -90,6 +102,7 @@ function main() {
|
||||||
onlyAbortsOnce();
|
onlyAbortsOnce();
|
||||||
controllerHasProperToString();
|
controllerHasProperToString();
|
||||||
abortSignalIllegalConstructor();
|
abortSignalIllegalConstructor();
|
||||||
|
abortSignalEventOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Reference in a new issue