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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 /** | 14 /** |
15 * A class to uniformly access the prototype of any Object and walk its | 15 * A class to uniformly access the prototype of any Object and walk its |
16 * prototype chain. | 16 * prototype chain. |
17 * | 17 * |
18 * The PrototypeIterator can either start at the prototype (default), or | 18 * The PrototypeIterator can either start at the prototype (default), or |
19 * include the receiver itself. If a PrototypeIterator is constructed for a | 19 * include the receiver itself. If a PrototypeIterator is constructed for a |
20 * Map, it will always start at the prototype. | 20 * Map, it will always start at the prototype. |
21 * | 21 * |
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 }; | |
29 | |
30 enum WhereToEnd { END_AT_NULL, END_AT_NON_HIDDEN }; | 28 enum WhereToEnd { END_AT_NULL, END_AT_NON_HIDDEN }; |
31 | 29 |
32 const int kProxyPrototypeLimit = 100 * 1000; | 30 const int kProxyPrototypeLimit = 100 * 1000; |
33 | 31 |
34 PrototypeIterator(Isolate* isolate, Handle<JSReceiver> receiver, | 32 PrototypeIterator(Isolate* isolate, Handle<JSReceiver> receiver, |
35 WhereToStart where_to_start = START_AT_PROTOTYPE, | 33 WhereToStart where_to_start = kStartAtPrototype, |
36 WhereToEnd where_to_end = END_AT_NULL) | 34 WhereToEnd where_to_end = END_AT_NULL) |
37 : object_(NULL), | 35 : object_(NULL), |
38 handle_(receiver), | 36 handle_(receiver), |
39 isolate_(isolate), | 37 isolate_(isolate), |
40 where_to_end_(where_to_end), | 38 where_to_end_(where_to_end), |
41 is_at_end_(false), | 39 is_at_end_(false), |
42 seen_proxies_(0) { | 40 seen_proxies_(0) { |
43 CHECK(!handle_.is_null()); | 41 CHECK(!handle_.is_null()); |
44 if (where_to_start == START_AT_PROTOTYPE) Advance(); | 42 if (where_to_start == kStartAtPrototype) Advance(); |
45 } | 43 } |
46 | 44 |
47 PrototypeIterator(Isolate* isolate, JSReceiver* receiver, | 45 PrototypeIterator(Isolate* isolate, JSReceiver* receiver, |
48 WhereToStart where_to_start = START_AT_PROTOTYPE, | 46 WhereToStart where_to_start = kStartAtPrototype, |
49 WhereToEnd where_to_end = END_AT_NULL) | 47 WhereToEnd where_to_end = END_AT_NULL) |
50 : object_(receiver), | 48 : object_(receiver), |
51 isolate_(isolate), | 49 isolate_(isolate), |
52 where_to_end_(where_to_end), | 50 where_to_end_(where_to_end), |
53 is_at_end_(false), | 51 is_at_end_(false), |
54 seen_proxies_(0) { | 52 seen_proxies_(0) { |
55 if (where_to_start == START_AT_PROTOTYPE) Advance(); | 53 if (where_to_start == kStartAtPrototype) Advance(); |
56 } | 54 } |
57 | 55 |
58 explicit PrototypeIterator(Map* receiver_map) | 56 explicit PrototypeIterator(Map* receiver_map) |
59 : object_(receiver_map->prototype()), | 57 : object_(receiver_map->prototype()), |
60 isolate_(receiver_map->GetIsolate()), | 58 isolate_(receiver_map->GetIsolate()), |
61 where_to_end_(END_AT_NULL), | 59 where_to_end_(END_AT_NULL), |
62 is_at_end_(object_->IsNull()) {} | 60 is_at_end_(object_->IsNull()), |
| 61 seen_proxies_(0) {} |
63 | 62 |
64 explicit PrototypeIterator(Handle<Map> receiver_map) | 63 explicit PrototypeIterator(Handle<Map> receiver_map) |
65 : object_(NULL), | 64 : object_(NULL), |
66 handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())), | 65 handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())), |
67 isolate_(receiver_map->GetIsolate()), | 66 isolate_(receiver_map->GetIsolate()), |
68 where_to_end_(END_AT_NULL), | 67 where_to_end_(END_AT_NULL), |
69 is_at_end_(handle_->IsNull()) {} | 68 is_at_end_(handle_->IsNull()), |
| 69 seen_proxies_(0) {} |
70 | 70 |
71 ~PrototypeIterator() {} | 71 ~PrototypeIterator() {} |
72 | 72 |
73 bool HasAccess() const { | 73 bool HasAccess() const { |
74 // We can only perform access check in the handlified version of the | 74 // We can only perform access check in the handlified version of the |
75 // PrototypeIterator. | 75 // PrototypeIterator. |
76 DCHECK(!handle_.is_null()); | 76 DCHECK(!handle_.is_null()); |
77 if (handle_->IsAccessCheckNeeded()) { | 77 if (handle_->IsAccessCheckNeeded()) { |
78 return isolate_->MayAccess(handle(isolate_->context()), | 78 return isolate_->MayAccess(handle(isolate_->context()), |
79 Handle<JSObject>::cast(handle_)); | 79 Handle<JSObject>::cast(handle_)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); | 170 DISALLOW_COPY_AND_ASSIGN(PrototypeIterator); |
171 }; | 171 }; |
172 | 172 |
173 | 173 |
174 } // namespace internal | 174 } // namespace internal |
175 | 175 |
176 } // namespace v8 | 176 } // namespace v8 |
177 | 177 |
178 #endif // V8_PROTOTYPE_H_ | 178 #endif // V8_PROTOTYPE_H_ |
OLD | NEW |