Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: src/lookup.h

Issue 314953006: Implement LookupIterator designed to replace LookupResult (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef V8_LOOKUP_H_
6 #define V8_LOOKUP_H_
7
8 #include "src/factory.h"
9 #include "src/isolate.h"
10 #include "src/objects.h"
11
12 namespace v8 {
13 namespace internal {
14
15 class LookupIterator V8_FINAL BASE_EMBEDDED {
16 public:
17 enum Type {
18 CHECK_DERIVED = 1 << 0,
19 CHECK_INTERCEPTOR = 1 << 1,
20 CHECK_ACCESS_CHECK = 1 << 2,
21 CHECK_OWN_REAL = 0,
22 CHECK_ALL = CHECK_DERIVED | CHECK_INTERCEPTOR | CHECK_ACCESS_CHECK,
23 SKIP_INTERCEPTOR = CHECK_ALL ^ CHECK_INTERCEPTOR
24 };
25
26 enum State {
27 NOT_FOUND,
28 PROPERTY,
29 INTERCEPTOR,
30 ACCESS_CHECK,
31 JSPROXY
32 };
33
34 enum PropertyType {
35 DATA,
36 ACCESSORS
37 };
38
39 enum PropertyEncoding {
40 DICTIONARY,
41 DESCRIPTOR
42 };
43
44 LookupIterator(Handle<Object> receiver,
45 Handle<Name> name,
46 Type type = CHECK_ALL)
47 : type_(type),
48 state_(NOT_FOUND),
49 has_property_(false),
50 property_type_(DATA),
51 property_encoding_(DESCRIPTOR),
52 property_details_(NONE, NONEXISTENT, Representation::None()),
53 isolate_(name->GetIsolate()),
54 name_(name),
55 maybe_receiver_(receiver),
56 number_(DescriptorArray::kNotFound) {
57 Handle<JSReceiver> origin = GetOrigin();
58 holder_map_ = handle(origin->map());
59 maybe_holder_ = origin;
60 ContinueLookup();
61 }
62
63 LookupIterator(Handle<Object> receiver,
64 Handle<Name> name,
65 Handle<JSReceiver> holder,
66 Type type = CHECK_ALL)
67 : type_(type),
68 state_(NOT_FOUND),
69 has_property_(false),
70 property_type_(DATA),
71 property_encoding_(DESCRIPTOR),
72 property_details_(NONE, NONEXISTENT, Representation::None()),
73 isolate_(name->GetIsolate()),
74 name_(name),
75 holder_map_(holder->map()),
76 maybe_receiver_(receiver),
77 maybe_holder_(holder),
78 number_(DescriptorArray::kNotFound) {
79 ContinueLookup();
80 }
81
82 Isolate* isolate() const { return isolate_; }
83 State state() const { return state_; }
84 Handle<Name> name() const { return name_; }
85
86 bool IsFound() const { return state_ != NOT_FOUND; }
87 void Next();
88
89 Heap* heap() const { return isolate_->heap(); }
90 Factory* factory() const { return isolate_->factory(); }
91 Handle<Object> GetReceiver() const {
92 return Handle<Object>::cast(maybe_receiver_.ToHandleChecked());
93 }
94 Handle<JSObject> GetHolder() const {
95 ASSERT(IsFound() && state_ != JSPROXY);
96 return Handle<JSObject>::cast(maybe_holder_.ToHandleChecked());
97 }
98 Handle<JSReceiver> GetOrigin() const;
99
100 /* ACCESS_CHECK */
101 bool HasAccess(v8::AccessType access_type) const;
102
103 /* PROPERTY */
104 // HasProperty needs to be called before any of the other PROPERTY methods
105 // below can be used. It ensures that we are able to provide a definite
106 // answer, and loads extra information about the property.
107 bool HasProperty();
108 PropertyType property_type() const {
109 ASSERT(has_property_);
110 return property_type_;
111 }
112 PropertyDetails property_details() const {
113 ASSERT(has_property_);
114 return property_details_;
115 }
116 Handle<Object> GetAccessors() const;
117 Handle<Object> GetDataValue() const;
118
119 /* JSPROXY */
120
121 Handle<JSProxy> GetJSProxy() const {
122 return Handle<JSProxy>::cast(maybe_holder_.ToHandleChecked());
123 }
124
125 private:
126 Handle<Map> GetReceiverMap() const;
127
128 MUST_USE_RESULT bool NextHolder();
129 void ContinueLookup();
130 void LookupInHolder();
131 void LookupOwnRealNamedProperty();
132 void FetchDetails();
133 Handle<Object> FetchValue() const;
134
135 bool IsBootstrapping() const;
136
137 // Methods that fetch data from the holder ensure they always have a holder.
138 // This means the receiver needs to be present as opposed to just the receiver
139 // map. Other objects in the prototype chain are transitively guaranteed to be
140 // present via the receiver map.
141 bool is_guaranteed_to_have_holder() const {
142 return !maybe_receiver_.is_null();
143 }
144 bool check_interceptor() const {
145 return !IsBootstrapping() && (type_ & CHECK_INTERCEPTOR) != 0;
146 }
147 bool check_derived() const {
148 return (type_ & CHECK_DERIVED) != 0;
149 }
150 bool check_access_check() const {
151 return (type_ & CHECK_ACCESS_CHECK) != 0;
152 }
153
154 Type type_;
155 State state_;
156 bool has_property_;
157 PropertyType property_type_;
158 PropertyEncoding property_encoding_;
159 PropertyDetails property_details_;
160 Isolate* isolate_;
161 Handle<Name> name_;
162 Handle<Map> holder_map_;
163 MaybeHandle<Object> maybe_receiver_;
164 MaybeHandle<JSReceiver> maybe_holder_;
165
166 int number_;
167 };
168
169
170 } } // namespace v8::internal
171
172 #endif // V8_LOOKUP_H_
OLDNEW
« no previous file with comments | « src/json-stringifier.h ('k') | src/lookup.cc » ('j') | src/lookup.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698