1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:28:13 +00:00

LibJS: Convert IteratorComplete AO to ThrowCompletionOr

This commit is contained in:
Timothy Flynn 2021-10-20 09:00:37 -04:00 committed by Linus Groh
parent 8be1caa05d
commit a64752cd34
4 changed files with 15 additions and 13 deletions

View file

@ -149,9 +149,10 @@ void IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const
return;
auto* iterator_result = iterator_result_or_error.release_value();
auto complete = iterator_complete(global_object, *iterator_result);
if (vm.exception())
auto complete_or_error = iterator_complete(global_object, *iterator_result);
if (complete_or_error.is_error())
return;
auto complete = complete_or_error.release_value();
if (complete) {
interpreter.accumulator() = array;
@ -506,7 +507,13 @@ void IteratorResultDone::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() = Value(iterator_complete(interpreter.global_object(), *iterator_result));
auto complete_or_error = iterator_complete(interpreter.global_object(), *iterator_result);
if (complete_or_error.is_error())
return;
auto complete = complete_or_error.release_value();
interpreter.accumulator() = Value(complete);
}
void IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const

View file

@ -57,12 +57,12 @@ ThrowCompletionOr<Object*> iterator_next(Object& iterator, Value value)
}
// 7.4.3 IteratorComplete ( iterResult ), https://tc39.es/ecma262/#sec-iteratorcomplete
bool iterator_complete(GlobalObject& global_object, Object& iterator_result)
ThrowCompletionOr<bool> iterator_complete(GlobalObject& global_object, Object& iterator_result)
{
auto& vm = global_object.vm();
// 1. Return ! ToBoolean(? Get(iterResult, "done")).
return TRY_OR_DISCARD(iterator_result.get(vm.names.done)).to_boolean();
return TRY(iterator_result.get(vm.names.done)).to_boolean();
}
// 7.4.4 IteratorValue ( iterResult ), https://tc39.es/ecma262/#sec-iteratorvalue
@ -77,13 +77,8 @@ Value iterator_value(GlobalObject& global_object, Object& iterator_result)
// 7.4.5 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep
ThrowCompletionOr<Object*> iterator_step(GlobalObject& global_object, Object& iterator)
{
auto& vm = global_object.vm();
auto* result = TRY(iterator_next(iterator));
auto done = iterator_complete(global_object, *result);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
auto done = TRY(iterator_complete(global_object, *result));
if (done)
return nullptr;

View file

@ -22,7 +22,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 = {});
ThrowCompletionOr<Object*> iterator_step(GlobalObject&, Object& iterator);
bool iterator_complete(GlobalObject&, Object& iterator_result);
ThrowCompletionOr<bool> iterator_complete(GlobalObject&, Object& iterator_result);
Value iterator_value(GlobalObject&, Object& iterator_result);
void iterator_close(Object& iterator);
Object* create_iterator_result_object(GlobalObject&, Value value, bool done);

View file

@ -72,7 +72,7 @@ static bool iterator_record_is_complete(GlobalObject& global_object, Object& ite
// FIXME: Create a native iterator structure with the [[Done]] internal slot. For now, temporarily clear
// the exception so we can access the "done" property on the iterator object.
TemporaryClearException clear_exception(vm);
return iterator_complete(global_object, iterator_record);
return MUST(iterator_complete(global_object, iterator_record));
}
static void set_iterator_record_complete(GlobalObject& global_object, Object& iterator_record)