OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_ELEMENTS_H_ | 5 #ifndef V8_ELEMENTS_H_ |
6 #define V8_ELEMENTS_H_ | 6 #define V8_ELEMENTS_H_ |
7 | 7 |
8 #include "src/elements-kind.h" | 8 #include "src/elements-kind.h" |
9 #include "src/heap/heap.h" | 9 #include "src/heap/heap.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 // Checks the elements of an object for consistency, asserting when a problem | 26 // Checks the elements of an object for consistency, asserting when a problem |
27 // is found. | 27 // is found. |
28 virtual void Validate(Handle<JSObject> obj) = 0; | 28 virtual void Validate(Handle<JSObject> obj) = 0; |
29 | 29 |
30 // Returns true if a holder contains an element with the specified key | 30 // Returns true if a holder contains an element with the specified key |
31 // without iterating up the prototype chain. The caller can optionally pass | 31 // without iterating up the prototype chain. The caller can optionally pass |
32 // in the backing store to use for the check, which must be compatible with | 32 // in the backing store to use for the check, which must be compatible with |
33 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the | 33 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the |
34 // holder->elements() is used as the backing store. | 34 // holder->elements() is used as the backing store. |
35 virtual bool HasElement( | 35 virtual bool HasElement(JSObject* holder, uint32_t key, |
36 Handle<JSObject> holder, | 36 FixedArrayBase* backing_store) = 0; |
37 uint32_t key, | |
38 Handle<FixedArrayBase> backing_store) = 0; | |
39 | 37 |
40 inline bool HasElement( | 38 inline bool HasElement(JSObject* holder, uint32_t key) { |
41 Handle<JSObject> holder, | 39 return HasElement(holder, key, holder->elements()); |
42 uint32_t key) { | |
43 return HasElement(holder, key, handle(holder->elements())); | |
44 } | 40 } |
45 | 41 |
46 // Returns the element with the specified key or undefined if there is no such | 42 // Returns the element with the specified key or undefined if there is no such |
47 // element. This method doesn't iterate up the prototype chain. The caller | 43 // element. This method doesn't iterate up the prototype chain. The caller |
48 // can optionally pass in the backing store to use for the check, which must | 44 // can optionally pass in the backing store to use for the check, which must |
49 // be compatible with the ElementsKind of the ElementsAccessor. If | 45 // be compatible with the ElementsKind of the ElementsAccessor. If |
50 // backing_store is NULL, the holder->elements() is used as the backing store. | 46 // backing_store is NULL, the holder->elements() is used as the backing store. |
51 MUST_USE_RESULT virtual MaybeHandle<Object> Get( | 47 MUST_USE_RESULT virtual MaybeHandle<Object> Get( |
52 Handle<Object> receiver, | 48 Handle<Object> receiver, |
53 Handle<JSObject> holder, | 49 Handle<JSObject> holder, |
54 uint32_t key, | 50 uint32_t key, |
55 Handle<FixedArrayBase> backing_store) = 0; | 51 Handle<FixedArrayBase> backing_store) = 0; |
56 | 52 |
57 MUST_USE_RESULT inline MaybeHandle<Object> Get( | 53 MUST_USE_RESULT inline MaybeHandle<Object> Get( |
58 Handle<Object> receiver, | 54 Handle<Object> receiver, |
59 Handle<JSObject> holder, | 55 Handle<JSObject> holder, |
60 uint32_t key) { | 56 uint32_t key) { |
61 return Get(receiver, holder, key, handle(holder->elements())); | 57 return Get(receiver, holder, key, handle(holder->elements())); |
62 } | 58 } |
63 | 59 |
64 // Returns an element's attributes, or ABSENT if there is no such | 60 // Returns an element's attributes, or ABSENT if there is no such |
65 // element. This method doesn't iterate up the prototype chain. The caller | 61 // element. This method doesn't iterate up the prototype chain. The caller |
66 // can optionally pass in the backing store to use for the check, which must | 62 // can optionally pass in the backing store to use for the check, which must |
67 // be compatible with the ElementsKind of the ElementsAccessor. If | 63 // be compatible with the ElementsKind of the ElementsAccessor. If |
68 // backing_store is NULL, the holder->elements() is used as the backing store. | 64 // backing_store is NULL, the holder->elements() is used as the backing store. |
69 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( | 65 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( |
70 Handle<JSObject> holder, | 66 JSObject* holder, uint32_t key, FixedArrayBase* backing_store) = 0; |
71 uint32_t key, | |
72 Handle<FixedArrayBase> backing_store) = 0; | |
73 | 67 |
74 MUST_USE_RESULT inline PropertyAttributes GetAttributes( | 68 MUST_USE_RESULT inline PropertyAttributes GetAttributes(JSObject* holder, |
75 Handle<JSObject> holder, | 69 uint32_t key) { |
76 uint32_t key) { | 70 return GetAttributes(holder, key, holder->elements()); |
77 return GetAttributes(holder, key, handle(holder->elements())); | |
78 } | 71 } |
79 | 72 |
80 // Returns an element's accessors, or NULL if the element does not exist or | 73 // Returns an element's accessors, or NULL if the element does not exist or |
81 // is plain. This method doesn't iterate up the prototype chain. The caller | 74 // is plain. This method doesn't iterate up the prototype chain. The caller |
82 // can optionally pass in the backing store to use for the check, which must | 75 // can optionally pass in the backing store to use for the check, which must |
83 // be compatible with the ElementsKind of the ElementsAccessor. If | 76 // be compatible with the ElementsKind of the ElementsAccessor. If |
84 // backing_store is NULL, the holder->elements() is used as the backing store. | 77 // backing_store is NULL, the holder->elements() is used as the backing store. |
85 MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair( | 78 MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair( |
86 Handle<JSObject> holder, | 79 Handle<JSObject> holder, |
87 uint32_t key, | 80 uint32_t key, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return AddElementsToFixedArray(receiver, holder, to, | 161 return AddElementsToFixedArray(receiver, holder, to, |
169 handle(holder->elements()), filter); | 162 handle(holder->elements()), filter); |
170 } | 163 } |
171 | 164 |
172 // Returns a shared ElementsAccessor for the specified ElementsKind. | 165 // Returns a shared ElementsAccessor for the specified ElementsKind. |
173 static ElementsAccessor* ForKind(ElementsKind elements_kind) { | 166 static ElementsAccessor* ForKind(ElementsKind elements_kind) { |
174 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount); | 167 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount); |
175 return elements_accessors_[elements_kind]; | 168 return elements_accessors_[elements_kind]; |
176 } | 169 } |
177 | 170 |
178 static ElementsAccessor* ForArray(Handle<FixedArrayBase> array); | 171 static ElementsAccessor* ForArray(FixedArrayBase* array); |
179 | 172 |
180 static void InitializeOncePerProcess(); | 173 static void InitializeOncePerProcess(); |
181 static void TearDown(); | 174 static void TearDown(); |
182 | 175 |
183 protected: | 176 protected: |
184 friend class SloppyArgumentsElementsAccessor; | 177 friend class SloppyArgumentsElementsAccessor; |
185 | 178 |
186 virtual uint32_t GetCapacity(Handle<FixedArrayBase> backing_store) = 0; | 179 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) = 0; |
187 | 180 |
188 // Element handlers distinguish between indexes and keys when they manipulate | 181 // Element handlers distinguish between indexes and keys when they manipulate |
189 // elements. Indexes refer to elements in terms of their location in the | 182 // elements. Indexes refer to elements in terms of their location in the |
190 // underlying storage's backing store representation, and are between 0 and | 183 // underlying storage's backing store representation, and are between 0 and |
191 // GetCapacity. Keys refer to elements in terms of the value that would be | 184 // GetCapacity. Keys refer to elements in terms of the value that would be |
192 // specified in JavaScript to access the element. In most implementations, | 185 // specified in JavaScript to access the element. In most implementations, |
193 // keys are equivalent to indexes, and GetKeyForIndex returns the same value | 186 // keys are equivalent to indexes, and GetKeyForIndex returns the same value |
194 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps | 187 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps |
195 // the index to a key using the KeyAt method on the NumberDictionary. | 188 // the index to a key using the KeyAt method on the NumberDictionary. |
196 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store, | 189 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store, |
197 uint32_t index) = 0; | 190 uint32_t index) = 0; |
198 | 191 |
199 private: | 192 private: |
200 static ElementsAccessor** elements_accessors_; | 193 static ElementsAccessor** elements_accessors_; |
201 const char* name_; | 194 const char* name_; |
202 | 195 |
203 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); | 196 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); |
204 }; | 197 }; |
205 | 198 |
206 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key, | 199 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key, |
207 bool allow_appending = false); | 200 bool allow_appending = false); |
208 | 201 |
209 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements( | 202 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements( |
210 Handle<JSArray> array, | 203 Handle<JSArray> array, |
211 Arguments* args); | 204 Arguments* args); |
212 | 205 |
213 } } // namespace v8::internal | 206 } } // namespace v8::internal |
214 | 207 |
215 #endif // V8_ELEMENTS_H_ | 208 #endif // V8_ELEMENTS_H_ |
OLD | NEW |