summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-07-04 01:33:37 +0300
committerLinus Groh <mail@linusgroh.de>2021-07-04 00:51:43 +0100
commit5ee1ae37b2e2eafb88114160396be7cd61e7343b (patch)
tree52777cf125799359f45ebc9638effcddf662145a /Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
parentba4d367deae1543ffd03c538dba66bb367fdbc38 (diff)
downloadserenity-5ee1ae37b2e2eafb88114160396be7cd61e7343b.zip
LibJS: Add the IteratorStep abstract iterator operation
As well as add 2 missing exception checks in the IteratorComplete and IteratorValue abstract iterator operations.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
index 0e934e06c0..fbd57f2bd5 100644
--- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp
@@ -73,13 +73,40 @@ 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)
{
- return iterator_result.get(global_object.vm().names.done).value_or(Value(false)).to_boolean();
+ auto& vm = global_object.vm();
+ auto done = iterator_result.get(vm.names.done).value_or(js_undefined());
+ if (vm.exception())
+ return {};
+ return done.to_boolean();
}
// 7.4.4 IteratorValue ( iterResult ), https://tc39.es/ecma262/#sec-iteratorvalue
Value iterator_value(GlobalObject& global_object, Object& iterator_result)
{
- return iterator_result.get(global_object.vm().names.value).value_or(js_undefined());
+ auto& vm = global_object.vm();
+ auto value = iterator_result.get(vm.names.value).value_or(js_undefined());
+ if (vm.exception())
+ return {};
+ return value;
+}
+
+// 7.4.5 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep
+Object* iterator_step(GlobalObject& global_object, Object& iterator)
+{
+ auto& vm = global_object.vm();
+
+ auto result = iterator_next(iterator);
+ if (vm.exception())
+ return {};
+
+ auto done = iterator_complete(global_object, *result);
+ if (vm.exception())
+ return {};
+
+ if (done)
+ return nullptr;
+
+ return result;
}
// 7.4.6 IteratorClose ( iteratorRecord, completion ), https://tc39.es/ecma262/#sec-iteratorclose