mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 13:17:36 +00:00
LibJS: Convert IteratorStep AO to ThrowCompletionOr
This commit is contained in:
parent
c981d7b9bd
commit
8be1caa05d
7 changed files with 12 additions and 20 deletions
|
@ -128,10 +128,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayConstructor::from)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto next = iterator_step(global_object, *iterator);
|
auto* next = TRY_OR_DISCARD(iterator_step(global_object, *iterator));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
if (!next) {
|
if (!next) {
|
||||||
TRY_OR_DISCARD(array_object.set(vm.names.length, Value(k), Object::ShouldThrowExceptions::Yes));
|
TRY_OR_DISCARD(array_object.set(vm.names.length, Value(k), Object::ShouldThrowExceptions::Yes));
|
||||||
return array;
|
return array;
|
||||||
|
|
|
@ -287,9 +287,7 @@ ThrowCompletionOr<Vector<String>> string_list_from_iterable(GlobalObject& global
|
||||||
// 5. Repeat, while next is not false,
|
// 5. Repeat, while next is not false,
|
||||||
do {
|
do {
|
||||||
// a. Set next to ? IteratorStep(iteratorRecord).
|
// a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
next = iterator_step(global_object, *iterator_record);
|
next = TRY(iterator_step(global_object, *iterator_record));
|
||||||
if (auto* exception = vm.exception())
|
|
||||||
return throw_completion(exception->value());
|
|
||||||
|
|
||||||
// b. If next is not false, then
|
// b. If next is not false, then
|
||||||
if (next != nullptr) {
|
if (next != nullptr) {
|
||||||
|
|
|
@ -75,15 +75,15 @@ Value iterator_value(GlobalObject& global_object, Object& iterator_result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.4.5 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep
|
// 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& 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);
|
auto done = iterator_complete(global_object, *result);
|
||||||
if (vm.exception())
|
if (auto* exception = vm.exception())
|
||||||
return {};
|
return throw_completion(exception->value());
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -21,7 +21,7 @@ enum class IteratorHint {
|
||||||
|
|
||||||
ThrowCompletionOr<Object*> get_iterator(GlobalObject&, Value value, IteratorHint hint = IteratorHint::Sync, Value method = {});
|
ThrowCompletionOr<Object*> get_iterator(GlobalObject&, Value value, IteratorHint hint = IteratorHint::Sync, Value method = {});
|
||||||
ThrowCompletionOr<Object*> iterator_next(Object& iterator, Value value = {});
|
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);
|
bool iterator_complete(GlobalObject&, Object& iterator_result);
|
||||||
Value iterator_value(GlobalObject&, Object& iterator_result);
|
Value iterator_value(GlobalObject&, Object& iterator_result);
|
||||||
void iterator_close(Object& iterator);
|
void iterator_close(Object& iterator);
|
||||||
|
|
|
@ -100,11 +100,12 @@ static Value perform_promise_common(GlobalObject& global_object, Object& iterato
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto* next = iterator_step(global_object, iterator_record);
|
auto next_or_error = iterator_step(global_object, iterator_record);
|
||||||
if (vm.exception()) {
|
if (next_or_error.is_throw_completion()) {
|
||||||
set_iterator_record_complete(global_object, iterator_record);
|
set_iterator_record_complete(global_object, iterator_record);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
auto* next = next_or_error.release_value();
|
||||||
|
|
||||||
if (!next) {
|
if (!next) {
|
||||||
set_iterator_record_complete(global_object, iterator_record);
|
set_iterator_record_complete(global_object, iterator_record);
|
||||||
|
|
|
@ -51,9 +51,7 @@ ThrowCompletionOr<MarkedValueList> iterable_to_list_of_type(GlobalObject& global
|
||||||
// 4. Repeat, while next is not false,
|
// 4. Repeat, while next is not false,
|
||||||
while (next) {
|
while (next) {
|
||||||
// a. Set next to ? IteratorStep(iteratorRecord).
|
// a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
auto* iterator_result = iterator_step(global_object, *iterator_record);
|
auto* iterator_result = TRY(iterator_step(global_object, *iterator_record));
|
||||||
if (auto* exception = vm.exception())
|
|
||||||
return throw_completion(exception->value());
|
|
||||||
next = iterator_result;
|
next = iterator_result;
|
||||||
|
|
||||||
// b. If next is not false, then
|
// b. If next is not false, then
|
||||||
|
|
|
@ -501,9 +501,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(CalendarPrototype::fields)
|
||||||
// 7. Repeat, while next is not false,
|
// 7. Repeat, while next is not false,
|
||||||
while (true) {
|
while (true) {
|
||||||
// a. Set next to ? IteratorStep(iteratorRecord).
|
// a. Set next to ? IteratorStep(iteratorRecord).
|
||||||
auto* next = iterator_step(global_object, *iterator_record);
|
auto* next = TRY_OR_DISCARD(iterator_step(global_object, *iterator_record));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
// b. If next is not false, then
|
// b. If next is not false, then
|
||||||
if (!next)
|
if (!next)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue