Index: src/builtins/builtins-iterator.cc |
diff --git a/src/builtins/builtins-iterator.cc b/src/builtins/builtins-iterator.cc |
index 7b91e364eb2cfd22517a9157f0a235acc9bdd046..d3dbf490a6cf3cec53a653b57315a51c43c316ad 100644 |
--- a/src/builtins/builtins-iterator.cc |
+++ b/src/builtins/builtins-iterator.cc |
@@ -2,8 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "src/builtins/builtins.h" |
#include "src/builtins/builtins-utils.h" |
+#include "src/builtins/builtins.h" |
+#include "src/frames-inl.h" |
namespace v8 { |
namespace internal { |
@@ -13,5 +14,55 @@ void Builtins::Generate_IteratorPrototypeIterator( |
assembler->Return(assembler->Parameter(0)); |
} |
+BUILTIN(ModuleNamespaceIterator) { |
+ HandleScope scope(isolate); |
+ DCHECK_EQ(1, args.length()); |
+ Handle<Object> receiver = args.at<Object>(0); |
+ |
+ if (!receiver->IsJSModuleNamespace()) { |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
+ isolate->factory()->iterator_symbol(), receiver)); |
+ } |
+ auto ns = Handle<JSModuleNamespace>::cast(receiver); |
+ |
+ Handle<FixedArray> names = |
+ KeyAccumulator::GetKeys(ns, KeyCollectionMode::kOwnOnly, SKIP_SYMBOLS) |
+ .ToHandleChecked(); |
+ return *isolate->factory()->NewJSFixedArrayIterator(names); |
+} |
+ |
+BUILTIN(FixedArrayIteratorNext) { |
+ HandleScope scope(isolate); |
+ DCHECK_EQ(1, args.length()); |
+ Handle<Object> receiver = args.at<Object>(0); |
+ |
+ // It is an error if this function is called on anything other than the |
+ // particular iterator object for which the function was created. |
+ if (!receiver->IsJSFixedArrayIterator() || |
+ Handle<JSFixedArrayIterator>::cast(receiver)->initial_next() != |
+ *args.target<JSFunction>()) { |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, |
+ isolate->factory()->next_string(), receiver)); |
+ } |
+ |
+ auto iterator = Handle<JSFixedArrayIterator>::cast(receiver); |
+ Handle<Object> value; |
+ bool done; |
+ |
+ int index = iterator->index(); |
+ if (index < iterator->array()->length()) { |
+ value = handle(iterator->array()->get(index), isolate); |
+ done = false; |
+ iterator->set_index(index + 1); |
+ } else { |
+ value = isolate->factory()->undefined_value(); |
+ done = true; |
+ } |
+ |
+ return *isolate->factory()->NewJSIteratorResult(value, done); |
+} |
+ |
} // namespace internal |
} // namespace v8 |