LibJS: Don't assume [[GetOwnPropertyDescriptor]] always succeeds

It can fail if we're talking to a badly-behaved proxy when enumerating
object properties for iteration.
This commit is contained in:
Andreas Kling 2025-03-19 13:23:38 -05:00 committed by Andreas Kling
parent 37c7eb14fe
commit 660d533b50
Notes: github-actions[bot] 2025-03-20 17:52:44 +00:00
2 changed files with 14 additions and 0 deletions

View file

@ -1732,6 +1732,8 @@ inline ThrowCompletionOr<Object*> get_object_property_iterator(VM& vm, Value val
continue;
auto descriptor = TRY(object_to_check->internal_get_own_property(property_key));
if (!descriptor.has_value())
continue;
if (!*descriptor->enumerable)
non_enumerable_properties.set(move(property_key));
else

View file

@ -0,0 +1,12 @@
test("iterate over bogus proxy", () => {
expect(() => {
let proxy = new Proxy([123], {
getOwnPropertyDescriptor: function (p) {
return undefined;
},
});
for (const p in proxy) {
}
}).toThrow();
});