2015-10-01 13:48:05 +00:00
|
|
|
// 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/objects.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<TypeFeedbackVector> vector)
|
|
|
|
: vector_(vector) {
|
2015-10-07 10:33:22 +00:00
|
|
|
int slot_count = vector->slot_count();
|
2015-10-01 13:48:05 +00:00
|
|
|
slots_.reserve(slot_count);
|
2015-10-07 10:33:22 +00:00
|
|
|
TypeFeedbackMetadataIterator iter(vector->metadata());
|
2015-10-01 13:48:05 +00:00
|
|
|
while (iter.HasNext()) {
|
|
|
|
FeedbackVectorSlot slot = iter.Next();
|
|
|
|
slots_.push_back(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<TypeFeedbackVector> vector() { return vector_; }
|
|
|
|
|
|
|
|
// Returns slot identifier by numerical index.
|
|
|
|
FeedbackVectorSlot 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<TypeFeedbackVector> vector_;
|
|
|
|
std::vector<FeedbackVectorSlot> slots_;
|
|
|
|
};
|
|
|
|
|
2015-10-07 10:33:22 +00:00
|
|
|
template <typename Spec>
|
|
|
|
Handle<TypeFeedbackVector> NewTypeFeedbackVector(Isolate* isolate, Spec* spec) {
|
|
|
|
Handle<TypeFeedbackMetadata> metadata =
|
|
|
|
TypeFeedbackMetadata::New(isolate, spec);
|
|
|
|
return TypeFeedbackVector::New(isolate, metadata);
|
|
|
|
}
|
|
|
|
|
2017-01-26 10:03:00 +00:00
|
|
|
template <typename Spec>
|
|
|
|
Handle<TypeFeedbackMetadata> NewTypeFeedbackMetadata(Isolate* isolate,
|
|
|
|
Spec* spec) {
|
|
|
|
return TypeFeedbackMetadata::New(isolate, spec);
|
|
|
|
}
|
2015-10-07 10:33:22 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif
|