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;