1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibJS: Convert IteratorValue AO to ThrowCompletionOr

This commit is contained in:
Timothy Flynn 2021-10-20 09:05:52 -04:00 committed by Linus Groh
parent a64752cd34
commit 7b4814f74c
Notes: sideshowbarker 2024-07-18 02:06:59 +09:00
8 changed files with 20 additions and 21 deletions

View file

@ -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

View file

@ -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) {

View file

@ -292,9 +292,7 @@ ThrowCompletionOr<Vector<String>> 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()) {

View file

@ -66,12 +66,12 @@ ThrowCompletionOr<bool> 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<Value> 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

View file

@ -23,7 +23,7 @@ ThrowCompletionOr<Object*> get_iterator(GlobalObject&, Value value, IteratorHint
ThrowCompletionOr<Object*> iterator_next(Object& iterator, Value value = {});
ThrowCompletionOr<Object*> iterator_step(GlobalObject&, Object& iterator);
ThrowCompletionOr<bool> iterator_complete(GlobalObject&, Object& iterator_result);
Value iterator_value(GlobalObject&, Object& iterator_result);
ThrowCompletionOr<Value> 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 = {});

View file

@ -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());

View file

@ -57,9 +57,7 @@ ThrowCompletionOr<MarkedValueList> 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).

View file

@ -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()) {