From d2f574b5be9d095fbff6f60fd1673e20c071b7f2 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Sat, 31 Oct 2020 07:38:26 +0900 Subject: [PATCH] lib: let abort_controller target be EventTarget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The AbortController abort event should have EventTarget as a target property of the argument event. PR-URL: https://github.com/nodejs/node/pull/35869 Refs: https://github.com/web-platform-tests/wpt/blob/master/dom/abort/event.any.js Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso Reviewed-By: Benjamin Gruenbaum --- lib/internal/abort_controller.js | 5 ++--- lib/internal/event_target.js | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index dc494e920aeec2..592e46e5320ce9 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -10,6 +10,7 @@ const { } = primordials; const { + defineEventHandler, EventTarget, Event, kTrustEvent @@ -53,9 +54,6 @@ function abortSignal(signal) { const event = new Event('abort', { [kTrustEvent]: true }); - if (typeof signal.onabort === 'function') { - signal.onabort(event); - } signal.dispatchEvent(event); } @@ -67,6 +65,7 @@ class AbortController { constructor() { this[kSignal] = new AbortSignal(); emitExperimentalWarning('AbortController'); + defineEventHandler(this[kSignal], 'abort'); } get signal() { return this[kSignal]; } diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 4023e59bfe5359..e05ccd4b11f9ac 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -334,14 +334,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;