From d3edbd13644fe3f6a24cc36baec69e47823a8a89 Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Fri, 19 Dec 2025 17:39:24 +0100 Subject: [PATCH 1/4] events: remove eventtarget custom inspect branding --- lib/internal/event_target.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index c267050bf614d6..9029f19b30da0e 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -867,8 +867,6 @@ class EventTarget { return new CustomEvent(type, { detail: nodeValue }); } [customInspectSymbol](depth, options) { - if (!isEventTarget(this)) - throw new ERR_INVALID_THIS('EventTarget'); const name = this.constructor.name; if (depth < 0) return name; From 830ace596fb96b1b3d6fbba7ca54c78a6357a61c Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Fri, 19 Dec 2025 17:39:32 +0100 Subject: [PATCH 2/4] test: test eventtarget custom inspect w/o branding --- ...eventtarget-custom-inspect-does-not-throw.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/parallel/test-eventtarget-custom-inspect-does-not-throw.js diff --git a/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js new file mode 100644 index 00000000000000..c160827673e90b --- /dev/null +++ b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js @@ -0,0 +1,17 @@ +'use strict'; + +const assert = require('assert'); +const util = require('util'); + +const symbol = util.inspect.custom; + +const eventTargetInspect = EventTarget.prototype[symbol]; + +const fakeEventTarget = { + [symbol]: eventTargetInspect, + someOtherField: 42 +}; + +assert.doesNotThrow(() => { + util.inspect(fakeEventTarget); +}); From bf43b8acc4b1922d7aa494b09522b3766f2ca32a Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Sun, 21 Dec 2025 12:06:22 +0100 Subject: [PATCH 3/4] test: use check output type instead of using doesNotThrow --- .../test-eventtarget-custom-inspect-does-not-throw.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js index c160827673e90b..3fe0a04a005dce 100644 --- a/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js +++ b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js @@ -12,6 +12,8 @@ const fakeEventTarget = { someOtherField: 42 }; -assert.doesNotThrow(() => { - util.inspect(fakeEventTarget); -}); +// should not throw when calling the custom inspect method +const output = util.inspect(fakeEventTarget); + +assert.strictEqual(typeof output, 'string'); + From d8e55f9efea47e5d6344b11a4248e9aefa880ba1 Mon Sep 17 00:00:00 2001 From: Efe Karasakal Date: Sun, 21 Dec 2025 13:27:21 +0100 Subject: [PATCH 4/4] test: fix lint errors --- .../test-eventtarget-custom-inspect-does-not-throw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js index 3fe0a04a005dce..114f7e856243f8 100644 --- a/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js +++ b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js @@ -1,5 +1,6 @@ 'use strict'; +require('../common'); const assert = require('assert'); const util = require('util'); @@ -12,8 +13,7 @@ const fakeEventTarget = { someOtherField: 42 }; -// should not throw when calling the custom inspect method +// Should not throw when calling the custom inspect method const output = util.inspect(fakeEventTarget); assert.strictEqual(typeof output, 'string'); -