bytecode-array-random-iterator.cc 1.12 KB
Newer Older
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/interpreter/bytecode-array-random-iterator.h"
6
#include "src/objects-inl.h"
7
#include "src/objects/code-inl.h"
8 9 10 11 12

namespace v8 {
namespace internal {
namespace interpreter {

13
BytecodeArrayRandomIterator::BytecodeArrayRandomIterator(
14 15 16 17 18 19 20 21
    Handle<BytecodeArray> bytecode_array, Zone* zone)
    : BytecodeArrayAccessor(bytecode_array, 0), offsets_(zone) {
  // Run forwards through the bytecode array to determine the offset of each
  // bytecode.
  while (current_offset() < bytecode_array->length()) {
    offsets_.push_back(current_offset());
    SetOffset(current_offset() + current_bytecode_size());
  }
22
  GoToStart();
23 24
}

25 26 27
bool BytecodeArrayRandomIterator::IsValid() const {
  return current_index_ >= 0 &&
         static_cast<size_t>(current_index_) < offsets_.size();
28 29
}

30 31 32
void BytecodeArrayRandomIterator::UpdateOffsetFromIndex() {
  if (IsValid()) {
    SetOffset(offsets_[current_index_]);
33 34 35 36 37 38
  }
}

}  // namespace interpreter
}  // namespace internal
}  // namespace v8