v8  3.14.5(node0.10.28)
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.
68  MUST_USE_RESULT virtual MaybeObject* Get(
69  Object* receiver,
70  JSObject* holder,
71  uint32_t key,
72  FixedArrayBase* backing_store = NULL) = 0;
73 
74  // Modifies the length data property as specified for JSArrays and resizes the
75  // underlying backing store accordingly. The method honors the semantics of
76  // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that
77  // have non-deletable elements can only be shrunk to the size of highest
78  // element that is non-deletable.
79  MUST_USE_RESULT virtual MaybeObject* SetLength(JSArray* holder,
80  Object* new_length) = 0;
81 
82  // Modifies both the length and capacity of a JSArray, resizing the underlying
83  // backing store as necessary. This method does NOT honor the semantics of
84  // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable
85  // elements. This method should only be called for array expansion OR by
86  // runtime JavaScript code that use InternalArrays and don't care about
87  // EcmaScript 5.1 semantics.
88  MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array,
89  int capacity,
90  int length) = 0;
91 
92  // Deletes an element in an object, returning a new elements backing store.
93  MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* holder,
94  uint32_t key,
95  JSReceiver::DeleteMode mode) = 0;
96 
97  // If kCopyToEnd is specified as the copy_size to CopyElements, it copies all
98  // of elements from source after source_start to the destination array.
99  static const int kCopyToEnd = -1;
100  // If kCopyToEndAndInitializeToHole is specified as the copy_size to
101  // CopyElements, it copies all of elements from source after source_start to
102  // destination array, padding any remaining uninitialized elements in the
103  // destination array with the hole.
104  static const int kCopyToEndAndInitializeToHole = -2;
105 
106  // Copy elements from one backing store to another. Typically, callers specify
107  // the source JSObject or JSArray in source_holder. If the holder's backing
108  // store is available, it can be passed in source and source_holder is
109  // ignored.
110  MUST_USE_RESULT virtual MaybeObject* CopyElements(
111  JSObject* source_holder,
112  uint32_t source_start,
113  FixedArrayBase* destination,
114  ElementsKind destination_kind,
115  uint32_t destination_start,
116  int copy_size,
117  FixedArrayBase* source = NULL) = 0;
118 
119  MUST_USE_RESULT MaybeObject* CopyElements(JSObject* from_holder,
120  FixedArrayBase* to,
121  ElementsKind to_kind,
122  FixedArrayBase* from = NULL) {
123  return CopyElements(from_holder, 0, to, to_kind, 0,
125  }
126 
127  MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray(
128  Object* receiver,
129  JSObject* holder,
130  FixedArray* to,
131  FixedArrayBase* from = NULL) = 0;
132 
133  // Returns a shared ElementsAccessor for the specified ElementsKind.
134  static ElementsAccessor* ForKind(ElementsKind elements_kind) {
135  ASSERT(elements_kind < kElementsKindCount);
136  return elements_accessors_[elements_kind];
137  }
138 
139  static ElementsAccessor* ForArray(FixedArrayBase* array);
140 
141  static void InitializeOncePerProcess();
142  static void TearDown();
143 
144  protected:
146 
147  virtual uint32_t GetCapacity(FixedArrayBase* backing_store) = 0;
148 
149  // Element handlers distinguish between indexes and keys when they manipulate
150  // elements. Indexes refer to elements in terms of their location in the
151  // underlying storage's backing store representation, and are between 0 and
152  // GetCapacity. Keys refer to elements in terms of the value that would be
153  // specified in JavaScript to access the element. In most implementations,
154  // keys are equivalent to indexes, and GetKeyForIndex returns the same value
155  // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps
156  // the index to a key using the KeyAt method on the NumberDictionary.
157  virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store,
158  uint32_t index) = 0;
159 
160  private:
161  static ElementsAccessor** elements_accessors_;
162  const char* name_;
163 
165 };
166 
167 
169  ElementsKind from_kind,
170  uint32_t from_start,
171  FixedArray* to_obj,
172  ElementsKind to_kind,
173  uint32_t to_start,
174  int copy_size);
175 
176 
177 } } // namespace v8::internal
178 
179 #endif // V8_ELEMENTS_H_
virtual MUST_USE_RESULT MaybeObject * Delete(JSObject *holder, uint32_t key, JSReceiver::DeleteMode mode)=0
virtual MUST_USE_RESULT MaybeObject * SetCapacityAndLength(JSArray *array, int capacity, int length)=0
virtual ElementsKind kind() const =0
virtual MUST_USE_RESULT MaybeObject * CopyElements(JSObject *source_holder, uint32_t source_start, FixedArrayBase *destination, ElementsKind destination_kind, uint32_t destination_start, int copy_size, FixedArrayBase *source=NULL)=0
#define ASSERT(condition)
Definition: checks.h:270
static const int kCopyToEnd
Definition: elements.h:99
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:346
ElementsAccessor(const char *name)
Definition: elements.h:43
static void InitializeOncePerProcess()
Definition: elements.cc:1606
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:307
static ElementsAccessor * ForArray(FixedArrayBase *array)
Definition: elements.cc:1573
virtual MUST_USE_RESULT MaybeObject * Get(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
virtual bool HasElement(Object *receiver, JSObject *holder, uint32_t key, FixedArrayBase *backing_store=NULL)=0
virtual uint32_t GetKeyForIndex(FixedArrayBase *backing_store, uint32_t index)=0
static ElementsAccessor * ForKind(ElementsKind elements_kind)
Definition: elements.h:134
const int kElementsKindCount
Definition: elements-kind.h:76
void CopyObjectToObjectElements(FixedArray *from, ElementsKind from_kind, uint32_t from_start, FixedArray *to, ElementsKind to_kind, uint32_t to_start, int raw_copy_size)
Definition: elements.cc:149
static const int kCopyToEndAndInitializeToHole
Definition: elements.h:104
MUST_USE_RESULT MaybeObject * CopyElements(JSObject *from_holder, FixedArrayBase *to, ElementsKind to_kind, FixedArrayBase *from=NULL)
Definition: elements.h:119
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit 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 SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available 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 MIPS FPU instructions if NULL
Definition: flags.cc:301
virtual uint32_t GetCapacity(FixedArrayBase *backing_store)=0
virtual MUST_USE_RESULT MaybeObject * SetLength(JSArray *holder, Object *new_length)=0
const char * name() const
Definition: elements.h:47