diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 50aa33f349..ed6fe6ca75 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -134,7 +134,6 @@ void NewArray::execute_impl(Bytecode::Interpreter& interpreter) const void IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const { auto& global_object = interpreter.global_object(); - auto& vm = interpreter.vm(); auto iterator_or_error = interpreter.accumulator().to_object(global_object); if (iterator_or_error.is_error()) return; @@ -159,9 +158,10 @@ void IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const return; } - auto value = iterator_value(global_object, *iterator_result); - if (vm.exception()) + auto value_or_error = iterator_value(global_object, *iterator_result); + if (value_or_error.is_error()) return; + auto value = value_or_error.release_value(); MUST(array->create_data_property_or_throw(index, value)); index++; @@ -522,7 +522,13 @@ void IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const if (iterator_result_or_error.is_error()) return; auto* iterator_result = iterator_result_or_error.release_value(); - interpreter.accumulator() = iterator_value(interpreter.global_object(), *iterator_result); + + auto value_or_error = iterator_value(interpreter.global_object(), *iterator_result); + if (value_or_error.is_error()) + return; + auto value = value_or_error.release_value(); + + interpreter.accumulator() = value; } void NewClass::execute_impl(Bytecode::Interpreter&) const diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 5958903c7f..32bc5740cb 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -134,9 +134,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayConstructor::from) return array; } - auto next_value = iterator_value(global_object, *next); - if (vm.exception()) - return {}; + auto next_value = TRY_OR_DISCARD(iterator_value(global_object, *next)); Value mapped_value; if (map_fn) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index a450f58c2a..c44267031f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -292,9 +292,7 @@ ThrowCompletionOr> string_list_from_iterable(GlobalObject& global // b. If next is not false, then if (next != nullptr) { // i. Let nextValue be ? IteratorValue(next). - auto next_value = iterator_value(global_object, *next); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto next_value = TRY(iterator_value(global_object, *next)); // ii. If Type(nextValue) is not String, then if (!next_value.is_string()) { diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 65815327d6..0d3f69bc1e 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -66,12 +66,12 @@ ThrowCompletionOr iterator_complete(GlobalObject& global_object, Object& i } // 7.4.4 IteratorValue ( iterResult ), https://tc39.es/ecma262/#sec-iteratorvalue -Value iterator_value(GlobalObject& global_object, Object& iterator_result) +ThrowCompletionOr iterator_value(GlobalObject& global_object, Object& iterator_result) { auto& vm = global_object.vm(); // 1. Return ? Get(iterResult, "value"). - return TRY_OR_DISCARD(iterator_result.get(vm.names.value)); + return TRY(iterator_result.get(vm.names.value)); } // 7.4.5 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index cee7cecc1f..8844a5a3a8 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -23,7 +23,7 @@ ThrowCompletionOr get_iterator(GlobalObject&, Value value, IteratorHint ThrowCompletionOr iterator_next(Object& iterator, Value value = {}); ThrowCompletionOr iterator_step(GlobalObject&, Object& iterator); ThrowCompletionOr iterator_complete(GlobalObject&, Object& iterator_result); -Value iterator_value(GlobalObject&, Object& iterator_result); +ThrowCompletionOr iterator_value(GlobalObject&, Object& iterator_result); void iterator_close(Object& iterator); Object* create_iterator_result_object(GlobalObject&, Value value, bool done); MarkedValueList iterable_to_list(GlobalObject&, Value iterable, Value method = {}); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index feadd749e6..3a9feb3b1b 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -117,11 +117,12 @@ static Value perform_promise_common(GlobalObject& global_object, Object& iterato return result_capability.promise; } - auto next_value = iterator_value(global_object, *next); - if (vm.exception()) { + auto next_value_or_error = iterator_value(global_object, *next); + if (next_value_or_error.is_throw_completion()) { set_iterator_record_complete(global_object, iterator_record); return {}; } + auto next_value = next_value_or_error.release_value(); values->values().append(js_undefined()); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 49df0f360d..ecc42e189e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -57,9 +57,7 @@ ThrowCompletionOr iterable_to_list_of_type(GlobalObject& global // b. If next is not false, then if (next) { // i. Let nextValue be ? IteratorValue(next). - auto next_value = iterator_value(global_object, *iterator_result); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto next_value = TRY(iterator_value(global_object, *iterator_result)); // ii. If Type(nextValue) is not an element of elementTypes, then if (auto type = to_option_type(next_value); !type.has_value() || !element_types.contains_slow(*type)) { // 1. Let completion be ThrowCompletion(a newly created TypeError object). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index be82579e52..8b3ce39613 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -508,9 +508,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(CalendarPrototype::fields) break; // i. Let nextValue be ? IteratorValue(next). - auto next_value = iterator_value(global_object, *next); - if (vm.exception()) - return {}; + auto next_value = TRY_OR_DISCARD(iterator_value(global_object, *next)); // ii. If Type(nextValue) is not String, then if (!next_value.is_string()) {