1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibJS: Use OrdinaryCreateFromConstructor() in a bunch of constructors

Resolves various FIXMEs :^)
This commit is contained in:
Linus Groh 2021-06-20 01:09:39 +01:00 committed by Andreas Kling
parent e5753443ae
commit 8f6ac0db1c
16 changed files with 173 additions and 102 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
@ -41,25 +42,30 @@ Value WeakMapConstructor::call()
}
// 24.3.1.1 WeakMap ( [ iterable ] ), https://tc39.es/ecma262/#sec-weakmap-iterable
Value WeakMapConstructor::construct(Function&)
Value WeakMapConstructor::construct(Function& new_target)
{
auto& vm = this->vm();
if (vm.argument(0).is_nullish())
return WeakMap::create(global_object());
auto& global_object = this->global_object();
auto* weak_map = ordinary_create_from_constructor<WeakMap>(global_object, new_target, &GlobalObject::weak_map_prototype);
if (vm.exception())
return {};
if (vm.argument(0).is_nullish())
return weak_map;
auto* weak_map = WeakMap::create(global_object());
auto adder = weak_map->get(vm.names.set);
if (vm.exception())
return {};
if (!adder.is_function()) {
vm.throw_exception<TypeError>(global_object(), ErrorType::NotAFunction, "'set' property of WeakMap");
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, "'set' property of WeakMap");
return {};
}
get_iterator_values(global_object(), vm.argument(0), [&](Value iterator_value) {
get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) {
if (vm.exception())
return IterationDecision::Break;
if (!iterator_value.is_object()) {
vm.throw_exception<TypeError>(global_object(), ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects()));
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).value_or(js_undefined());