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