diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-10-20 08:56:01 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 00:26:45 +0100 |
commit | 8be1caa05d57c2571e9215875b0e5e6dd7b7845a (patch) | |
tree | fb32324fce3c46af85ccef066635fe2d5a22746e /Userland/Libraries/LibJS/Runtime | |
parent | c981d7b9bd211bd3d5e61951395b278e95ae1a9b (diff) | |
download | serenity-8be1caa05d57c2571e9215875b0e5e6dd7b7845a.zip |
LibJS: Convert IteratorStep AO to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
7 files changed, 12 insertions, 20 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 8cc1b3e7a8..5958903c7f 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -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; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index d695056bb4..a450f58c2a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -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) { diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 2dfdeac91e..3373639505 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -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; diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index d53ef65339..17fe2a202d 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -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); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index e8b8da0669..e31f398469 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -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); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 66eca3d7cf..49df0f360d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index f6382492e8..be82579e52 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -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) |