v8/test/cctest/feedback-vector-helper.h
Feng Yu b09b5f7867 [test] Migrate cctest/test-feedback-vector to unittests/
Bug: v8:12781
Change-Id: I3dfbc03dd2dd4ac32d16cf153146979a0b4bcf50
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3829504
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82628}
2022-08-22 16:36:28 +00:00

48 lines
1.3 KiB
C++

// 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.
#ifndef V8_TEST_FEEDBACK_VECTOR_H_
#define V8_TEST_FEEDBACK_VECTOR_H_
#include "src/execution/isolate.h"
#include "src/objects/feedback-vector.h"
#include "src/objects/objects.h"
#include "src/objects/shared-function-info.h"
namespace v8 {
namespace internal {
// Helper class that allows to write tests in a slot size independent manner.
// Use helper.slot(X) to get X'th slot identifier.
class FeedbackVectorHelper {
public:
explicit FeedbackVectorHelper(Handle<FeedbackVector> vector)
: vector_(vector) {
int slot_count = vector->length();
slots_.reserve(slot_count);
FeedbackMetadataIterator iter(vector->metadata());
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
slots_.push_back(slot);
}
}
Handle<FeedbackVector> vector() { return vector_; }
// Returns slot identifier by numerical index.
FeedbackSlot slot(int index) const { return slots_[index]; }
// Returns the number of slots in the feedback vector.
int slot_count() const { return static_cast<int>(slots_.size()); }
private:
Handle<FeedbackVector> vector_;
std::vector<FeedbackSlot> slots_;
};
} // namespace internal
} // namespace v8
#endif