From 42d932c59bffe2f399759b8c7dd32e351ff144a3 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Sat, 30 May 2020 23:00:43 +0300 Subject: [PATCH] events: fix depth in customInspectSymbol and clean up PR-URL: https://github.com/nodejs/node/pull/34015 Reviewed-By: Denys Otrishko Reviewed-By: Benjamin Gruenbaum --- lib/internal/event_target.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index bccb2e0edc6a0d..21d3774a586a7f 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -2,8 +2,10 @@ const { ArrayFrom, + Boolean, Error, Map, + NumberIsInteger, Object, Set, Symbol, @@ -78,7 +80,7 @@ class Event { return name; const opts = Object.assign({}, options, { - dept: options.depth === null ? null : options.depth - 1 + depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth }); return `${name} ${inspect({ @@ -294,7 +296,7 @@ class EventTarget { this.#emitting.delete(event.type); event[kTarget] = undefined; - return event.defaultPrevented === true ? false : true; + return event.defaultPrevented !== true; } [customInspectSymbol](depth, options) { @@ -303,7 +305,7 @@ class EventTarget { return name; const opts = Object.assign({}, options, { - dept: options.depth === null ? null : options.depth - 1 + depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth }); return `${name} ${inspect({}, opts)}`; @@ -429,15 +431,10 @@ function validateEventListenerOptions(options) { if (typeof options === 'boolean') return { capture: options }; validateObject(options, 'options'); - const { - once = false, - capture = false, - passive = false, - } = options; return { - once: !!once, - capture: !!capture, - passive: !!passive, + once: Boolean(options.once), + capture: Boolean(options.capture), + passive: Boolean(options.passive), }; }