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:
parent
a64752cd34
commit
7b4814f74c
Notes:
sideshowbarker
2024-07-18 02:06:59 +09:00
Author: https://github.com/trflynn89
Commit: 7b4814f74c
Pull-request: https://github.com/SerenityOS/serenity/pull/10546
Reviewed-by: https://github.com/IdanHo
Reviewed-by: https://github.com/linusg ✅
8 changed files with 20 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {});
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue