diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-04-16 23:54:41 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-17 00:24:09 +0200 |
commit | e3c634fdd05b5eefc41d7952adffa0bdb41099fa (patch) | |
tree | 5492657d4cb4ae352c4fbf3e973ebf40d62943c4 /Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp | |
parent | 06a2173586dfd2d0f61f78a5920b50d722fc94d6 (diff) | |
download | serenity-e3c634fdd05b5eefc41d7952adffa0bdb41099fa.zip |
LibJS: Implement initializing a TypedArray from an iterable object
Based on these specifications (which required IterableToList as well):
https://tc39.es/ecma262/#sec-typedarray
https://tc39.es/ecma262/#sec-initializetypedarrayfromlist
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 6dd9259203..0b80ab0625 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -92,6 +92,21 @@ void iterator_close([[maybe_unused]] Object& iterator) TODO(); } +MarkedValueList iterable_to_list(GlobalObject& global_object, Value iterable, Value method) +{ + auto& vm = global_object.vm(); + MarkedValueList values(vm.heap()); + get_iterator_values( + global_object, iterable, [&](auto value) { + if (vm.exception()) + return IterationDecision::Break; + values.append(value); + return IterationDecision::Continue; + }, + method); + return values; +} + Value create_iterator_result_object(GlobalObject& global_object, Value value, bool done) { auto& vm = global_object.vm(); @@ -101,11 +116,11 @@ Value create_iterator_result_object(GlobalObject& global_object, Value value, bo return object; } -void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<IterationDecision(Value)> callback) +void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<IterationDecision(Value)> callback, Value method) { auto& vm = global_object.vm(); - auto iterator = get_iterator(global_object, value); + auto iterator = get_iterator(global_object, value, "sync", method); if (!iterator) return; |