1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibJS: Use IteratorStepValue in ECMA-262

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

Note they have not yet updated all potential consumers to use this new
AO.
This commit is contained in:
Timothy Flynn 2024-02-01 14:53:28 -05:00 committed by Tim Flynn
parent 2b96e732dd
commit 18847fca50
9 changed files with 80 additions and 156 deletions

View file

@ -56,59 +56,37 @@ static ThrowCompletionOr<Value> perform_promise_common(VM& vm, IteratorRecord& i
// 4. Repeat,
while (true) {
// a. Let next be Completion(IteratorStep(iteratorRecord)).
auto next_or_error = iterator_step(vm, iterator_record);
// a. Let next be ? IteratorStepValue(iteratorRecord).
auto next = TRY(iterator_step_value(vm, iterator_record));
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
// c. ReturnIfAbrupt(next).
if (next_or_error.is_throw_completion()) {
iterator_record.done = true;
return next_or_error.release_error();
}
auto next = next_or_error.release_value();
// d. If next is false, then
if (!next) {
// i. Set iteratorRecord.[[Done]] to true.
iterator_record.done = true;
// ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// iii. If remainingElementsCount.[[Value]] is 0, then
// b. If next is DONE, then
if (!next.has_value()) {
// i. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
// ii. If remainingElementsCount.[[Value]] = 0, then
if (--remaining_elements_count->value == 0) {
// 1-2/3. are handled in `end_of_list`
// 1-2. are handled in `end_of_list`
return TRY(end_of_list(*values));
}
// iv. Return resultCapability.[[Promise]].
// iii. Return resultCapability.[[Promise]].
return result_capability.promise();
}
// e. Let nextValue be Completion(IteratorValue(next)).
auto next_value_or_error = iterator_value(vm, *next);
// f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
// g. ReturnIfAbrupt(nextValue).
if (next_value_or_error.is_throw_completion()) {
iterator_record.done = true;
return next_value_or_error.release_error();
}
auto next_value = next_value_or_error.release_value();
// h. Append undefined to values.
// c. Append undefined to values.
values->values().append(js_undefined());
// i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
auto next_promise = TRY(call(vm, promise_resolve.as_function(), constructor, next_value));
// d. Let nextPromise be ? Call(promiseResolve, constructor, « next »).
auto next_promise = TRY(call(vm, promise_resolve.as_function(), constructor, next.release_value()));
// j-q. are handled in `invoke_element_function`
// e-l. are handled in `invoke_element_function`
// r. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
// m. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
++remaining_elements_count->value;
// s. Perform ? Invoke(nextPromise, "then", « ... »).
// n. Perform ? Invoke(nextPromise, "then", « ... »).
TRY(invoke_element_function(*values, *remaining_elements_count, next_promise, index));
// t. Set index to index + 1.
// o. Set index to index + 1.
++index;
}
}