1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 05:57:41 +00:00

LibJS: Convert IteratorStep AO to ThrowCompletionOr

This commit is contained in:
Timothy Flynn 2021-10-20 08:56:01 -04:00 committed by Linus Groh
parent c981d7b9bd
commit 8be1caa05d
7 changed files with 12 additions and 20 deletions

View file

@ -128,10 +128,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayConstructor::from)
return {};
}
auto next = iterator_step(global_object, *iterator);
if (vm.exception())
return {};
auto* next = TRY_OR_DISCARD(iterator_step(global_object, *iterator));
if (!next) {
TRY_OR_DISCARD(array_object.set(vm.names.length, Value(k), Object::ShouldThrowExceptions::Yes));
return array;

View file

@ -287,9 +287,7 @@ ThrowCompletionOr<Vector<String>> string_list_from_iterable(GlobalObject& global
// 5. Repeat, while next is not false,
do {
// a. Set next to ? IteratorStep(iteratorRecord).
next = iterator_step(global_object, *iterator_record);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
next = TRY(iterator_step(global_object, *iterator_record));
// b. If next is not false, then
if (next != nullptr) {

View file

@ -75,15 +75,15 @@ Value iterator_value(GlobalObject& global_object, Object& iterator_result)
}
// 7.4.5 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep
Object* iterator_step(GlobalObject& global_object, Object& iterator)
ThrowCompletionOr<Object*> iterator_step(GlobalObject& global_object, Object& iterator)
{
auto& vm = global_object.vm();
auto result = TRY_OR_DISCARD(iterator_next(iterator));
auto* result = TRY(iterator_next(iterator));
auto done = iterator_complete(global_object, *result);
if (vm.exception())
return {};
if (auto* exception = vm.exception())
return throw_completion(exception->value());
if (done)
return nullptr;

View file

@ -21,7 +21,7 @@ enum class IteratorHint {
ThrowCompletionOr<Object*> get_iterator(GlobalObject&, Value value, IteratorHint hint = IteratorHint::Sync, Value method = {});
ThrowCompletionOr<Object*> iterator_next(Object& iterator, Value value = {});
Object* iterator_step(GlobalObject&, Object& iterator);
ThrowCompletionOr<Object*> iterator_step(GlobalObject&, Object& iterator);
bool iterator_complete(GlobalObject&, Object& iterator_result);
Value iterator_value(GlobalObject&, Object& iterator_result);
void iterator_close(Object& iterator);

View file

@ -100,11 +100,12 @@ static Value perform_promise_common(GlobalObject& global_object, Object& iterato
size_t index = 0;
while (true) {
auto* next = iterator_step(global_object, iterator_record);
if (vm.exception()) {
auto next_or_error = iterator_step(global_object, iterator_record);
if (next_or_error.is_throw_completion()) {
set_iterator_record_complete(global_object, iterator_record);
return {};
}
auto* next = next_or_error.release_value();
if (!next) {
set_iterator_record_complete(global_object, iterator_record);

View file

@ -51,9 +51,7 @@ ThrowCompletionOr<MarkedValueList> iterable_to_list_of_type(GlobalObject& global
// 4. Repeat, while next is not false,
while (next) {
// a. Set next to ? IteratorStep(iteratorRecord).
auto* iterator_result = iterator_step(global_object, *iterator_record);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
auto* iterator_result = TRY(iterator_step(global_object, *iterator_record));
next = iterator_result;
// b. If next is not false, then

View file

@ -501,9 +501,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(CalendarPrototype::fields)
// 7. Repeat, while next is not false,
while (true) {
// a. Set next to ? IteratorStep(iteratorRecord).
auto* next = iterator_step(global_object, *iterator_record);
if (vm.exception())
return {};
auto* next = TRY_OR_DISCARD(iterator_step(global_object, *iterator_record));
// b. If next is not false, then
if (!next)