diff --git a/src/jsc/bindings/bindings.cpp b/src/jsc/bindings/bindings.cpp index 22ac3806337..9498c755e5a 100644 --- a/src/jsc/bindings/bindings.cpp +++ b/src/jsc/bindings/bindings.cpp @@ -5444,7 +5444,10 @@ static void JSC__JSValue__forEachPropertyImpl(JSC::EncodedJSValue JSValue0, JSC: break; if (iterating == globalObject) break; - iterating = iterating->getPrototype(globalObject).getObject(); + JSValue proto = iterating->getPrototype(globalObject); + // Ignore exceptions from Proxy "getPrototypeOf" trap. + CLEAR_IF_EXCEPTION(scope); + iterating = proto ? proto.getObject() : nullptr; } } diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 32a70af3018..322f2fa7ddc 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -451,6 +451,29 @@ const fixture = [ }, }, ), + () => + Object.setPrototypeOf( + { yolo: 1 }, + new Proxy( + {}, + { + getPrototypeOf() { + throw new Error("nope"); + }, + }, + ), + ), + () => + Object.create( + new Proxy( + { yolo: 1 }, + { + getPrototypeOf() { + throw new Error("nope"); + }, + }, + ), + ), ]; describe("crash testing", () => {