1 // Copyright 2015 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_TEST_FEEDBACK_VECTOR_H_ 6 #define V8_TEST_FEEDBACK_VECTOR_H_ 7 8 #include "src/objects.h" 9 10 11 namespace v8 { 12 namespace internal { 13 14 // Helper class that allows to write tests in a slot size independent manner. 15 // Use helper.slot(X) to get X'th slot identifier. 16 class FeedbackVectorHelper { 17 public: FeedbackVectorHelper(Handle<TypeFeedbackVector> vector)18 explicit FeedbackVectorHelper(Handle<TypeFeedbackVector> vector) 19 : vector_(vector) { 20 int slot_count = vector->slot_count(); 21 slots_.reserve(slot_count); 22 TypeFeedbackMetadataIterator iter(vector->metadata()); 23 while (iter.HasNext()) { 24 FeedbackVectorSlot slot = iter.Next(); 25 slots_.push_back(slot); 26 } 27 } 28 vector()29 Handle<TypeFeedbackVector> vector() { return vector_; } 30 31 // Returns slot identifier by numerical index. slot(int index)32 FeedbackVectorSlot slot(int index) const { return slots_[index]; } 33 34 // Returns the number of slots in the feedback vector. slot_count()35 int slot_count() const { return static_cast<int>(slots_.size()); } 36 37 private: 38 Handle<TypeFeedbackVector> vector_; 39 std::vector<FeedbackVectorSlot> slots_; 40 }; 41 42 template <typename Spec> NewTypeFeedbackVector(Isolate * isolate,Spec * spec)43Handle<TypeFeedbackVector> NewTypeFeedbackVector(Isolate* isolate, Spec* spec) { 44 Handle<TypeFeedbackMetadata> metadata = 45 TypeFeedbackMetadata::New(isolate, spec); 46 return TypeFeedbackVector::New(isolate, metadata); 47 } 48 49 50 } // namespace internal 51 } // namespace v8 52 53 #endif 54