diff --git a/lib/internal/error_serdes.js b/lib/internal/error_serdes.js index 5c25830600237c..d340c4a4bbc7fd 100644 --- a/lib/internal/error_serdes.js +++ b/lib/internal/error_serdes.js @@ -13,7 +13,6 @@ const { ObjectGetOwnPropertyNames, ObjectGetPrototypeOf, ObjectKeys, - ObjectPrototypeHasOwnProperty, ObjectPrototypeToString, RangeError, ReferenceError, @@ -134,8 +133,7 @@ function serializeError(error) { // Continue regardless of error. } try { - if (error != null && - ObjectPrototypeHasOwnProperty(error, customInspectSymbol)) { + if (error != null && customInspectSymbol in error) { return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8'); } } catch { diff --git a/test/parallel/test-error-serdes.js b/test/parallel/test-error-serdes.js index 3b61d3a4b9b34b..da09e6ed0a4d9f 100644 --- a/test/parallel/test-error-serdes.js +++ b/test/parallel/test-error-serdes.js @@ -125,3 +125,11 @@ const data = { } }; assert.strictEqual(inspect(cycle(data)), 'barbaz'); + +const inheritedCustomInspect = new class { + foo = 'bar'; + [inspect.custom]() { + return 'barbaz'; + } +}(); +assert.strictEqual(inspect(cycle(inheritedCustomInspect)), 'barbaz');