1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibJS: Rename IterableToList to IteratorToList

This is an editorial change in the ECMA-262 spec. See:
ff60140

In doing so, as the new name implies, callsites are updated to pass in
an IteratorRecord themselves, rather than an iterable value.
This commit is contained in:
Timothy Flynn 2023-07-18 15:02:28 -04:00 committed by Andreas Kling
parent 1760361304
commit a7a109062a
Notes: sideshowbarker 2024-07-18 08:59:31 +09:00
6 changed files with 12 additions and 25 deletions

View file

@ -64,8 +64,8 @@ ThrowCompletionOr<NonnullGCPtr<Object>> 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 }));

View file

@ -208,29 +208,16 @@ NonnullGCPtr<Object> 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<MarkedVector<Value>> iterable_to_list(VM& vm, Value items, GCPtr<FunctionObject> method)
// 7.4.13 IteratorToList ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratortolist
ThrowCompletionOr<MarkedVector<Value>> 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<Value> values(vm.heap());
// 4. Let next be true.
// 2. Let next be true.
GCPtr<Object> 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<MarkedVector<Value>> iterable_to_list(VM& vm, Value items, GCP
}
} while (next);
// 6. Return values.
// 4. Return values.
return values;
}

View file

@ -31,7 +31,7 @@ ThrowCompletionOr<Value> iterator_value(VM&, Object& iterator_result);
Completion iterator_close(VM&, IteratorRecord const&, Completion);
Completion async_iterator_close(VM&, IteratorRecord const&, Completion);
NonnullGCPtr<Object> create_iterator_result_object(VM&, Value, bool done);
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list(VM&, Value iterable, GCPtr<FunctionObject> method = {});
ThrowCompletionOr<MarkedVector<Value>> iterator_to_list(VM&, IteratorRecord const&);
using IteratorValueCallback = Function<Optional<Completion>(Value)>;
Completion get_iterator_values(VM&, Value iterable, IteratorValueCallback callback);

View file

@ -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())); \

View file

@ -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();

View file

@ -203,7 +203,7 @@ JS::ThrowCompletionOr<size_t> instantiate_module(JS::VM& vm, Wasm::Module const&
if (method == JS::js_undefined())
return vm.throw_completion<JS::TypeError>(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<JS::TypeError>(DeprecatedString::formatted("Invalid number of return values for multi-value wasm return of {} objects", type.results().size()));