V8 Project
lookup.h
Go to the documentation of this file.
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 FINAL BASE_EMBEDDED {
16  public:
18  // Configuration bits.
19  kHidden = 1 << 0,
20  kInterceptor = 1 << 1,
21  kPrototypeChain = 1 << 2,
22 
23  // Convience combinations of bits.
24  OWN_SKIP_INTERCEPTOR = 0,
25  OWN = kInterceptor,
26  HIDDEN_SKIP_INTERCEPTOR = kHidden,
27  HIDDEN = kHidden | kInterceptor,
28  PROTOTYPE_CHAIN_SKIP_INTERCEPTOR = kHidden | kPrototypeChain,
29  PROTOTYPE_CHAIN = kHidden | kPrototypeChain | kInterceptor
30  };
31 
32  enum State {
40  // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a
41  // PROPERTY lookup.
42  BEFORE_PROPERTY = INTERCEPTOR
43  };
44 
46  Configuration configuration = PROTOTYPE_CHAIN)
47  : configuration_(ComputeConfiguration(configuration, name)),
48  state_(NOT_FOUND),
49  property_details_(NONE, NORMAL, Representation::None()),
50  isolate_(name->GetIsolate()),
51  name_(name),
52  receiver_(receiver),
53  number_(DescriptorArray::kNotFound) {
54  holder_ = GetRoot();
55  holder_map_ = handle(holder_->map(), isolate_);
56  Next();
57  }
58 
60  Handle<JSReceiver> holder,
61  Configuration configuration = PROTOTYPE_CHAIN)
62  : configuration_(ComputeConfiguration(configuration, name)),
63  state_(NOT_FOUND),
64  property_details_(NONE, NORMAL, Representation::None()),
65  isolate_(name->GetIsolate()),
66  name_(name),
67  holder_map_(holder->map(), isolate_),
68  receiver_(receiver),
69  holder_(holder),
70  number_(DescriptorArray::kNotFound) {
71  Next();
72  }
73 
74  Isolate* isolate() const { return isolate_; }
75  State state() const { return state_; }
76  Handle<Name> name() const { return name_; }
77 
78  bool IsFound() const { return state_ != NOT_FOUND; }
79  void Next();
80  void NotFound() {
81  has_property_ = false;
82  state_ = NOT_FOUND;
83  }
84 
85  Factory* factory() const { return isolate_->factory(); }
86  Handle<Object> GetReceiver() const { return receiver_; }
88  bool is_dictionary_holder() const { return holder_map_->is_dictionary_map(); }
90  DCHECK_EQ(TRANSITION, state_);
91  return transition_map_;
92  }
93  template <class T>
94  Handle<T> GetHolder() const {
95  DCHECK(IsFound());
96  return Handle<T>::cast(holder_);
97  }
100 
101  /* ACCESS_CHECK */
102  bool HasAccess(v8::AccessType access_type) const;
103 
104  /* PROPERTY */
107  PropertyAttributes attributes,
108  Object::StoreFromKeyed store_mode);
110  bool cacheable =
111  state_ == TRANSITION && transition_map()->GetBackPointer()->IsMap();
112  if (cacheable) {
113  property_details_ = transition_map_->GetLastDescriptorDetails();
114  has_property_ = true;
115  }
116  return cacheable;
117  }
120  PropertyAttributes attributes);
122  Handle<Object> accessor,
123  PropertyAttributes attributes);
124  PropertyDetails property_details() const {
125  DCHECK(has_property_);
126  return property_details_;
127  }
128  bool IsConfigurable() const { return property_details().IsConfigurable(); }
129  bool IsReadOnly() const { return property_details().IsReadOnly(); }
131  return property_details().representation();
132  }
133  FieldIndex GetFieldIndex() const;
135  int GetConstantIndex() const;
140 
142 
143  private:
145 
147  inline State LookupInHolder(Map* map, JSReceiver* holder);
150 
151  bool IsBootstrapping() const;
152 
153  bool check_hidden() const { return (configuration_ & kHidden) != 0; }
154  bool check_interceptor() const {
155  return !IsBootstrapping() && (configuration_ & kInterceptor) != 0;
156  }
157  bool check_prototype_chain() const {
158  return (configuration_ & kPrototypeChain) != 0;
159  }
160  int descriptor_number() const {
161  DCHECK(has_property_);
162  DCHECK(!holder_map_->is_dictionary_map());
163  return number_;
164  }
165  int dictionary_entry() const {
166  DCHECK(has_property_);
167  DCHECK(holder_map_->is_dictionary_map());
168  return number_;
169  }
170 
172  Configuration configuration, Handle<Name> name) {
173  if (name->IsOwn()) {
174  return static_cast<Configuration>(configuration & HIDDEN);
175  } else {
176  return configuration;
177  }
178  }
179 
180  // If configuration_ becomes mutable, update
181  // HolderIsReceiverOrHiddenPrototype.
183  State state_;
185  PropertyDetails property_details_;
186  Isolate* isolate_;
190  Handle<Object> receiver_;
192 
193  int number_;
194 };
195 
196 
197 } } // namespace v8::internal
198 
199 #endif // V8_LOOKUP_H_
#define BASE_EMBEDDED
Definition: allocation.h:45
Handle< Object > GetAccessors() const
Isolate * isolate() const
Definition: lookup.h:74
Handle< Map > transition_map_
Definition: lookup.h:189
Handle< Object > GetDataValue() const
bool IsReadOnly() const
Definition: lookup.h:129
int descriptor_number() const
Definition: lookup.h:160
Handle< T > GetHolder() const
Definition: lookup.h:94
FieldIndex GetFieldIndex() const
MUST_USE_RESULT JSReceiver * NextHolder(Map *map)
Handle< Name > name() const
Definition: lookup.h:76
static Configuration ComputeConfiguration(Configuration configuration, Handle< Name > name)
Definition: lookup.h:171
Handle< Object > FetchValue() const
Handle< Map > holder_map_
Definition: lookup.h:188
bool check_hidden() const
Definition: lookup.h:153
void ReconfigureDataProperty(Handle< Object > value, PropertyAttributes attributes)
bool IsFound() const
Definition: lookup.h:78
int dictionary_entry() const
Definition: lookup.h:165
Factory * factory() const
Definition: lookup.h:85
Configuration configuration_
Definition: lookup.h:182
void WriteDataValue(Handle< Object > value)
void PrepareForDataProperty(Handle< Object > value)
Handle< JSReceiver > GetRoot() const
bool is_dictionary_holder() const
Definition: lookup.h:88
Handle< Object > GetReceiver() const
Definition: lookup.h:86
Handle< Map > GetReceiverMap() const
void TransitionToAccessorProperty(AccessorComponent component, Handle< Object > accessor, PropertyAttributes attributes)
LookupIterator(Handle< Object > receiver, Handle< Name > name, Configuration configuration=PROTOTYPE_CHAIN)
Definition: lookup.h:45
Handle< Name > name_
Definition: lookup.h:187
Handle< JSReceiver > holder_
Definition: lookup.h:191
bool HolderIsReceiverOrHiddenPrototype() const
bool IsConfigurable() const
Definition: lookup.h:128
void PrepareTransitionToDataProperty(Handle< Object > value, PropertyAttributes attributes, Object::StoreFromKeyed store_mode)
bool check_interceptor() const
Definition: lookup.h:154
LookupIterator(Handle< Object > receiver, Handle< Name > name, Handle< JSReceiver > holder, Configuration configuration=PROTOTYPE_CHAIN)
Definition: lookup.h:59
Handle< HeapType > GetFieldType() const
bool HasAccess(v8::AccessType access_type) const
PropertyDetails property_details_
Definition: lookup.h:185
State state() const
Definition: lookup.h:75
bool check_prototype_chain() const
Definition: lookup.h:157
Handle< Map > transition_map() const
Definition: lookup.h:89
Handle< PropertyCell > GetPropertyCell() const
Representation representation() const
Definition: lookup.h:130
State LookupInHolder(Map *map, JSReceiver *holder)
Handle< JSObject > GetStoreTarget() const
PropertyDetails property_details() const
Definition: lookup.h:124
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
#define FINAL
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
#define MUST_USE_RESULT
Definition: macros.h:266
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
@ None
Definition: v8.h:2211
AccessType
Access type specification.
Definition: v8.h:3519
PropertyAttributes
@ NONE