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