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

Side by Side Diff: src/elements.h

Issue 225623004: Callers of ElementsAccessor::AddElementsToFixedArray(), ElementsAccessor::HasElement() and Elements… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: HasElement() polishing Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/builtins.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 // 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Checks the elements of an object for consistency, asserting when a problem 49 // Checks the elements of an object for consistency, asserting when a problem
50 // is found. 50 // is found.
51 virtual void Validate(JSObject* obj) = 0; 51 virtual void Validate(JSObject* obj) = 0;
52 52
53 // Returns true if a holder contains an element with the specified key 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 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 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 56 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the
57 // holder->elements() is used as the backing store. 57 // holder->elements() is used as the backing store.
58 virtual bool HasElement(Object* receiver, 58 virtual bool HasElement(
59 JSObject* holder, 59 Handle<Object> receiver,
60 uint32_t key, 60 Handle<JSObject> holder,
61 FixedArrayBase* backing_store = NULL) = 0; 61 uint32_t key,
62 Handle<FixedArrayBase> backing_store) = 0;
63
64 inline bool HasElement(
65 Handle<Object> receiver,
66 Handle<JSObject> holder,
67 uint32_t key) {
68 return HasElement(receiver, holder, key, handle(holder->elements()));
69 }
62 70
63 // Returns the element with the specified key or undefined if there is no such 71 // 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 72 // 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 73 // can optionally pass in the backing store to use for the check, which must
66 // be compatible with the ElementsKind of the ElementsAccessor. If 74 // be compatible with the ElementsKind of the ElementsAccessor. If
67 // 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.
68 MUST_USE_RESULT virtual Handle<Object> Get( 76 MUST_USE_RESULT virtual Handle<Object> Get(
69 Handle<Object> receiver, 77 Handle<Object> receiver,
70 Handle<JSObject> holder, 78 Handle<JSObject> holder,
71 uint32_t key, 79 uint32_t key,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 int copy_size) = 0; 182 int copy_size) = 0;
175 183
176 inline void CopyElements( 184 inline void CopyElements(
177 Handle<JSObject> from_holder, 185 Handle<JSObject> from_holder,
178 Handle<FixedArrayBase> to, 186 Handle<FixedArrayBase> to,
179 ElementsKind from_kind) { 187 ElementsKind from_kind) {
180 CopyElements( 188 CopyElements(
181 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole); 189 *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole);
182 } 190 }
183 191
184 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( 192 virtual Handle<FixedArray> AddElementsToFixedArray(
185 Object* receiver, 193 Handle<Object> receiver,
186 JSObject* holder, 194 Handle<JSObject> holder,
187 FixedArray* to, 195 Handle<FixedArray> to,
188 FixedArrayBase* from = NULL) = 0; 196 Handle<FixedArrayBase> from) = 0;
197
198 inline Handle<FixedArray> AddElementsToFixedArray(
199 Handle<Object> receiver,
200 Handle<JSObject> holder,
201 Handle<FixedArray> to) {
202 return AddElementsToFixedArray(
203 receiver, holder, to, handle(holder->elements()));
204 }
189 205
190 // Returns a shared ElementsAccessor for the specified ElementsKind. 206 // Returns a shared ElementsAccessor for the specified ElementsKind.
191 static ElementsAccessor* ForKind(ElementsKind elements_kind) { 207 static ElementsAccessor* ForKind(ElementsKind elements_kind) {
192 ASSERT(elements_kind < kElementsKindCount); 208 ASSERT(elements_kind < kElementsKindCount);
193 return elements_accessors_[elements_kind]; 209 return elements_accessors_[elements_kind];
194 } 210 }
195 211
212 // TODO(ishell): Temporary wrapper until handlified.
213 inline static ElementsAccessor* ForArray(Handle<FixedArrayBase> array) {
214 return ForArray(*array);
215 }
196 static ElementsAccessor* ForArray(FixedArrayBase* array); 216 static ElementsAccessor* ForArray(FixedArrayBase* array);
197 217
198 static void InitializeOncePerProcess(); 218 static void InitializeOncePerProcess();
199 static void TearDown(); 219 static void TearDown();
200 220
201 protected: 221 protected:
202 friend class SloppyArgumentsElementsAccessor; 222 friend class SloppyArgumentsElementsAccessor;
203 223
204 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) = 0; 224 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) = 0;
205 225
206 // Element handlers distinguish between indexes and keys when they manipulate 226 // Element handlers distinguish between indexes and keys when they manipulate
207 // elements. Indexes refer to elements in terms of their location in the 227 // elements. Indexes refer to elements in terms of their location in the
208 // underlying storage's backing store representation, and are between 0 and 228 // underlying storage's backing store representation, and are between 0 and
209 // GetCapacity. Keys refer to elements in terms of the value that would be 229 // GetCapacity. Keys refer to elements in terms of the value that would be
210 // specified in JavaScript to access the element. In most implementations, 230 // specified in JavaScript to access the element. In most implementations,
211 // keys are equivalent to indexes, and GetKeyForIndex returns the same value 231 // keys are equivalent to indexes, and GetKeyForIndex returns the same value
212 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps 232 // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps
213 // the index to a key using the KeyAt method on the NumberDictionary. 233 // the index to a key using the KeyAt method on the NumberDictionary.
214 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, 234 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store,
215 uint32_t index) = 0; 235 uint32_t index) = 0;
216 236
217 private: 237 private:
218 static ElementsAccessor** elements_accessors_; 238 static ElementsAccessor** elements_accessors_;
219 const char* name_; 239 const char* name_;
220 240
221 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); 241 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor);
222 }; 242 };
223 243
224 void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key, 244 void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key,
225 bool allow_appending = false); 245 bool allow_appending = false);
226 246
227 Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array, 247 Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
228 Arguments* args); 248 Arguments* args);
229 249
230 } } // namespace v8::internal 250 } } // namespace v8::internal
231 251
232 #endif // V8_ELEMENTS_H_ 252 #endif // V8_ELEMENTS_H_
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | src/elements.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698