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,
|
ObjectGetOwnPropertyNames,
|
||||||
ObjectGetPrototypeOf,
|
ObjectGetPrototypeOf,
|
||||||
ObjectKeys,
|
ObjectKeys,
|
||||||
ObjectPrototypeHasOwnProperty,
|
|
||||||
ObjectPrototypeToString,
|
ObjectPrototypeToString,
|
||||||
RangeError,
|
RangeError,
|
||||||
ReferenceError,
|
ReferenceError,
|
||||||
@ -134,8 +133,7 @@ function serializeError(error) {
|
|||||||
// Continue regardless of error.
|
// Continue regardless of error.
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (error != null &&
|
if (error != null && customInspectSymbol in error) {
|
||||||
ObjectPrototypeHasOwnProperty(error, customInspectSymbol)) {
|
|
||||||
return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8');
|
return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -125,3 +125,11 @@ const data = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
assert.strictEqual(inspect(cycle(data)), 'barbaz');
|
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