Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: src/builtins/builtins-iterator.cc

Issue 2407423002: [modules] Implement @@iterator on namespace objects. (Closed)
Patch Set: Rename kSize to kHeadersize again. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/types.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698