diff options
-rw-r--r-- | cli/tests/unit/console_test.ts | 12 | ||||
-rw-r--r-- | ext/console/01_console.js | 7 |
2 files changed, 18 insertions, 1 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 7dac7ca77..d8990559e 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -1051,6 +1051,18 @@ Deno.test(function consoleTestWithCustomInspectorUsingInspectFunc() { assertEquals(stringify(new A()), "b { c: 1 }"); }); +Deno.test(function consoleTestWithConstructorError() { + const obj = new Proxy({}, { + getOwnPropertyDescriptor(_target, name) { + if (name == "constructor") { + throw "yikes"; + } + return undefined; + }, + }); + assertEquals(Deno.inspect(obj), "{}"); +}); + Deno.test(function consoleTestWithCustomInspectorError() { class A { [customInspect](): never { diff --git a/ext/console/01_console.js b/ext/console/01_console.js index 8d9c56c92..a766bb641 100644 --- a/ext/console/01_console.js +++ b/ext/console/01_console.js @@ -1202,7 +1202,12 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) { let firstProto; const tmp = obj; while (obj || isUndetectableObject(obj)) { - const descriptor = ObjectGetOwnPropertyDescriptor(obj, "constructor"); + let descriptor; + try { + descriptor = ObjectGetOwnPropertyDescriptor(obj, "constructor"); + } catch { + /* this could fail */ + } if ( descriptor !== undefined && typeof descriptor.value === "function" && |