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:
parent
40122d7f2a
commit
612818d043
2 changed files with 18 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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" &&
|
||||
|
|
Loading…
Reference in a new issue