blob: e36ed14a1bbe067788e0ac1c4ad3f41afbc64ec2 [file] [log] [blame]
// 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.
#include "src/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 {
explicit FeedbackVectorHelper(Handle<FeedbackVector> vector)
: vector_(vector) {
int slot_count = vector->length();
FeedbackMetadataIterator iter(vector->metadata());
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
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()); }
Handle<FeedbackVector> vector_;
std::vector<FeedbackSlot> slots_;
template <typename Spec>
Handle<FeedbackVector> NewFeedbackVector(Isolate* isolate, Spec* spec) {
Handle<FeedbackMetadata> metadata = FeedbackMetadata::New(isolate, spec);
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
isolate->factory()->empty_string(), MaybeHandle<Code>(), false);
return FeedbackVector::New(isolate, shared);
template <typename Spec>
Handle<FeedbackMetadata> NewFeedbackMetadata(Isolate* isolate, Spec* spec) {
return FeedbackMetadata::New(isolate, spec);
} // namespace internal
} // namespace v8