1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

LibJS: Use undefined as the fallback value for iterable entry key/value

As defined in OdinaryGet in the specification.
This commit is contained in:
Idan Horowitz 2021-06-12 23:24:20 +03:00 committed by Linus Groh
parent c0e04768e0
commit 3c83298a26
2 changed files with 11 additions and 2 deletions

View file

@ -36,6 +36,7 @@ Value WeakMapConstructor::call()
return {};
}
// 24.3.1.1 WeakMap ( [ iterable ] ), https://tc39.es/ecma262/#sec-weakmap-iterable
Value WeakMapConstructor::construct(Function&)
{
auto& vm = this->vm();
@ -57,10 +58,10 @@ Value WeakMapConstructor::construct(Function&)
vm.throw_exception<TypeError>(global_object(), ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects()));
return IterationDecision::Break;
}
auto key = iterator_value.as_object().get(0);
auto key = iterator_value.as_object().get(0).value_or(js_undefined());
if (vm.exception())
return IterationDecision::Break;
auto value = iterator_value.as_object().get(1);
auto value = iterator_value.as_object().get(1).value_or(js_undefined());
if (vm.exception())
return IterationDecision::Break;
(void)vm.call(adder.as_function(), Value(weak_map), key, value);