v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
elements.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ELEMENTS_H_
29 #define V8_ELEMENTS_H_
30 
31 #include "elements-kind.h"
32 #include "objects.h"
33 #include "heap.h"
34 #include "isolate.h"
35 
36 namespace v8 {
37 namespace internal {
38 
39 // Abstract base class for handles that can operate on objects with differing
40 // ElementsKinds.
42  public:
43  explicit ElementsAccessor(const char* name) : name_(name) { }
44  virtual ~ElementsAccessor() { }
45 
46  virtual ElementsKind kind() const = 0;
47  const char* name() const { return name_; }
48 
49  // Checks the elements of an object for consistency, asserting when a problem
50  // is found.
51  virtual void Validate(JSObject* obj) = 0;
52 
53  // Returns true if a holder contains an element with the specified key
54  // without iterating up the prototype chain. The caller can optionally pass
55  // in the backing store to use for the check, which must be compatible with
56  // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the
57  // holder->elements() is used as the backing store.
58  virtual bool HasElement(Object* receiver,
59  JSObject* holder,
60  uint32_t key,
61  FixedArrayBase* backing_store = NULL) = 0;
62 
63  // Returns the element with the specified key or undefined if there is no such
64  // element. This method doesn't iterate up the prototype chain. The caller
65  // can optionally pass in the backing store to use for the check, which must
66  // be compatible with the ElementsKind of the ElementsAccessor. If
67  // backing_store is NULL, the holder->elements() is used as the backing store.
69  Handle<Object> receiver,
70  Handle<JSObject> holder,
71  uint32_t key,
72  Handle<FixedArrayBase> backing_store =
74 
75  MUST_USE_RESULT virtual MaybeObject* Get(
76  Object* receiver,
77  JSObject* holder,
78  uint32_t key,
79  FixedArrayBase* backing_store = NULL) = 0;
80 
81  // Returns an element's attributes, or ABSENT if there is no such
82  // element. This method doesn't iterate up the prototype chain. The caller
83  // can optionally pass in the backing store to use for the check, which must
84  // be compatible with the ElementsKind of the ElementsAccessor. If
85  // backing_store is NULL, the holder->elements() is used as the backing store.
87  Object* receiver,
88  JSObject* holder,
89  uint32_t key,
90  FixedArrayBase* backing_store = NULL) = 0;
91 
92  // Returns an element's type, or NONEXISTENT if there is no such
93  // element. This method doesn't iterate up the prototype chain. The caller
94  // can optionally pass in the backing store to use for the check, which must
95  // be compatible with the ElementsKind of the ElementsAccessor. If
96  // backing_store is NULL, the holder->elements() is used as the backing store.
98  Object* receiver,
99  JSObject* holder,
100  uint32_t key,
101  FixedArrayBase* backing_store = NULL) = 0;
102 
103  // Returns an element's accessors, or NULL if the element does not exist or
104  // is plain. This method doesn't iterate up the prototype chain. The caller
105  // can optionally pass in the backing store to use for the check, which must
106  // be compatible with the ElementsKind of the ElementsAccessor. If
107  // backing_store is NULL, the holder->elements() is used as the backing store.
109  Object* receiver,
110  JSObject* holder,
111  uint32_t key,
112  FixedArrayBase* backing_store = NULL) = 0;
113 
114  // Modifies the length data property as specified for JSArrays and resizes the
115  // underlying backing store accordingly. The method honors the semantics of
116  // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that
117  // have non-deletable elements can only be shrunk to the size of highest
118  // element that is non-deletable.
120  Handle<JSArray> holder,
121  Handle<Object> new_length) = 0;
122 
123  // Modifies both the length and capacity of a JSArray, resizing the underlying
124  // backing store as necessary. This method does NOT honor the semantics of
125  // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable
126  // elements. This method should only be called for array expansion OR by
127  // runtime JavaScript code that use InternalArrays and don't care about
128  // EcmaScript 5.1 semantics.
129  virtual void SetCapacityAndLength(
130  Handle<JSArray> array,
131  int capacity,
132  int length) = 0;
133 
134  // Deletes an element in an object, returning a new elements backing store.
136  Handle<JSObject> holder,
137  uint32_t key,
139 
140  // If kCopyToEnd is specified as the copy_size to CopyElements, it copies all
141  // of elements from source after source_start to the destination array.
142  static const int kCopyToEnd = -1;
143  // If kCopyToEndAndInitializeToHole is specified as the copy_size to
144  // CopyElements, it copies all of elements from source after source_start to
145  // destination array, padding any remaining uninitialized elements in the
146  // destination array with the hole.
147  static const int kCopyToEndAndInitializeToHole = -2;
148 
149  // Copy elements from one backing store to another. Typically, callers specify
150  // the source JSObject or JSArray in source_holder. If the holder's backing
151  // store is available, it can be passed in source and source_holder is
152  // ignored.
153  virtual void CopyElements(
154  Handle<JSObject> source_holder,
155  uint32_t source_start,
156  ElementsKind source_kind,
157  Handle<FixedArrayBase> destination,
158  uint32_t destination_start,
159  int copy_size,
161 
163  Handle<JSObject> from_holder,
165  ElementsKind from_kind,
167  CopyElements(from_holder, 0, from_kind, to, 0,
169  }
170 
171  MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray(
172  Object* receiver,
173  JSObject* holder,
174  FixedArray* to,
175  FixedArrayBase* from = NULL) = 0;
176 
177  // Returns a shared ElementsAccessor for the specified ElementsKind.
178  static ElementsAccessor* ForKind(ElementsKind elements_kind) {
179  ASSERT(elements_kind < kElementsKindCount);
180  return elements_accessors_[elements_kind];
181  }
182 
183  static ElementsAccessor* ForArray(FixedArrayBase* array);
184 
185  static void InitializeOncePerProcess();
186  static void TearDown();
187 
188  protected:
190 
191  virtual uint32_t GetCapacity(FixedArrayBase* backing_store) = 0;
192 
193  // Element handlers distinguish between indexes and keys when they manipulate
194  // elements. Indexes refer to elements in terms of their location in the
195  // underlying storage's backing store representation, and are between 0 and
196  // GetCapacity. Keys refer to elements in terms of the value that would be
197  // specified in JavaScript to access the element. In most implementations,
198  // keys are equivalent to indexes, and GetKeyForIndex returns the same value
199  // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps
200  // the index to a key using the KeyAt method on the NumberDictionary.
201  virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store,
202  uint32_t index) = 0;
203 
204  private:
205  static ElementsAccessor** elements_accessors_;
206  const char* name_;
207 
209 };
210 
211 void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key,
212  bool allow_appending = false);
213 
215  Arguments* args);
216 
217 } } // namespace v8::internal
218 
219 #endif // V8_ELEMENTS_H_
virtual MUST_USE_RESULT AccessorPair * GetAccessorPair(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
virtual MUST_USE_RESULT PropertyAttributes GetAttributes(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
virtual MUST_USE_RESULT Handle< Object > Get(Handle< Object > receiver, Handle< JSObject > holder, uint32_t key, Handle< FixedArrayBase > backing_store=Handle< FixedArrayBase >::null())=0
virtual ElementsKind kind() const =0
void CheckArrayAbuse(JSObject *obj, const char *op, uint32_t key, bool allow_appending)
Definition: elements.cc:520
Handle< Object > ArrayConstructInitializeElements(Handle< JSArray > array, Arguments *args)
Definition: elements.cc:1950
#define ASSERT(condition)
Definition: checks.h:329
virtual MUST_USE_RESULT Handle< Object > SetLength(Handle< JSArray > holder, Handle< Object > new_length)=0
PropertyAttributes
virtual MUST_USE_RESULT PropertyType GetType(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
static const int kCopyToEnd
Definition: elements.h:142
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV 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 mode(MIPS only)") DEFINE_string(expose_natives_as
virtual MUST_USE_RESULT MaybeObject * AddElementsToFixedArray(Object *receiver, JSObject *holder, FixedArray *to, FixedArrayBase *from=NULL)=0
virtual void Validate(JSObject *obj)=0
#define MUST_USE_RESULT
Definition: globals.h:381
ElementsAccessor(const char *name)
Definition: elements.h:43
static void InitializeOncePerProcess()
Definition: elements.cc:1861
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:359
static ElementsAccessor * ForArray(FixedArrayBase *array)
Definition: elements.cc:1856
virtual bool HasElement(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
void CopyElements(Handle< JSObject > from_holder, Handle< FixedArrayBase > to, ElementsKind from_kind, Handle< FixedArrayBase > from=Handle< FixedArrayBase >::null())
Definition: elements.h:162
virtual uint32_t GetKeyForIndex(FixedArrayBase *backing_store, uint32_t index)=0
static ElementsAccessor * ForKind(ElementsKind elements_kind)
Definition: elements.h:178
const int kElementsKindCount
Definition: elements-kind.h:89
virtual MUST_USE_RESULT Handle< Object > Delete(Handle< JSObject > holder, uint32_t key, JSReceiver::DeleteMode mode)=0
static const int kCopyToEndAndInitializeToHole
Definition: elements.h:147
virtual void SetCapacityAndLength(Handle< JSArray > array, int capacity, int length)=0
virtual void CopyElements(Handle< JSObject > source_holder, uint32_t source_start, ElementsKind source_kind, Handle< FixedArrayBase > destination, uint32_t destination_start, int copy_size, Handle< FixedArrayBase > source=Handle< FixedArrayBase >::null())=0
HeapObject * obj
virtual uint32_t GetCapacity(FixedArrayBase *backing_store)=0
const char * name() const
Definition: elements.h:47