Skip to content

Commit

Permalink
lib: let abort_controller target be EventTarget
Browse files Browse the repository at this point in the history
The AbortController abort event should have EventTarget as a target
property of the argument event.

PR-URL: #35869
Backport-PR-URL: #38386
Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
watilde authored and targos committed Apr 30, 2021
1 parent bf728b5 commit b2f8e8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 9 additions & 7 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
} = primordials;

const {
defineEventHandler,
EventTarget,
Event,
kTrustEvent
Expand Down Expand Up @@ -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, {
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b2f8e8d

Please sign in to comment.