| 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_PROPERTY_H_ | 5 #ifndef V8_PROPERTY_H_ |
| 6 #define V8_PROPERTY_H_ | 6 #define V8_PROPERTY_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 | 9 |
| 10 #include "src/factory.h" | 10 #include "src/factory.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 class AccessorConstantDescriptor FINAL : public Descriptor { | 98 class AccessorConstantDescriptor FINAL : public Descriptor { |
| 99 public: | 99 public: |
| 100 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign, | 100 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign, |
| 101 PropertyAttributes attributes) | 101 PropertyAttributes attributes) |
| 102 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT, | 102 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT, |
| 103 Representation::Tagged()) {} | 103 Representation::Tagged()) {} |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 | 106 |
| 107 class LookupResult FINAL BASE_EMBEDDED { | |
| 108 public: | |
| 109 explicit LookupResult(Isolate* isolate) | |
| 110 : isolate_(isolate), | |
| 111 next_(isolate->top_lookup_result()), | |
| 112 lookup_type_(NOT_FOUND), | |
| 113 transition_(NULL), | |
| 114 details_(NONE, DATA, Representation::None()) { | |
| 115 isolate->set_top_lookup_result(this); | |
| 116 } | |
| 117 | |
| 118 ~LookupResult() { | |
| 119 DCHECK(isolate()->top_lookup_result() == this); | |
| 120 isolate()->set_top_lookup_result(next_); | |
| 121 } | |
| 122 | |
| 123 Isolate* isolate() const { return isolate_; } | |
| 124 | |
| 125 void DescriptorResult(PropertyDetails details, int number) { | |
| 126 lookup_type_ = DESCRIPTOR_TYPE; | |
| 127 transition_ = NULL; | |
| 128 details_ = details; | |
| 129 number_ = number; | |
| 130 } | |
| 131 | |
| 132 void TransitionResult(Map* target) { | |
| 133 lookup_type_ = TRANSITION_TYPE; | |
| 134 number_ = target->LastAdded(); | |
| 135 details_ = target->instance_descriptors()->GetDetails(number_); | |
| 136 transition_ = target; | |
| 137 } | |
| 138 | |
| 139 void NotFound() { | |
| 140 lookup_type_ = NOT_FOUND; | |
| 141 details_ = PropertyDetails(NONE, DATA, 0); | |
| 142 transition_ = NULL; | |
| 143 } | |
| 144 | |
| 145 Representation representation() const { | |
| 146 DCHECK(IsFound()); | |
| 147 return details_.representation(); | |
| 148 } | |
| 149 | |
| 150 // Property callbacks does not include transitions to callbacks. | |
| 151 bool IsAccessorConstant() const { | |
| 152 return !IsTransition() && details_.type() == ACCESSOR_CONSTANT; | |
| 153 } | |
| 154 | |
| 155 bool IsReadOnly() const { | |
| 156 DCHECK(IsFound()); | |
| 157 return details_.IsReadOnly(); | |
| 158 } | |
| 159 | |
| 160 bool IsData() const { | |
| 161 return lookup_type_ == DESCRIPTOR_TYPE && details_.type() == DATA; | |
| 162 } | |
| 163 | |
| 164 bool IsDataConstant() const { | |
| 165 return lookup_type_ == DESCRIPTOR_TYPE && details_.type() == DATA_CONSTANT; | |
| 166 } | |
| 167 | |
| 168 bool IsConfigurable() const { return details_.IsConfigurable(); } | |
| 169 bool IsFound() const { return lookup_type_ != NOT_FOUND; } | |
| 170 bool IsTransition() const { return lookup_type_ == TRANSITION_TYPE; } | |
| 171 | |
| 172 // Is the result is a property excluding transitions and the null descriptor? | |
| 173 bool IsProperty() const { | |
| 174 return IsFound() && !IsTransition(); | |
| 175 } | |
| 176 | |
| 177 Map* GetTransitionTarget() const { | |
| 178 DCHECK(IsTransition()); | |
| 179 return transition_; | |
| 180 } | |
| 181 | |
| 182 bool IsTransitionToData() const { | |
| 183 return IsTransition() && details_.type() == DATA; | |
| 184 } | |
| 185 | |
| 186 int GetLocalFieldIndexFromMap(Map* map) const { | |
| 187 return GetFieldIndexFromMap(map) - map->inobject_properties(); | |
| 188 } | |
| 189 | |
| 190 Object* GetConstantFromMap(Map* map) const { | |
| 191 DCHECK(details_.type() == DATA_CONSTANT); | |
| 192 return GetValueFromMap(map); | |
| 193 } | |
| 194 | |
| 195 Object* GetValueFromMap(Map* map) const { | |
| 196 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | |
| 197 lookup_type_ == TRANSITION_TYPE); | |
| 198 DCHECK(number_ < map->NumberOfOwnDescriptors()); | |
| 199 return map->instance_descriptors()->GetValue(number_); | |
| 200 } | |
| 201 | |
| 202 int GetFieldIndexFromMap(Map* map) const { | |
| 203 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | |
| 204 lookup_type_ == TRANSITION_TYPE); | |
| 205 DCHECK(number_ < map->NumberOfOwnDescriptors()); | |
| 206 return map->instance_descriptors()->GetFieldIndex(number_); | |
| 207 } | |
| 208 | |
| 209 HeapType* GetFieldTypeFromMap(Map* map) const { | |
| 210 DCHECK_NE(NOT_FOUND, lookup_type_); | |
| 211 DCHECK(number_ < map->NumberOfOwnDescriptors()); | |
| 212 return map->instance_descriptors()->GetFieldType(number_); | |
| 213 } | |
| 214 | |
| 215 Map* GetFieldOwnerFromMap(Map* map) const { | |
| 216 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | |
| 217 lookup_type_ == TRANSITION_TYPE); | |
| 218 DCHECK(number_ < map->NumberOfOwnDescriptors()); | |
| 219 return map->FindFieldOwner(number_); | |
| 220 } | |
| 221 | |
| 222 void Iterate(ObjectVisitor* visitor); | |
| 223 | |
| 224 private: | |
| 225 Isolate* isolate_; | |
| 226 LookupResult* next_; | |
| 227 | |
| 228 // Where did we find the result; | |
| 229 enum { NOT_FOUND, DESCRIPTOR_TYPE, TRANSITION_TYPE } lookup_type_; | |
| 230 | |
| 231 Map* transition_; | |
| 232 int number_; | |
| 233 PropertyDetails details_; | |
| 234 }; | |
| 235 | |
| 236 | |
| 237 std::ostream& operator<<(std::ostream& os, const LookupResult& r); | |
| 238 } } // namespace v8::internal | 107 } } // namespace v8::internal |
| 239 | 108 |
| 240 #endif // V8_PROPERTY_H_ | 109 #endif // V8_PROPERTY_H_ |
| OLD | NEW |