| 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 11 matching lines...) Expand all Loading... |
| 22 * The PrototypeIterator can either run to the null_value(), the first | 22 * The PrototypeIterator can either run to the null_value(), the first |
| 23 * non-hidden prototype, or a given object. | 23 * non-hidden prototype, or a given object. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 class PrototypeIterator { | 26 class PrototypeIterator { |
| 27 public: | 27 public: |
| 28 enum WhereToStart { START_AT_RECEIVER, START_AT_PROTOTYPE }; | 28 enum WhereToStart { START_AT_RECEIVER, START_AT_PROTOTYPE }; |
| 29 | 29 |
| 30 enum WhereToEnd { END_AT_NULL, END_AT_NON_HIDDEN }; | 30 enum WhereToEnd { END_AT_NULL, END_AT_NON_HIDDEN }; |
| 31 | 31 |
| 32 enum WhenToCallProxyTrap { TRAP_CALL_ALWAYS, STOP_EARLY }; |
| 33 |
| 32 const int kProxyPrototypeLimit = 100 * 1000; | 34 const int kProxyPrototypeLimit = 100 * 1000; |
| 33 | 35 |
| 34 PrototypeIterator(Isolate* isolate, Handle<JSReceiver> receiver, | 36 PrototypeIterator(Isolate* isolate, Handle<JSReceiver> receiver, |
| 35 WhereToStart where_to_start = START_AT_PROTOTYPE, | 37 WhereToStart where_to_start = START_AT_PROTOTYPE, |
| 36 WhereToEnd where_to_end = END_AT_NULL) | 38 WhereToEnd where_to_end = END_AT_NULL) |
| 37 : object_(NULL), | 39 : object_(NULL), |
| 38 handle_(receiver), | 40 handle_(receiver), |
| 39 isolate_(isolate), | 41 isolate_(isolate), |
| 40 where_to_end_(where_to_end), | 42 where_to_end_(where_to_end), |
| 41 is_at_end_(false), | 43 is_at_end_(false), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 120 |
| 119 if (handle_.is_null()) { | 121 if (handle_.is_null()) { |
| 120 object_ = prototype; | 122 object_ = prototype; |
| 121 } else { | 123 } else { |
| 122 handle_ = handle(prototype, isolate_); | 124 handle_ = handle(prototype, isolate_); |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 // Returns false iff a call to JSProxy::GetPrototype throws. | 128 // Returns false iff a call to JSProxy::GetPrototype throws. |
| 127 // TODO(neis): This should probably replace Advance(). | 129 // TODO(neis): This should probably replace Advance(). |
| 128 bool AdvanceFollowingProxies() { | 130 bool AdvanceFollowingProxies( |
| 131 WhenToCallProxyTrap when_to_call_trap = TRAP_CALL_ALWAYS) { |
| 129 DCHECK(!(handle_.is_null() && object_->IsJSProxy())); | 132 DCHECK(!(handle_.is_null() && object_->IsJSProxy())); |
| 130 if (!HasAccess()) { | 133 if (!HasAccess()) { |
| 131 // Abort the lookup if we do not have access to the current object. | 134 // Abort the lookup if we do not have access to the current object. |
| 132 handle_ = isolate_->factory()->null_value(); | 135 handle_ = isolate_->factory()->null_value(); |
| 133 is_at_end_ = true; | 136 is_at_end_ = true; |
| 134 return true; | 137 return true; |
| 135 } | 138 } |
| 136 if (handle_.is_null() || !handle_->IsJSProxy()) { | 139 if (handle_.is_null() || !handle_->IsJSProxy()) { |
| 137 AdvanceIgnoringProxies(); | 140 AdvanceIgnoringProxies(); |
| 138 return true; | 141 return true; |
| 139 } | 142 } |
| 143 |
| 144 // Proxies can never have hidden protoypes |
| 145 if (where_to_end_ == END_AT_NON_HIDDEN) { |
| 146 is_at_end_ = true; |
| 147 if (when_to_call_trap == STOP_EARLY) return true; |
| 148 } |
| 149 |
| 140 // Due to possible __proto__ recursion limit the number of Proxies | 150 // Due to possible __proto__ recursion limit the number of Proxies |
| 141 // we visit to an arbitrarily chosen large number. | 151 // we visit to an arbitrarily chosen large number. |
| 142 seen_proxies_++; | 152 seen_proxies_++; |
| 143 if (seen_proxies_ > kProxyPrototypeLimit) { | 153 if (seen_proxies_ > kProxyPrototypeLimit) { |
| 144 isolate_->Throw( | 154 isolate_->Throw( |
| 145 *isolate_->factory()->NewRangeError(MessageTemplate::kStackOverflow)); | 155 *isolate_->factory()->NewRangeError(MessageTemplate::kStackOverflow)); |
| 146 return false; | 156 return false; |
| 147 } | 157 } |
| 148 MaybeHandle<Object> proto = | 158 MaybeHandle<Object> proto = |
| 149 JSProxy::GetPrototype(Handle<JSProxy>::cast(handle_)); | 159 JSProxy::GetPrototype(Handle<JSProxy>::cast(handle_)); |
| 150 if (!proto.ToHandle(&handle_)) return false; | 160 if (!proto.ToHandle(&handle_)) return false; |
| 151 is_at_end_ = where_to_end_ == END_AT_NON_HIDDEN || handle_->IsNull(); | 161 if (handle_->IsNull()) is_at_end_ = true; |
| 152 return true; | 162 return true; |
| 153 } | 163 } |
| 154 | 164 |
| 155 bool IsAtEnd() const { return is_at_end_; } | 165 bool IsAtEnd() const { return is_at_end_; } |
| 156 | 166 |
| 157 private: | 167 private: |
| 158 Object* object_; | 168 Object* object_; |
| 159 Handle<Object> handle_; | 169 Handle<Object> handle_; |
| 160 Isolate* isolate_; | 170 Isolate* isolate_; |
| 161 WhereToEnd where_to_end_; | 171 WhereToEnd where_to_end_; |
| 162 bool is_at_end_; | 172 bool is_at_end_; |
| 163 int seen_proxies_; | 173 int seen_proxies_; |
| 164 | 174 |
| 165 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); | 175 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); |
| 166 }; | 176 }; |
| 167 | 177 |
| 168 | 178 |
| 169 } // namespace internal | 179 } // namespace internal |
| 170 | 180 |
| 171 } // namespace v8 | 181 } // namespace v8 |
| 172 | 182 |
| 173 #endif // V8_PROTOTYPE_H_ | 183 #endif // V8_PROTOTYPE_H_ |
| OLD | NEW |