mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 21:54:48 +00:00
parent
01147fab80
commit
fd1c913985
2 changed files with 16 additions and 0 deletions
|
@ -193,6 +193,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function inspectFunction(value, _ctx) {
|
function inspectFunction(value, _ctx) {
|
||||||
|
if (customInspect in value && typeof value[customInspect] === "function") {
|
||||||
|
try {
|
||||||
|
return String(value[customInspect]());
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
// Might be Function/AsyncFunction/GeneratorFunction
|
// Might be Function/AsyncFunction/GeneratorFunction
|
||||||
const cstrName = Object.getPrototypeOf(value).constructor.name;
|
const cstrName = Object.getPrototypeOf(value).constructor.name;
|
||||||
if (value.name && value.name !== "anonymous") {
|
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 {
|
unitTest(function consoleTestWithIntegerFormatSpecifier(): void {
|
||||||
assertEquals(stringify("%i"), "%i");
|
assertEquals(stringify("%i"), "%i");
|
||||||
assertEquals(stringify("%i", 42.0), "42");
|
assertEquals(stringify("%i", 42.0), "42");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue