summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-10-20 09:00:37 -0400
committerLinus Groh <mail@linusgroh.de>2021-10-21 00:26:45 +0100
commita64752cd34b8ca2ce49fc9989bef60a1175e6ffb (patch)
treed2657343b40fc5a84227777fd7f195474ba3c934 /Userland/Libraries
parent8be1caa05d57c2571e9215875b0e5e6dd7b7845a (diff)
downloadserenity-a64752cd34b8ca2ce49fc9989bef60a1175e6ffb.zip
LibJS: Convert IteratorComplete AO to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp13
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp11
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp2
4 files changed, 15 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 5dc4201ee5..50aa33f349 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -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
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
index 3373639505..65815327d6 100644
--- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
@@ -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;
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h
index 17fe2a202d..cee7cecc1f 100644
--- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h
@@ -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);
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index e31f398469..feadd749e6 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -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)