mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
Prevent customInspect error from crashing console (#3226)
This commit is contained in:
parent
f484776384
commit
2f0f236d56
2 changed files with 26 additions and 2 deletions
|
@ -190,6 +190,27 @@ test(function consoleTestWithCustomInspector(): void {
|
|||
assertEquals(stringify(new A()), "b");
|
||||
});
|
||||
|
||||
test(function consoleTestWithCustomInspectorError(): void {
|
||||
class A {
|
||||
[customInspect](): string {
|
||||
throw new Error("BOOM");
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(stringify(new A()), "A {}");
|
||||
|
||||
class B {
|
||||
constructor(public field: { a: string }) {}
|
||||
[customInspect](): string {
|
||||
return this.field.a;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(stringify(new B({ a: "a" })), "a");
|
||||
assertEquals(stringify(B.prototype), "{}");
|
||||
});
|
||||
|
||||
test(function consoleTestWithIntegerFormatSpecifier(): void {
|
||||
assertEquals(stringify("%i"), "%i");
|
||||
assertEquals(stringify("%i", 42.0), "42");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue