mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
parent
01147fab80
commit
fd1c913985
2 changed files with 16 additions and 0 deletions
|
@ -193,6 +193,11 @@
|
|||
}
|
||||
|
||||
function inspectFunction(value, _ctx) {
|
||||
if (customInspect in value && typeof value[customInspect] === "function") {
|
||||
try {
|
||||
return String(value[customInspect]());
|
||||
} catch {}
|
||||
}
|
||||
// Might be Function/AsyncFunction/GeneratorFunction
|
||||
const cstrName = Object.getPrototypeOf(value).constructor.name;
|
||||
if (value.name && value.name !== "anonymous") {
|
||||
|
|
|
@ -831,6 +831,17 @@ unitTest(function consoleTestWithCustomInspectorError(): void {
|
|||
);
|
||||
});
|
||||
|
||||
unitTest(function consoleTestWithCustomInspectFunction(): void {
|
||||
function a() {}
|
||||
Object.assign(a, {
|
||||
[customInspect]() {
|
||||
return "b";
|
||||
},
|
||||
});
|
||||
|
||||
assertEquals(stringify(a), "b");
|
||||
});
|
||||
|
||||
unitTest(function consoleTestWithIntegerFormatSpecifier(): void {
|
||||
assertEquals(stringify("%i"), "%i");
|
||||
assertEquals(stringify("%i", 42.0), "42");
|
||||
|
|
Loading…
Reference in a new issue