Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: src/elements.h

Issue 1159433003: Use GetProperty for getting elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/js-typed-lowering.cc ('k') | src/elements.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 30 matching lines...) Expand all
41 Handle<JSObject> holder, 41 Handle<JSObject> holder,
42 uint32_t key) { 42 uint32_t key) {
43 return HasElement(holder, key, handle(holder->elements())); 43 return HasElement(holder, key, handle(holder->elements()));
44 } 44 }
45 45
46 // 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
47 // 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
48 // 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
49 // be compatible with the ElementsKind of the ElementsAccessor. If 49 // be compatible with the ElementsKind of the ElementsAccessor. If
50 // 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.
51 MUST_USE_RESULT virtual MaybeHandle<Object> Get( 51 virtual Handle<Object> Get(Handle<JSObject> holder, uint32_t key,
52 Handle<Object> receiver, 52 Handle<FixedArrayBase> backing_store) = 0;
53 Handle<JSObject> holder,
54 uint32_t key,
55 Handle<FixedArrayBase> backing_store) = 0;
56 53
57 MUST_USE_RESULT inline MaybeHandle<Object> Get( 54 inline Handle<Object> Get(Handle<JSObject> holder, uint32_t key) {
58 Handle<Object> receiver, 55 return Get(holder, key, handle(holder->elements()));
59 Handle<JSObject> holder,
60 uint32_t key) {
61 return Get(receiver, holder, key, handle(holder->elements()));
62 } 56 }
63 57
64 // Returns an element's attributes, or ABSENT if there is no such 58 // 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 59 // 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 60 // can optionally pass in the backing store to use for the check, which must
67 // be compatible with the ElementsKind of the ElementsAccessor. If 61 // be compatible with the ElementsKind of the ElementsAccessor. If
68 // 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.
69 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( 63 virtual PropertyAttributes GetAttributes(JSObject* holder, uint32_t key,
70 Handle<JSObject> holder, 64 FixedArrayBase* backing_store) = 0;
71 uint32_t key,
72 Handle<FixedArrayBase> backing_store) = 0;
73 65
74 MUST_USE_RESULT inline PropertyAttributes GetAttributes( 66 inline PropertyAttributes GetAttributes(Handle<JSObject> holder,
75 Handle<JSObject> holder, 67 uint32_t key) {
76 uint32_t key) { 68 return GetAttributes(*holder, key, holder->elements());
77 return GetAttributes(holder, key, handle(holder->elements()));
78 } 69 }
79 70
80 // Returns an element's accessors, or NULL if the element does not exist or 71 // 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 72 // 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 73 // can optionally pass in the backing store to use for the check, which must
83 // be compatible with the ElementsKind of the ElementsAccessor. If 74 // be compatible with the ElementsKind of the ElementsAccessor. If
84 // backing_store is NULL, the holder->elements() is used as the backing store. 75 // backing_store is NULL, the holder->elements() is used as the backing store.
85 MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair( 76 virtual MaybeHandle<AccessorPair> GetAccessorPair(
86 Handle<JSObject> holder, 77 Handle<JSObject> holder, uint32_t key,
87 uint32_t key,
88 Handle<FixedArrayBase> backing_store) = 0; 78 Handle<FixedArrayBase> backing_store) = 0;
89 79
90 MUST_USE_RESULT inline MaybeHandle<AccessorPair> GetAccessorPair( 80 inline MaybeHandle<AccessorPair> GetAccessorPair(Handle<JSObject> holder,
91 Handle<JSObject> holder, 81 uint32_t key) {
92 uint32_t key) {
93 return GetAccessorPair(holder, key, handle(holder->elements())); 82 return GetAccessorPair(holder, key, handle(holder->elements()));
94 } 83 }
95 84
96 // Modifies the length data property as specified for JSArrays and resizes the 85 // Modifies the length data property as specified for JSArrays and resizes the
97 // underlying backing store accordingly. The method honors the semantics of 86 // underlying backing store accordingly. The method honors the semantics of
98 // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that 87 // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that
99 // have non-deletable elements can only be shrunk to the size of highest 88 // have non-deletable elements can only be shrunk to the size of highest
100 // element that is non-deletable. 89 // element that is non-deletable.
101 MUST_USE_RESULT virtual MaybeHandle<Object> SetLength( 90 MUST_USE_RESULT virtual MaybeHandle<Object> SetLength(
102 Handle<JSArray> holder, 91 Handle<JSArray> holder,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int copy_size) = 0; 140 int copy_size) = 0;
152 141
153 inline void CopyElements( 142 inline void CopyElements(
154 Handle<JSObject> from_holder, 143 Handle<JSObject> from_holder,
155 Handle<FixedArrayBase> to, 144 Handle<FixedArrayBase> to,
156 ElementsKind from_kind) { 145 ElementsKind from_kind) {
157 CopyElements( 146 CopyElements(
158 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole); 147 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole);
159 } 148 }
160 149
161 MUST_USE_RESULT virtual MaybeHandle<FixedArray> AddElementsToFixedArray( 150 virtual Handle<FixedArray> AddElementsToFixedArray(
162 Handle<JSObject> receiver, Handle<FixedArray> to, 151 Handle<JSObject> receiver, Handle<FixedArray> to,
163 FixedArray::KeyFilter filter) = 0; 152 FixedArray::KeyFilter filter) = 0;
164 153
165 // Returns a shared ElementsAccessor for the specified ElementsKind. 154 // Returns a shared ElementsAccessor for the specified ElementsKind.
166 static ElementsAccessor* ForKind(ElementsKind elements_kind) { 155 static ElementsAccessor* ForKind(ElementsKind elements_kind) {
167 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount); 156 DCHECK(static_cast<int>(elements_kind) < kElementsKindCount);
168 return elements_accessors_[elements_kind]; 157 return elements_accessors_[elements_kind];
169 } 158 }
170 159
171 static ElementsAccessor* ForArray(Handle<FixedArrayBase> array); 160 static ElementsAccessor* ForArray(Handle<FixedArrayBase> array);
(...skipping 17 matching lines...) Expand all
189 // specified in JavaScript to access the element. In most implementations, 178 // specified in JavaScript to access the element. In most implementations,
190 // keys are equivalent to indexes, and GetKeyForIndex returns the same value 179 // keys are equivalent to indexes, and GetKeyForIndex returns the same value
191 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps 180 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps
192 // the index to a key using the KeyAt method on the NumberDictionary. 181 // the index to a key using the KeyAt method on the NumberDictionary.
193 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, 182 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store,
194 uint32_t index) = 0; 183 uint32_t index) = 0;
195 virtual uint32_t GetIndexForKey(FixedArrayBase* backing_store, 184 virtual uint32_t GetIndexForKey(FixedArrayBase* backing_store,
196 uint32_t key) = 0; 185 uint32_t key) = 0;
197 virtual PropertyDetails GetDetails(FixedArrayBase* backing_store, 186 virtual PropertyDetails GetDetails(FixedArrayBase* backing_store,
198 uint32_t index) = 0; 187 uint32_t index) = 0;
188 virtual bool HasIndex(FixedArrayBase* backing_store, uint32_t key) = 0;
199 189
200 private: 190 private:
201 static ElementsAccessor** elements_accessors_; 191 static ElementsAccessor** elements_accessors_;
202 const char* name_; 192 const char* name_;
203 193
204 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); 194 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor);
205 }; 195 };
206 196
207 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key, 197 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key,
208 bool allow_appending = false); 198 bool allow_appending = false);
209 199
210 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements( 200 MUST_USE_RESULT MaybeHandle<Object> ArrayConstructInitializeElements(
211 Handle<JSArray> array, 201 Handle<JSArray> array,
212 Arguments* args); 202 Arguments* args);
213 203
214 } } // namespace v8::internal 204 } } // namespace v8::internal
215 205
216 #endif // V8_ELEMENTS_H_ 206 #endif // V8_ELEMENTS_H_
OLDNEW
« no previous file with comments | « src/compiler/js-typed-lowering.cc ('k') | src/elements.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698