OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PROTOTYPE_H_ | 5 #ifndef V8_PROTOTYPE_H_ |
6 #define V8_PROTOTYPE_H_ | 6 #define V8_PROTOTYPE_H_ |
7 | 7 |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 WhereToStart where_to_start = START_AT_PROTOTYPE) | 32 WhereToStart where_to_start = START_AT_PROTOTYPE) |
33 : did_jump_to_prototype_chain_(false), | 33 : did_jump_to_prototype_chain_(false), |
34 object_(NULL), | 34 object_(NULL), |
35 handle_(receiver), | 35 handle_(receiver), |
36 isolate_(isolate) { | 36 isolate_(isolate) { |
37 CHECK(!handle_.is_null()); | 37 CHECK(!handle_.is_null()); |
38 if (where_to_start == START_AT_PROTOTYPE) { | 38 if (where_to_start == START_AT_PROTOTYPE) { |
39 Advance(); | 39 Advance(); |
40 } | 40 } |
41 } | 41 } |
42 | |
42 PrototypeIterator(Isolate* isolate, Object* receiver, | 43 PrototypeIterator(Isolate* isolate, Object* receiver, |
43 WhereToStart where_to_start = START_AT_PROTOTYPE) | 44 WhereToStart where_to_start = START_AT_PROTOTYPE) |
44 : did_jump_to_prototype_chain_(false), | 45 : did_jump_to_prototype_chain_(false), |
45 object_(receiver), | 46 object_(receiver), |
46 isolate_(isolate) { | 47 isolate_(isolate) { |
47 if (where_to_start == START_AT_PROTOTYPE) { | 48 if (where_to_start == START_AT_PROTOTYPE) { |
48 Advance(); | 49 Advance(); |
49 } | 50 } |
50 } | 51 } |
52 | |
51 explicit PrototypeIterator(Map* receiver_map) | 53 explicit PrototypeIterator(Map* receiver_map) |
52 : did_jump_to_prototype_chain_(true), | 54 : did_jump_to_prototype_chain_(true), |
53 object_(receiver_map->prototype()), | 55 object_(receiver_map->prototype()), |
54 isolate_(receiver_map->GetIsolate()) {} | 56 isolate_(receiver_map->GetIsolate()) {} |
57 | |
55 explicit PrototypeIterator(Handle<Map> receiver_map) | 58 explicit PrototypeIterator(Handle<Map> receiver_map) |
56 : did_jump_to_prototype_chain_(true), | 59 : did_jump_to_prototype_chain_(true), |
57 object_(NULL), | 60 object_(NULL), |
58 handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())), | 61 handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())), |
59 isolate_(receiver_map->GetIsolate()) {} | 62 isolate_(receiver_map->GetIsolate()) {} |
63 | |
60 ~PrototypeIterator() {} | 64 ~PrototypeIterator() {} |
61 | 65 |
62 Object* GetCurrent() const { | 66 template <typename T = Object> |
67 T* GetCurrent() const { | |
63 DCHECK(handle_.is_null()); | 68 DCHECK(handle_.is_null()); |
64 return object_; | 69 return T::cast(object_); |
65 } | 70 } |
71 | |
66 static Handle<Object> GetCurrent(const PrototypeIterator& iterator) { | 72 static Handle<Object> GetCurrent(const PrototypeIterator& iterator) { |
Jakob Kummerow
2015/09/09 14:29:55
Why do we still need this?
Camillo Bruni
2015/09/10 10:53:59
removed
| |
67 DCHECK(!iterator.handle_.is_null()); | 73 DCHECK(!iterator.handle_.is_null()); |
68 return iterator.handle_; | 74 return iterator.handle_; |
69 } | 75 } |
76 | |
77 template <typename T> | |
78 static Handle<T> GetCurrent(const PrototypeIterator& iterator) { | |
79 DCHECK(!iterator.handle_.is_null()); | |
80 return Handle<T>::cast(iterator.handle_); | |
81 } | |
82 | |
70 void Advance() { | 83 void Advance() { |
71 if (handle_.is_null() && object_->IsJSProxy()) { | 84 if (handle_.is_null() && object_->IsJSProxy()) { |
72 did_jump_to_prototype_chain_ = true; | 85 did_jump_to_prototype_chain_ = true; |
73 object_ = isolate_->heap()->null_value(); | 86 object_ = isolate_->heap()->null_value(); |
74 return; | 87 return; |
75 } else if (!handle_.is_null() && handle_->IsJSProxy()) { | 88 } else if (!handle_.is_null() && handle_->IsJSProxy()) { |
76 did_jump_to_prototype_chain_ = true; | 89 did_jump_to_prototype_chain_ = true; |
77 handle_ = handle(isolate_->heap()->null_value(), isolate_); | 90 handle_ = handle(isolate_->heap()->null_value(), isolate_); |
78 return; | 91 return; |
79 } | 92 } |
80 AdvanceIgnoringProxies(); | 93 AdvanceIgnoringProxies(); |
81 } | 94 } |
95 | |
82 void AdvanceIgnoringProxies() { | 96 void AdvanceIgnoringProxies() { |
83 if (!did_jump_to_prototype_chain_) { | 97 if (!did_jump_to_prototype_chain_) { |
84 did_jump_to_prototype_chain_ = true; | 98 did_jump_to_prototype_chain_ = true; |
85 if (handle_.is_null()) { | 99 if (handle_.is_null()) { |
86 object_ = object_->GetRootMap(isolate_)->prototype(); | 100 object_ = object_->GetRootMap(isolate_)->prototype(); |
87 } else { | 101 } else { |
88 handle_ = handle(handle_->GetRootMap(isolate_)->prototype(), isolate_); | 102 handle_ = handle(handle_->GetRootMap(isolate_)->prototype(), isolate_); |
89 } | 103 } |
90 } else { | 104 } else { |
91 if (handle_.is_null()) { | 105 if (handle_.is_null()) { |
92 object_ = HeapObject::cast(object_)->map()->prototype(); | 106 object_ = HeapObject::cast(object_)->map()->prototype(); |
93 } else { | 107 } else { |
94 handle_ = | 108 handle_ = |
95 handle(HeapObject::cast(*handle_)->map()->prototype(), isolate_); | 109 handle(HeapObject::cast(*handle_)->map()->prototype(), isolate_); |
96 } | 110 } |
97 } | 111 } |
98 } | 112 } |
113 | |
99 bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const { | 114 bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const { |
100 if (handle_.is_null()) { | 115 if (handle_.is_null()) { |
101 return object_->IsNull() || | 116 return object_->IsNull() || |
102 (did_jump_to_prototype_chain_ && | 117 (did_jump_to_prototype_chain_ && |
103 where_to_end == END_AT_NON_HIDDEN && | 118 where_to_end == END_AT_NON_HIDDEN && |
104 !HeapObject::cast(object_)->map()->is_hidden_prototype()); | 119 !HeapObject::cast(object_)->map()->is_hidden_prototype()); |
105 } else { | 120 } else { |
106 return handle_->IsNull() || | 121 return handle_->IsNull() || |
107 (did_jump_to_prototype_chain_ && | 122 (did_jump_to_prototype_chain_ && |
108 where_to_end == END_AT_NON_HIDDEN && | 123 where_to_end == END_AT_NON_HIDDEN && |
109 !Handle<HeapObject>::cast(handle_)->map()->is_hidden_prototype()); | 124 !Handle<HeapObject>::cast(handle_)->map()->is_hidden_prototype()); |
110 } | 125 } |
111 } | 126 } |
127 | |
112 bool IsAtEnd(Object* final_object) { | 128 bool IsAtEnd(Object* final_object) { |
113 DCHECK(handle_.is_null()); | 129 DCHECK(handle_.is_null()); |
114 return object_->IsNull() || object_ == final_object; | 130 return object_->IsNull() || object_ == final_object; |
115 } | 131 } |
132 | |
116 bool IsAtEnd(Handle<Object> final_object) { | 133 bool IsAtEnd(Handle<Object> final_object) { |
117 DCHECK(!handle_.is_null()); | 134 DCHECK(!handle_.is_null()); |
118 return handle_->IsNull() || *handle_ == *final_object; | 135 return handle_->IsNull() || *handle_ == *final_object; |
119 } | 136 } |
120 | 137 |
121 private: | 138 private: |
122 bool did_jump_to_prototype_chain_; | 139 bool did_jump_to_prototype_chain_; |
123 Object* object_; | 140 Object* object_; |
124 Handle<Object> handle_; | 141 Handle<Object> handle_; |
125 Isolate* isolate_; | 142 Isolate* isolate_; |
126 | 143 |
127 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); | 144 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); |
128 }; | 145 }; |
129 | 146 |
130 | 147 |
131 } // namespace internal | 148 } // namespace internal |
132 | 149 |
133 } // namespace v8 | 150 } // namespace v8 |
134 | 151 |
135 #endif // V8_PROTOTYPE_H_ | 152 #endif // V8_PROTOTYPE_H_ |
OLD | NEW |