diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-20 21:16:30 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 09:02:23 +0100 |
commit | 5832de62fe5e2de4f9a65485246df6550aece33f (patch) | |
tree | 485f847a4dedebdcb2b11902bbe0256fa98518ed /Userland/Libraries/LibJS/Runtime/SetConstructor.cpp | |
parent | 0881f8160fd81d8e25b7cc2eff2d64f2aed7ed53 (diff) | |
download | serenity-5832de62fe5e2de4f9a65485246df6550aece33f.zip |
LibJS: Convert NativeFunction::{call,construct}() to ThrowCompletionOr
Both at the same time because many of them call construct() in call()
and I'm not keen on adding a bunch of temporary plumbing to turn
exceptions into throw completions.
Also changes the return value of construct() to Object* instead of Value
as it always needs to return an object; allowing an arbitrary Value is a
massive foot gun.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/SetConstructor.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/SetConstructor.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp index 0bd301d452..64c64306ef 100644 --- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp @@ -36,31 +36,28 @@ SetConstructor::~SetConstructor() } // 24.2.1.1 Set ( [ iterable ] ), https://tc39.es/ecma262/#sec-set-iterable -Value SetConstructor::call() +ThrowCompletionOr<Value> SetConstructor::call() { auto& vm = this->vm(); - vm.throw_exception<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.Set); - return {}; + return vm.throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.Set); } // 24.2.1.1 Set ( [ iterable ] ), https://tc39.es/ecma262/#sec-set-iterable -Value SetConstructor::construct(FunctionObject& new_target) +ThrowCompletionOr<Object*> SetConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); auto& global_object = this->global_object(); - auto* set = TRY_OR_DISCARD(ordinary_create_from_constructor<Set>(global_object, new_target, &GlobalObject::set_prototype)); + auto* set = TRY(ordinary_create_from_constructor<Set>(global_object, new_target, &GlobalObject::set_prototype)); if (vm.argument(0).is_nullish()) return set; - auto adder = TRY_OR_DISCARD(set->get(vm.names.add)); - if (!adder.is_function()) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of Set"); - return {}; - } + auto adder = TRY(set->get(vm.names.add)); + if (!adder.is_function()) + return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of Set"); - TRY_OR_DISCARD(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> { + TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> { TRY(vm.call(adder.as_function(), Value(set), iterator_value)); return {}; })); |