mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
lib: let abort_controller target be EventTarget
The AbortController abort event should have EventTarget as a target property of the argument event. PR-URL: https://github.com/nodejs/node/pull/35869 Backport-PR-URL: https://github.com/nodejs/node/pull/38386 Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
bf728b5439
commit
b2f8e8dd28
2 files changed
+11
-10
No files matched your search
@@ -9,6 +9,7 @@ const {
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
defineEventHandler,
|
||||
EventTarget,
|
||||
Event,
|
||||
kTrustEvent
|
||||
@@ -52,21 +53,22 @@ function abortSignal(signal) {
|
||||
const event = new Event('abort', {
|
||||
[kTrustEvent]: true
|
||||
});
|
||||
if (typeof signal.onabort === 'function') {
|
||||
signal.onabort(event);
|
||||
}
|
||||
signal.dispatchEvent(event);
|
||||
}
|
||||
|
||||
// TODO(joyeecheung): V8 snapshot does not support instance member
|
||||
// initializers for now:
|
||||
// https://bugs.chromium.org/p/v8/issues/detail?id=10704
|
||||
const kSignal = Symbol('signal');
|
||||
class AbortController {
|
||||
#signal = new AbortSignal();
|
||||
|
||||
constructor() {
|
||||
this[kSignal] = new AbortSignal();
|
||||
emitExperimentalWarning('AbortController');
|
||||
defineEventHandler(this[kSignal], 'abort');
|
||||
}
|
||||
|
||||
get signal() { return this.#signal; }
|
||||
abort() { abortSignal(this.#signal); }
|
||||
get signal() { return this[kSignal]; }
|
||||
abort() { abortSignal(this[kSignal]); }
|
||||
|
||||
[customInspectSymbol](depth, options) {
|
||||
return customInspect(this, {
|
||||
|
||||
@@ -333,14 +333,13 @@ class EventTarget {
|
||||
}
|
||||
return event;
|
||||
};
|
||||
if (event !== undefined)
|
||||
event[kTarget] = this;
|
||||
|
||||
const root = this[kEvents].get(type);
|
||||
if (root === undefined || root.next === undefined)
|
||||
return true;
|
||||
|
||||
if (event !== undefined)
|
||||
event[kTarget] = this;
|
||||
|
||||
let handler = root.next;
|
||||
let next;
|
||||
|
||||
|
||||
Reference in new issue
Block a user