mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibJS: Convert get_iterator_values helper to ThrowCompletionOr
This one is a bit unusual, so to clarify: Previously, callers of get_iterator_values() would supply a callback that would return an IterationDecision, and an enum to indicate whether iterator_close() should be invoked upon IterationDecision::Break. Now, use of both those enums is removed, and callers must return an Optional<Completion>. If a Completion is provided, the iterator will be closed, and that completion will be returned from get_iterator_values. Otherwise, once the iterator is exhausted, a default-initialized Completion will be returned.
This commit is contained in:
committed by
Linus Groh
parent
7b4814f74c
commit
04b4307b3d
Notes:
sideshowbarker
2024-07-18 02:06:55 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/04b4307b3d5 Pull-request: https://github.com/SerenityOS/serenity/pull/10546 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/linusg ✅
@@ -59,14 +59,12 @@ Value SetConstructor::construct(FunctionObject& new_target)
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of Set");
|
||||
return {};
|
||||
}
|
||||
get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) {
|
||||
if (vm.exception())
|
||||
return IterationDecision::Break;
|
||||
(void)vm.call(adder.as_function(), Value(set), iterator_value);
|
||||
return vm.exception() ? IterationDecision::Break : IterationDecision::Continue;
|
||||
});
|
||||
if (vm.exception())
|
||||
|
||||
TRY_OR_DISCARD(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
|
||||
TRY(vm.call(adder.as_function(), Value(set), iterator_value));
|
||||
return {};
|
||||
}));
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user