1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

fix(cli): customInspect works on functions (#7670)

Fixes #7650
This commit is contained in:
Kitson Kelly 2020-09-25 21:36:26 +10:00 committed by GitHub
parent 01147fab80
commit fd1c913985
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -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") {

View file

@ -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");