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; 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..114f7e856243f8 --- /dev/null +++ b/test/parallel/test-eventtarget-custom-inspect-does-not-throw.js @@ -0,0 +1,19 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const util = require('util'); + +const symbol = util.inspect.custom; + +const eventTargetInspect = EventTarget.prototype[symbol]; + +const fakeEventTarget = { + [symbol]: eventTargetInspect, + someOtherField: 42 +}; + +// Should not throw when calling the custom inspect method +const output = util.inspect(fakeEventTarget); + +assert.strictEqual(typeof output, 'string');