lib: add support for inherited custom inspection methods
PR-URL: https://github.com/nodejs/node/pull/48306 Fixes: https://github.com/nodejs/node/issues/48207 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0c875bbfc8
commit
2c6698b4db
@ -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 {
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user