diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-09-19 12:24:19 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-19 18:24:19 +0000 |
commit | 612818d04399ef706df3df5ac94e6ef7e633cff7 (patch) | |
tree | 14d5f4313efe9fdc69a4ee3f7b0f5e72f62f7747 | |
parent | 40122d7f2a867660900612980dfc75eece0d5e29 (diff) |
fix(cli): ensure that an exception in getOwnPropertyDescriptor('constructor') doesn't break Deno.inspect (#20568)
Fixes #20561
-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" && |