1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

fix(cli): ensure that an exception in getOwnPropertyDescriptor('constructor') doesn't break Deno.inspect (#20568)

Fixes #20561
This commit is contained in:
Matt Mastracci 2023-09-19 12:24:19 -06:00 committed by GitHub
parent 40122d7f2a
commit 612818d043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -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 {

View file

@ -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" &&