diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index 4f5930b1ef..f14965c9eb 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -64,8 +64,8 @@ ThrowCompletionOr> AggregateErrorConstructor::construct(Fun // 4. Perform ? InstallErrorCause(O, options). TRY(aggregate_error->install_error_cause(options)); - // 5. Let errorsList be ? IterableToList(errors). - auto errors_list = TRY(iterable_to_list(vm, errors)); + // 5. Let errorsList be ? IteratorToList(? GetIterator(errors, sync)). + auto errors_list = TRY(iterator_to_list(vm, TRY(get_iterator(vm, errors, IteratorHint::Sync)))); // 6. Perform ! DefinePropertyOrThrow(O, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errorsList) }). MUST(aggregate_error->define_property_or_throw(vm.names.errors, { .value = Array::create_from(realm, errors_list), .writable = true, .enumerable = false, .configurable = true })); diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 44990c6e02..9f87dcfdf5 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -208,29 +208,16 @@ NonnullGCPtr create_iterator_result_object(VM& vm, Value value, bool don return object; } -// 7.4.13 IterableToList ( items [ , method ] ), https://tc39.es/ecma262/#sec-iterabletolist -ThrowCompletionOr> iterable_to_list(VM& vm, Value items, GCPtr method) +// 7.4.13 IteratorToList ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratortolist +ThrowCompletionOr> iterator_to_list(VM& vm, IteratorRecord const& iterator_record) { - IteratorRecord iterator_record; - - // 1. If method is present, then - if (method) { - // a. Let iteratorRecord be ? GetIteratorFromMethod(items, method). - iterator_record = TRY(get_iterator_from_method(vm, items, *method)); - } - // 2. Else, - else { - // b. Let iteratorRecord be ? GetIterator(items, sync). - iterator_record = TRY(get_iterator(vm, items, IteratorHint::Sync)); - } - - // 3. Let values be a new empty List. + // 1. Let values be a new empty List. MarkedVector values(vm.heap()); - // 4. Let next be true. + // 2. Let next be true. GCPtr next; - // 5. Repeat, while next is not false, + // 3. Repeat, while next is not false, do { // a. Set next to ? IteratorStep(iteratorRecord). next = TRY(iterator_step(vm, iterator_record)); @@ -245,7 +232,7 @@ ThrowCompletionOr> iterable_to_list(VM& vm, Value items, GCP } } while (next); - // 6. Return values. + // 4. Return values. return values; } diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index f7b9a17305..6b6a6b2eb3 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -31,7 +31,7 @@ ThrowCompletionOr iterator_value(VM&, Object& iterator_result); Completion iterator_close(VM&, IteratorRecord const&, Completion); Completion async_iterator_close(VM&, IteratorRecord const&, Completion); NonnullGCPtr create_iterator_result_object(VM&, Value, bool done); -ThrowCompletionOr> iterable_to_list(VM&, Value iterable, GCPtr method = {}); +ThrowCompletionOr> iterator_to_list(VM&, IteratorRecord const&); using IteratorValueCallback = Function(Value)>; Completion get_iterator_values(VM&, Value iterable, IteratorValueCallback callback); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index f93b0e8fec..e810603c80 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -529,7 +529,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) } else { \ auto iterator = TRY(first_argument.get_method(vm, vm.well_known_symbol_iterator())); \ if (iterator) { \ - auto values = TRY(iterable_to_list(vm, first_argument, iterator)); \ + auto values = TRY(iterator_to_list(vm, TRY(get_iterator_from_method(vm, first_argument, *iterator)))); \ TRY(initialize_typed_array_from_list(vm, *typed_array, values)); \ } else { \ TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object())); \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp index 7c9e7899f7..7fd7da49f1 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp @@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from) // 6. If usingIterator is not undefined, then if (using_iterator) { // a. Let values be ? IteratorToList(? GetIteratorFromMethod(source, usingIterator)). - auto values = TRY(iterable_to_list(vm, source, using_iterator)); + auto values = TRY(iterator_to_list(vm, TRY(get_iterator_from_method(vm, source, *using_iterator)))); // b. Let len be the number of elements in values. auto length = values.size(); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index 07ddd74a48..1ce0edb9f5 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -203,7 +203,7 @@ JS::ThrowCompletionOr instantiate_module(JS::VM& vm, Wasm::Module const& if (method == JS::js_undefined()) return vm.throw_completion(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, result.to_string_without_side_effects())); - auto values = TRY(JS::iterable_to_list(vm, result, method)); + auto values = TRY(JS::iterator_to_list(vm, TRY(JS::get_iterator_from_method(vm, result, *method)))); if (values.size() != type.results().size()) return vm.throw_completion(DeprecatedString::formatted("Invalid number of return values for multi-value wasm return of {} objects", type.results().size()));