V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
bytecode-array-random-iterator.h
1 // Copyright 2016 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_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
6 #define V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
7 
8 #include "src/interpreter/bytecode-array-accessor.h"
9 #include "src/zone/zone-containers.h"
10 #include "src/zone/zone.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace interpreter {
15 
16 class V8_EXPORT_PRIVATE BytecodeArrayRandomIterator final
17  : public BytecodeArrayAccessor {
18  public:
19  explicit BytecodeArrayRandomIterator(Handle<BytecodeArray> bytecode_array,
20  Zone* zone);
21 
22  BytecodeArrayRandomIterator& operator++() {
23  ++current_index_;
24  UpdateOffsetFromIndex();
25  return *this;
26  }
27  BytecodeArrayRandomIterator& operator--() {
28  --current_index_;
29  UpdateOffsetFromIndex();
30  return *this;
31  }
32 
33  BytecodeArrayRandomIterator& operator+=(int offset) {
34  current_index_ += offset;
35  UpdateOffsetFromIndex();
36  return *this;
37  }
38 
39  BytecodeArrayRandomIterator& operator-=(int offset) {
40  current_index_ -= offset;
41  UpdateOffsetFromIndex();
42  return *this;
43  }
44 
45  int current_index() const { return current_index_; }
46 
47  size_t size() const { return offsets_.size(); }
48 
49  void GoToIndex(int index) {
50  current_index_ = index;
51  UpdateOffsetFromIndex();
52  }
53  void GoToStart() {
54  current_index_ = 0;
55  UpdateOffsetFromIndex();
56  }
57  void GoToEnd() {
58  DCHECK_LT(offsets_.size() - 1, static_cast<size_t>(INT_MAX));
59  current_index_ = static_cast<int>(offsets_.size() - 1);
60  UpdateOffsetFromIndex();
61  }
62 
63  bool IsValid() const;
64 
65  private:
66  ZoneVector<int> offsets_;
67  int current_index_;
68 
69  void UpdateOffsetFromIndex();
70 
71  DISALLOW_COPY_AND_ASSIGN(BytecodeArrayRandomIterator);
72 };
73 
74 } // namespace interpreter
75 } // namespace internal
76 } // namespace v8
77 
78 #endif // V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
Definition: libplatform.h:13