Skip to content

Commit 612818d

Browse files
authored
fix(cli): ensure that an exception in getOwnPropertyDescriptor('constructor') doesn't break Deno.inspect (#20568)
Fixes #20561
1 parent 40122d7 commit 612818d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cli/tests/unit/console_test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,18 @@ Deno.test(function consoleTestWithCustomInspectorUsingInspectFunc() {
10511051
assertEquals(stringify(new A()), "b { c: 1 }");
10521052
});
10531053

1054+
Deno.test(function consoleTestWithConstructorError() {
1055+
const obj = new Proxy({}, {
1056+
getOwnPropertyDescriptor(_target, name) {
1057+
if (name == "constructor") {
1058+
throw "yikes";
1059+
}
1060+
return undefined;
1061+
},
1062+
});
1063+
assertEquals(Deno.inspect(obj), "{}");
1064+
});
1065+
10541066
Deno.test(function consoleTestWithCustomInspectorError() {
10551067
class A {
10561068
[customInspect](): never {

ext/console/01_console.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,12 @@ function getConstructorName(obj, ctx, recurseTimes, protoProps) {
12021202
let firstProto;
12031203
const tmp = obj;
12041204
while (obj || isUndetectableObject(obj)) {
1205-
const descriptor = ObjectGetOwnPropertyDescriptor(obj, "constructor");
1205+
let descriptor;
1206+
try {
1207+
descriptor = ObjectGetOwnPropertyDescriptor(obj, "constructor");
1208+
} catch {
1209+
/* this could fail */
1210+
}
12061211
if (
12071212
descriptor !== undefined &&
12081213
typeof descriptor.value === "function" &&

0 commit comments

Comments
 (0)