1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibJS: Convert IterableToList AO to ThrowCompletionOr

This commit is contained in:
Timothy Flynn 2021-10-20 13:41:27 -04:00 committed by Linus Groh
parent ec54a7b5b0
commit 03b251a704
5 changed files with 8 additions and 14 deletions

View file

@ -51,9 +51,7 @@ Value AggregateErrorConstructor::construct(FunctionObject& new_target)
TRY_OR_DISCARD(aggregate_error->install_error_cause(vm.argument(2)));
auto errors_list = iterable_to_list(global_object, vm.argument(0));
if (vm.exception())
return {};
auto errors_list = TRY_OR_DISCARD(iterable_to_list(global_object, vm.argument(0)));
MUST(aggregate_error->define_property_or_throw(vm.names.errors, { .value = Array::create_from(global_object, errors_list), .writable = true, .enumerable = false, .configurable = true }));

View file

@ -147,19 +147,19 @@ Object* create_iterator_result_object(GlobalObject& global_object, Value value,
}
// 7.4.10 IterableToList ( items [ , method ] ), https://tc39.es/ecma262/#sec-iterabletolist
MarkedValueList iterable_to_list(GlobalObject& global_object, Value iterable, Value method)
ThrowCompletionOr<MarkedValueList> iterable_to_list(GlobalObject& global_object, Value iterable, Value method)
{
auto& vm = global_object.vm();
MarkedValueList values(vm.heap());
(void)get_iterator_values(
TRY(get_iterator_values(
global_object, iterable, [&](auto value) -> Optional<Completion> {
values.append(value);
return {};
},
method);
method));
return values;
return { move(values) };
}
Completion get_iterator_values(GlobalObject& global_object, Value iterable, IteratorValueCallback callback, Value method)

View file

@ -27,7 +27,7 @@ ThrowCompletionOr<bool> iterator_complete(GlobalObject&, Object& iterator_result
ThrowCompletionOr<Value> iterator_value(GlobalObject&, Object& iterator_result);
Completion iterator_close(Object& iterator, Completion completion);
Object* create_iterator_result_object(GlobalObject&, Value value, bool done);
MarkedValueList iterable_to_list(GlobalObject&, Value iterable, Value method = {});
ThrowCompletionOr<MarkedValueList> iterable_to_list(GlobalObject&, Value iterable, Value method = {});
using IteratorValueCallback = Function<Optional<Completion>(Value)>;
Completion get_iterator_values(GlobalObject& global_object, Value iterable, IteratorValueCallback callback, Value method = {});

View file

@ -465,9 +465,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
} else { \
auto iterator = TRY_OR_DISCARD(first_argument.get_method(global_object(), *vm.well_known_symbol_iterator())); \
if (iterator) { \
auto values = iterable_to_list(global_object(), first_argument, iterator); \
if (vm.exception()) \
return {}; \
auto values = TRY_OR_DISCARD(iterable_to_list(global_object(), first_argument, iterator)); \
TRY_OR_DISCARD(initialize_typed_array_from_list(global_object(), *typed_array, values)); \
} else { \
TRY_OR_DISCARD(initialize_typed_array_from_array_like(global_object(), *typed_array, first_argument.as_object())); \

View file

@ -79,9 +79,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(TypedArrayConstructor::from)
auto using_iterator = TRY_OR_DISCARD(source.get_method(global_object, *vm.well_known_symbol_iterator()));
if (using_iterator) {
auto values = iterable_to_list(global_object, source, using_iterator);
if (vm.exception())
return {};
auto values = TRY_OR_DISCARD(iterable_to_list(global_object, source, using_iterator));
MarkedValueList arguments(vm.heap());
arguments.empend(values.size());