v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-collection-iterator.h
Go to the documentation of this file.
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
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):
15
16namespace v8 {
17namespace internal {
18
19#include "torque-generated/src/objects/js-collection-iterator-tq.inc"
20
22 : public TorqueGeneratedJSCollectionIterator<JSCollectionIterator,
23 JSObject> {
24 public:
25 void JSCollectionIteratorPrint(std::ostream& os, const char* name);
26
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.
42template <class Derived, class TableType>
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.
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.
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
62};
63
64} // namespace internal
65} // namespace v8
66
68
69#endif // V8_OBJECTS_JS_COLLECTION_ITERATOR_H_
void JSCollectionIteratorPrint(std::ostream &os, const char *name)
OBJECT_CONSTRUCTORS(OrderedHashTableIterator, JSCollectionIterator)
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
#define TQ_OBJECT_CONSTRUCTORS(Type)