OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 virtual bool HasElement(Object* receiver, | 53 virtual bool HasElement(Object* receiver, |
54 JSObject* holder, | 54 JSObject* holder, |
55 uint32_t key, | 55 uint32_t key, |
56 FixedArrayBase* backing_store = NULL) = 0; | 56 FixedArrayBase* backing_store = NULL) = 0; |
57 | 57 |
58 // Returns the element with the specified key or undefined if there is no such | 58 // Returns the element with the specified key or undefined if there is no such |
59 // element. This method doesn't iterate up the prototype chain. The caller | 59 // element. This method doesn't iterate up the prototype chain. The caller |
60 // can optionally pass in the backing store to use for the check, which must | 60 // can optionally pass in the backing store to use for the check, which must |
61 // be compatible with the ElementsKind of the ElementsAccessor. If | 61 // be compatible with the ElementsKind of the ElementsAccessor. If |
62 // backing_store is NULL, the holder->elements() is used as the backing store. | 62 // backing_store is NULL, the holder->elements() is used as the backing store. |
63 virtual MaybeObject* Get(Object* receiver, | 63 MUST_USE_RESULT virtual MaybeObject* Get( |
64 JSObject* holder, | 64 Object* receiver, |
65 uint32_t key, | 65 JSObject* holder, |
66 FixedArrayBase* backing_store = NULL) = 0; | 66 uint32_t key, |
| 67 FixedArrayBase* backing_store = NULL) = 0; |
67 | 68 |
68 // Modifies the length data property as specified for JSArrays and resizes the | 69 // Modifies the length data property as specified for JSArrays and resizes the |
69 // underlying backing store accordingly. The method honors the semantics of | 70 // underlying backing store accordingly. The method honors the semantics of |
70 // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that | 71 // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that |
71 // have non-deletable elements can only be shrunk to the size of highest | 72 // have non-deletable elements can only be shrunk to the size of highest |
72 // element that is non-deletable. | 73 // element that is non-deletable. |
73 virtual MaybeObject* SetLength(JSArray* holder, | 74 MUST_USE_RESULT virtual MaybeObject* SetLength(JSArray* holder, |
74 Object* new_length) = 0; | 75 Object* new_length) = 0; |
75 | 76 |
76 // Modifies both the length and capacity of a JSArray, resizing the underlying | 77 // Modifies both the length and capacity of a JSArray, resizing the underlying |
77 // backing store as necessary. This method does NOT honor the semantics of | 78 // backing store as necessary. This method does NOT honor the semantics of |
78 // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable | 79 // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable |
79 // elements. This method should only be called for array expansion OR by | 80 // elements. This method should only be called for array expansion OR by |
80 // runtime JavaScript code that use InternalArrays and don't care about | 81 // runtime JavaScript code that use InternalArrays and don't care about |
81 // EcmaScript 5.1 semantics. | 82 // EcmaScript 5.1 semantics. |
82 virtual MaybeObject* SetCapacityAndLength(JSArray* array, | 83 MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array, |
83 int capacity, | 84 int capacity, |
84 int length) = 0; | 85 int length) = 0; |
85 | 86 |
86 // Deletes an element in an object, returning a new elements backing store. | 87 // Deletes an element in an object, returning a new elements backing store. |
87 virtual MaybeObject* Delete(JSObject* holder, | 88 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* holder, |
88 uint32_t key, | 89 uint32_t key, |
89 JSReceiver::DeleteMode mode) = 0; | 90 JSReceiver::DeleteMode mode) = 0; |
90 | 91 |
91 // If kCopyToEnd is specified as the copy_size to CopyElements, it copies all | 92 // If kCopyToEnd is specified as the copy_size to CopyElements, it copies all |
92 // of elements from source after source_start to the destination array. | 93 // of elements from source after source_start to the destination array. |
93 static const int kCopyToEnd = -1; | 94 static const int kCopyToEnd = -1; |
94 // If kCopyToEndAndInitializeToHole is specified as the copy_size to | 95 // If kCopyToEndAndInitializeToHole is specified as the copy_size to |
95 // CopyElements, it copies all of elements from source after source_start to | 96 // CopyElements, it copies all of elements from source after source_start to |
96 // destination array, padding any remaining uninitialized elements in the | 97 // destination array, padding any remaining uninitialized elements in the |
97 // destination array with the hole. | 98 // destination array with the hole. |
98 static const int kCopyToEndAndInitializeToHole = -2; | 99 static const int kCopyToEndAndInitializeToHole = -2; |
99 | 100 |
100 // Copy elements from one backing store to another. Typically, callers specify | 101 // Copy elements from one backing store to another. Typically, callers specify |
101 // the source JSObject or JSArray in source_holder. If the holder's backing | 102 // the source JSObject or JSArray in source_holder. If the holder's backing |
102 // store is available, it can be passed in source and source_holder is | 103 // store is available, it can be passed in source and source_holder is |
103 // ignored. | 104 // ignored. |
104 virtual MaybeObject* CopyElements(JSObject* source_holder, | 105 MUST_USE_RESULT virtual MaybeObject* CopyElements( |
105 uint32_t source_start, | 106 JSObject* source_holder, |
106 FixedArrayBase* destination, | 107 uint32_t source_start, |
107 ElementsKind destination_kind, | 108 FixedArrayBase* destination, |
108 uint32_t destination_start, | 109 ElementsKind destination_kind, |
109 int copy_size, | 110 uint32_t destination_start, |
110 FixedArrayBase* source = NULL) = 0; | 111 int copy_size, |
| 112 FixedArrayBase* source = NULL) = 0; |
111 | 113 |
112 MaybeObject* CopyElements(JSObject* from_holder, | 114 MUST_USE_RESULT MaybeObject* CopyElements(JSObject* from_holder, |
113 FixedArrayBase* to, | 115 FixedArrayBase* to, |
114 ElementsKind to_kind, | 116 ElementsKind to_kind, |
115 FixedArrayBase* from = NULL) { | 117 FixedArrayBase* from = NULL) { |
116 return CopyElements(from_holder, 0, to, to_kind, 0, | 118 return CopyElements(from_holder, 0, to, to_kind, 0, |
117 kCopyToEndAndInitializeToHole, from); | 119 kCopyToEndAndInitializeToHole, from); |
118 } | 120 } |
119 | 121 |
120 virtual MaybeObject* AddElementsToFixedArray(Object* receiver, | 122 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( |
121 JSObject* holder, | 123 Object* receiver, |
122 FixedArray* to, | 124 JSObject* holder, |
123 FixedArrayBase* from = NULL) = 0; | 125 FixedArray* to, |
| 126 FixedArrayBase* from = NULL) = 0; |
124 | 127 |
125 // Returns a shared ElementsAccessor for the specified ElementsKind. | 128 // Returns a shared ElementsAccessor for the specified ElementsKind. |
126 static ElementsAccessor* ForKind(ElementsKind elements_kind) { | 129 static ElementsAccessor* ForKind(ElementsKind elements_kind) { |
127 ASSERT(elements_kind < kElementsKindCount); | 130 ASSERT(elements_kind < kElementsKindCount); |
128 return elements_accessors_[elements_kind]; | 131 return elements_accessors_[elements_kind]; |
129 } | 132 } |
130 | 133 |
131 static ElementsAccessor* ForArray(FixedArrayBase* array); | 134 static ElementsAccessor* ForArray(FixedArrayBase* array); |
132 | 135 |
133 static void InitializeOncePerProcess(); | 136 static void InitializeOncePerProcess(); |
(...skipping 28 matching lines...) Expand all Loading... |
162 uint32_t from_start, | 165 uint32_t from_start, |
163 FixedArray* to_obj, | 166 FixedArray* to_obj, |
164 ElementsKind to_kind, | 167 ElementsKind to_kind, |
165 uint32_t to_start, | 168 uint32_t to_start, |
166 int copy_size); | 169 int copy_size); |
167 | 170 |
168 | 171 |
169 } } // namespace v8::internal | 172 } } // namespace v8::internal |
170 | 173 |
171 #endif // V8_ELEMENTS_H_ | 174 #endif // V8_ELEMENTS_H_ |
OLD | NEW |