From 5d4cb8464d562abd31a4f2a4ae935baa555db68c Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Wed, 4 Jan 2023 13:28:54 +0900 Subject: [PATCH] events: check signal before listener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In WPT Events, TypeError is expected if both listener and signal are null. But checking listener doesn't throw TypeError. So check signal before listener because checking signal throws TypeError if signal is null. PR-URL: https://github.com/nodejs/node/pull/46054 Reviewed-By: Antoine du Hamel Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung --- lib/internal/event_target.js | 4 ++-- test/wpt/status/dom/events.json | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index ea8ac6652545d9..dac962e1a3b07e 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -561,6 +561,8 @@ class EventTarget { weak, } = validateEventListenerOptions(options); + validateAbortSignal(signal, 'options.signal'); + if (!validateEventListener(listener)) { // The DOM silently allows passing undefined as a second argument // No error code for this since it is a Warning @@ -575,8 +577,6 @@ class EventTarget { } type = String(type); - validateAbortSignal(signal, 'options.signal'); - if (signal) { if (signal.aborted) { return; diff --git a/test/wpt/status/dom/events.json b/test/wpt/status/dom/events.json index 607ac32ee4528f..b360c6f8feb0fd 100644 --- a/test/wpt/status/dom/events.json +++ b/test/wpt/status/dom/events.json @@ -8,13 +8,6 @@ ] } }, - "AddEventListenerOptions-signal.any.js": { - "fail": { - "expected": [ - "Passing null as the signal should throw (listener is also null)" - ] - } - }, "Event-constructors.any.js": { "fail": { "expected": [