mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 23:59:59 -05:00
feat(console): pass options and depth to custom inspects (#14855)
This commit updates Deno.inspect() to pass inspect options and the current inspect depth to custom inspect functions. Refs: https://github.com/denoland/deno/issues/8099 Refs: https://github.com/denoland/deno/issues/14171
This commit is contained in:
parent
7b1662a8e6
commit
64abb65f05
2 changed files with 13 additions and 4 deletions
|
@ -884,7 +884,14 @@ Deno.test(async function consoleTestStringifyPromises() {
|
|||
|
||||
Deno.test(function consoleTestWithCustomInspector() {
|
||||
class A {
|
||||
[customInspect](): string {
|
||||
[customInspect](
|
||||
inspect: unknown,
|
||||
options: Deno.InspectOptions,
|
||||
depth: number,
|
||||
): string {
|
||||
assertEquals(typeof inspect, "function");
|
||||
assertEquals(typeof options, "object");
|
||||
assertEquals(depth, 0);
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,7 +335,7 @@
|
|||
ReflectHas(value, customInspect) &&
|
||||
typeof value[customInspect] === "function"
|
||||
) {
|
||||
return String(value[customInspect](inspect));
|
||||
return String(value[customInspect](inspect, inspectOptions, level));
|
||||
}
|
||||
// Might be Function/AsyncFunction/GeneratorFunction/AsyncGeneratorFunction
|
||||
let cstrName = ObjectGetPrototypeOf(value)?.constructor?.name;
|
||||
|
@ -1258,7 +1258,7 @@
|
|||
ReflectHas(value, customInspect) &&
|
||||
typeof value[customInspect] === "function"
|
||||
) {
|
||||
return String(value[customInspect](inspect));
|
||||
return String(value[customInspect](inspect, inspectOptions, level));
|
||||
}
|
||||
// This non-unique symbol is used to support op_crates, ie.
|
||||
// in extensions/web we don't want to depend on public
|
||||
|
@ -1273,7 +1273,9 @@
|
|||
// inspect implementations in `extensions` need it, but may not have access
|
||||
// to the `Deno` namespace in web workers. Remove when the `Deno`
|
||||
// namespace is always enabled.
|
||||
return String(value[privateCustomInspect](inspect));
|
||||
return String(
|
||||
value[privateCustomInspect](inspect, inspectOptions, level),
|
||||
);
|
||||
}
|
||||
if (ObjectPrototypeIsPrototypeOf(ErrorPrototype, value)) {
|
||||
return inspectError(value, maybeColor(colors.cyan, inspectOptions));
|
||||
|
|
Loading…
Reference in a new issue