• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_OBJECTS_JS_COLLECTION_ITERATOR_H_
6 #define V8_OBJECTS_JS_COLLECTION_ITERATOR_H_
7 
8 #include "src/common/globals.h"
9 #include "src/objects/js-objects.h"
10 #include "src/objects/objects.h"
11 #include "src/objects/smi.h"
12 
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 #include "torque-generated/src/objects/js-collection-iterator-tq.inc"
20 
21 class JSCollectionIterator
22     : public TorqueGeneratedJSCollectionIterator<JSCollectionIterator,
23                                                  JSObject> {
24  public:
25   void JSCollectionIteratorPrint(std::ostream& os, const char* name);
26 
27   TQ_OBJECT_CONSTRUCTORS(JSCollectionIterator)
28 };
29 
30 // OrderedHashTableIterator is an iterator that iterates over the keys and
31 // values of an OrderedHashTable.
32 //
33 // The iterator has a reference to the underlying OrderedHashTable data,
34 // [table], as well as the current [index] the iterator is at.
35 //
36 // When the OrderedHashTable is rehashed it adds a reference from the old table
37 // to the new table as well as storing enough data about the changes so that the
38 // iterator [index] can be adjusted accordingly.
39 //
40 // When the [Next] result from the iterator is requested, the iterator checks if
41 // there is a newer table that it needs to transition to.
42 template <class Derived, class TableType>
43 class OrderedHashTableIterator : public JSCollectionIterator {
44  public:
45   // Whether the iterator has more elements. This needs to be called before
46   // calling |CurrentKey| and/or |CurrentValue|.
47   bool HasMore();
48 
49   // Move the index forward one.
MoveNext()50   void MoveNext() { set_index(Smi::FromInt(Smi::ToInt(index()) + 1)); }
51 
52   // Returns the current key of the iterator. This should only be called when
53   // |HasMore| returns true.
54   inline Object CurrentKey();
55 
56  private:
57   // Transitions the iterator to the non obsolete backing store. This is a NOP
58   // if the [table] is not obsolete.
59   void Transition();
60 
61   OBJECT_CONSTRUCTORS(OrderedHashTableIterator, JSCollectionIterator);
62 };
63 
64 }  // namespace internal
65 }  // namespace v8
66 
67 #include "src/objects/object-macros-undef.h"
68 
69 #endif  // V8_OBJECTS_JS_COLLECTION_ITERATOR_H_
70