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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // } | 98 // } |
99 // | 99 // |
100 // This is an example of the Curiously Recurring Template Pattern (see | 100 // This is an example of the Curiously Recurring Template Pattern (see |
101 // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). We use | 101 // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). We use |
102 // CRTP to guarantee aggressive compile time optimizations (i.e. inlining and | 102 // CRTP to guarantee aggressive compile time optimizations (i.e. inlining and |
103 // specialization of SomeElementsAccessor methods). | 103 // specialization of SomeElementsAccessor methods). |
104 template <typename ElementsAccessorSubclass, typename BackingStoreClass> | 104 template <typename ElementsAccessorSubclass, typename BackingStoreClass> |
105 class ElementsAccessorBase : public ElementsAccessor { | 105 class ElementsAccessorBase : public ElementsAccessor { |
106 protected: | 106 protected: |
107 explicit ElementsAccessorBase(const char* name) : ElementsAccessor(name) { } | 107 explicit ElementsAccessorBase(const char* name) : ElementsAccessor(name) { } |
108 virtual MaybeObject* Get(FixedArrayBase* backing_store, | 108 |
109 uint32_t key, | 109 static bool HasElementImpl(Object* receiver, |
110 JSObject* obj, | 110 JSObject* holder, |
111 Object* receiver) { | 111 uint32_t key, |
112 return ElementsAccessorSubclass::GetImpl( | 112 BackingStoreClass* backing_store) { |
113 BackingStoreClass::cast(backing_store), key, obj, receiver); | 113 MaybeObject* element = |
| 114 ElementsAccessorSubclass::GetImpl(receiver, holder, key, backing_store); |
| 115 return !element->IsTheHole(); |
114 } | 116 } |
115 | 117 |
116 static MaybeObject* GetImpl(BackingStoreClass* backing_store, | 118 virtual bool HasElement(Object* receiver, |
| 119 JSObject* holder, |
| 120 uint32_t key, |
| 121 FixedArrayBase* backing_store) { |
| 122 if (backing_store == NULL) { |
| 123 backing_store = holder->elements(); |
| 124 } |
| 125 return ElementsAccessorSubclass::HasElementImpl( |
| 126 receiver, holder, key, BackingStoreClass::cast(backing_store)); |
| 127 } |
| 128 |
| 129 virtual MaybeObject* Get(Object* receiver, |
| 130 JSObject* holder, |
| 131 uint32_t key, |
| 132 FixedArrayBase* backing_store) { |
| 133 if (backing_store == NULL) { |
| 134 backing_store = holder->elements(); |
| 135 } |
| 136 return ElementsAccessorSubclass::GetImpl( |
| 137 receiver, holder, key, BackingStoreClass::cast(backing_store)); |
| 138 } |
| 139 |
| 140 static MaybeObject* GetImpl(Object* receiver, |
| 141 JSObject* obj, |
117 uint32_t key, | 142 uint32_t key, |
118 JSObject* obj, | 143 BackingStoreClass* backing_store) { |
119 Object* receiver) { | |
120 return (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) | 144 return (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) |
121 ? backing_store->get(key) | 145 ? backing_store->get(key) |
122 : backing_store->GetHeap()->the_hole_value(); | 146 : backing_store->GetHeap()->the_hole_value(); |
123 } | 147 } |
124 | 148 |
125 virtual MaybeObject* SetLength(JSObject* obj, | 149 virtual MaybeObject* SetLength(JSArray* array, |
126 Object* length) { | 150 Object* length) { |
127 ASSERT(obj->IsJSArray()); | |
128 return ElementsAccessorSubclass::SetLengthImpl( | 151 return ElementsAccessorSubclass::SetLengthImpl( |
129 BackingStoreClass::cast(obj->elements()), obj, length); | 152 array, length, BackingStoreClass::cast(array->elements())); |
130 } | 153 } |
131 | 154 |
132 static MaybeObject* SetLengthImpl(BackingStoreClass* backing_store, | 155 static MaybeObject* SetLengthImpl(JSObject* obj, |
133 JSObject* obj, | 156 Object* length, |
134 Object* length); | 157 BackingStoreClass* backing_store); |
135 | 158 |
136 virtual MaybeObject* SetCapacityAndLength(JSArray* array, | 159 virtual MaybeObject* SetCapacityAndLength(JSArray* array, |
137 int capacity, | 160 int capacity, |
138 int length) { | 161 int length) { |
139 return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( | 162 return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( |
140 array, | 163 array, |
141 capacity, | 164 capacity, |
142 length); | 165 length); |
143 } | 166 } |
144 | 167 |
145 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | 168 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
146 int capacity, | 169 int capacity, |
147 int length) { | 170 int length) { |
148 UNIMPLEMENTED(); | 171 UNIMPLEMENTED(); |
149 return obj; | 172 return obj; |
150 } | 173 } |
151 | 174 |
152 virtual MaybeObject* Delete(JSObject* obj, | 175 virtual MaybeObject* Delete(JSObject* obj, |
153 uint32_t key, | 176 uint32_t key, |
154 JSReceiver::DeleteMode mode) = 0; | 177 JSReceiver::DeleteMode mode) = 0; |
155 | 178 |
156 virtual MaybeObject* AddElementsToFixedArray(FixedArrayBase* from, | 179 virtual MaybeObject* AddElementsToFixedArray(Object* receiver, |
| 180 JSObject* holder, |
157 FixedArray* to, | 181 FixedArray* to, |
158 JSObject* holder, | 182 FixedArrayBase* from) { |
159 Object* receiver) { | |
160 int len0 = to->length(); | 183 int len0 = to->length(); |
161 #ifdef DEBUG | 184 #ifdef DEBUG |
162 if (FLAG_enable_slow_asserts) { | 185 if (FLAG_enable_slow_asserts) { |
163 for (int i = 0; i < len0; i++) { | 186 for (int i = 0; i < len0; i++) { |
164 ASSERT(!to->get(i)->IsTheHole()); | 187 ASSERT(!to->get(i)->IsTheHole()); |
165 } | 188 } |
166 } | 189 } |
167 #endif | 190 #endif |
| 191 if (from == NULL) { |
| 192 from = holder->elements(); |
| 193 } |
168 BackingStoreClass* backing_store = BackingStoreClass::cast(from); | 194 BackingStoreClass* backing_store = BackingStoreClass::cast(from); |
169 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(backing_store); | 195 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(backing_store); |
170 | 196 |
171 // Optimize if 'other' is empty. | 197 // Optimize if 'other' is empty. |
172 // We cannot optimize if 'this' is empty, as other may have holes. | 198 // We cannot optimize if 'this' is empty, as other may have holes. |
173 if (len1 == 0) return to; | 199 if (len1 == 0) return to; |
174 | 200 |
175 // Compute how many elements are not in other. | 201 // Compute how many elements are not in other. |
176 uint32_t extra = 0; | 202 uint32_t extra = 0; |
177 for (uint32_t y = 0; y < len1; y++) { | 203 for (uint32_t y = 0; y < len1; y++) { |
178 uint32_t key = | 204 uint32_t key = |
179 ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y); | 205 ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y); |
180 if (ElementsAccessorSubclass::HasElementImpl( | 206 if (ElementsAccessorSubclass::HasElementImpl( |
181 backing_store, key, holder, receiver)) { | 207 receiver, holder, key, backing_store)) { |
182 MaybeObject* maybe_value = | 208 MaybeObject* maybe_value = |
183 ElementsAccessorSubclass::GetImpl(backing_store, key, | 209 ElementsAccessorSubclass::GetImpl(receiver, holder, |
184 holder, receiver); | 210 key, backing_store); |
185 Object* value; | 211 Object* value; |
186 if (!maybe_value->ToObject(&value)) return maybe_value; | 212 if (!maybe_value->ToObject(&value)) return maybe_value; |
187 ASSERT(!value->IsTheHole()); | 213 ASSERT(!value->IsTheHole()); |
188 if (!HasKey(to, value)) { | 214 if (!HasKey(to, value)) { |
189 extra++; | 215 extra++; |
190 } | 216 } |
191 } | 217 } |
192 } | 218 } |
193 | 219 |
194 if (extra == 0) return to; | 220 if (extra == 0) return to; |
(...skipping 13 matching lines...) Expand all Loading... |
208 ASSERT(e->IsString() || e->IsNumber()); | 234 ASSERT(e->IsString() || e->IsNumber()); |
209 result->set(i, e, mode); | 235 result->set(i, e, mode); |
210 } | 236 } |
211 } | 237 } |
212 // Fill in the extra values. | 238 // Fill in the extra values. |
213 uint32_t index = 0; | 239 uint32_t index = 0; |
214 for (uint32_t y = 0; y < len1; y++) { | 240 for (uint32_t y = 0; y < len1; y++) { |
215 uint32_t key = | 241 uint32_t key = |
216 ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y); | 242 ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y); |
217 if (ElementsAccessorSubclass::HasElementImpl( | 243 if (ElementsAccessorSubclass::HasElementImpl( |
218 backing_store, key, holder, receiver)) { | 244 receiver, holder, key, backing_store)) { |
219 MaybeObject* maybe_value = | 245 MaybeObject* maybe_value = |
220 ElementsAccessorSubclass::GetImpl(backing_store, key, | 246 ElementsAccessorSubclass::GetImpl(receiver, holder, |
221 holder, receiver); | 247 key, backing_store); |
222 Object* value; | 248 Object* value; |
223 if (!maybe_value->ToObject(&value)) return maybe_value; | 249 if (!maybe_value->ToObject(&value)) return maybe_value; |
224 if (!value->IsTheHole() && !HasKey(to, value)) { | 250 if (!value->IsTheHole() && !HasKey(to, value)) { |
225 result->set(len0 + index, value); | 251 result->set(len0 + index, value); |
226 index++; | 252 index++; |
227 } | 253 } |
228 } | 254 } |
229 } | 255 } |
230 ASSERT(extra == index); | 256 ASSERT(extra == index); |
231 return result; | 257 return result; |
232 } | 258 } |
233 | 259 |
234 protected: | 260 protected: |
235 static uint32_t GetCapacityImpl(BackingStoreClass* backing_store) { | 261 static uint32_t GetCapacityImpl(BackingStoreClass* backing_store) { |
236 return backing_store->length(); | 262 return backing_store->length(); |
237 } | 263 } |
238 | 264 |
239 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) { | 265 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) { |
240 return ElementsAccessorSubclass::GetCapacityImpl( | 266 return ElementsAccessorSubclass::GetCapacityImpl( |
241 BackingStoreClass::cast(backing_store)); | 267 BackingStoreClass::cast(backing_store)); |
242 } | 268 } |
243 | 269 |
244 static bool HasElementImpl(BackingStoreClass* backing_store, | |
245 uint32_t key, | |
246 JSObject* holder, | |
247 Object* receiver) { | |
248 MaybeObject* element = | |
249 ElementsAccessorSubclass::GetImpl(backing_store, key, holder, receiver); | |
250 return !element->IsTheHole(); | |
251 } | |
252 | |
253 virtual bool HasElement(FixedArrayBase* backing_store, | |
254 uint32_t key, | |
255 JSObject* holder, | |
256 Object* receiver) { | |
257 return ElementsAccessorSubclass::HasElementImpl( | |
258 BackingStoreClass::cast(backing_store), key, holder, receiver); | |
259 } | |
260 | |
261 static uint32_t GetKeyForIndexImpl(BackingStoreClass* backing_store, | 270 static uint32_t GetKeyForIndexImpl(BackingStoreClass* backing_store, |
262 uint32_t index) { | 271 uint32_t index) { |
263 return index; | 272 return index; |
264 } | 273 } |
265 | 274 |
266 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, | 275 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, |
267 uint32_t index) { | 276 uint32_t index) { |
268 return ElementsAccessorSubclass::GetKeyForIndexImpl( | 277 return ElementsAccessorSubclass::GetKeyForIndexImpl( |
269 BackingStoreClass::cast(backing_store), index); | 278 BackingStoreClass::cast(backing_store), index); |
270 } | 279 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 JSReceiver::DeleteMode mode) { | 456 JSReceiver::DeleteMode mode) { |
448 int length = obj->IsJSArray() | 457 int length = obj->IsJSArray() |
449 ? Smi::cast(JSArray::cast(obj)->length())->value() | 458 ? Smi::cast(JSArray::cast(obj)->length())->value() |
450 : FixedDoubleArray::cast(obj->elements())->length(); | 459 : FixedDoubleArray::cast(obj->elements())->length(); |
451 if (key < static_cast<uint32_t>(length)) { | 460 if (key < static_cast<uint32_t>(length)) { |
452 FixedDoubleArray::cast(obj->elements())->set_the_hole(key); | 461 FixedDoubleArray::cast(obj->elements())->set_the_hole(key); |
453 } | 462 } |
454 return obj->GetHeap()->true_value(); | 463 return obj->GetHeap()->true_value(); |
455 } | 464 } |
456 | 465 |
457 static bool HasElementImpl(FixedDoubleArray* backing_store, | 466 static bool HasElementImpl(Object* receiver, |
| 467 JSObject* holder, |
458 uint32_t key, | 468 uint32_t key, |
459 JSObject* holder, | 469 FixedDoubleArray* backing_store) { |
460 Object* receiver) { | |
461 return !backing_store->is_the_hole(key); | 470 return !backing_store->is_the_hole(key); |
462 } | 471 } |
463 }; | 472 }; |
464 | 473 |
465 | 474 |
466 // Super class for all external element arrays. | 475 // Super class for all external element arrays. |
467 template<typename ExternalElementsAccessorSubclass, | 476 template<typename ExternalElementsAccessorSubclass, |
468 typename ExternalArray> | 477 typename ExternalArray> |
469 class ExternalElementsAccessor | 478 class ExternalElementsAccessor |
470 : public ElementsAccessorBase<ExternalElementsAccessorSubclass, | 479 : public ElementsAccessorBase<ExternalElementsAccessorSubclass, |
471 ExternalArray> { | 480 ExternalArray> { |
472 public: | 481 public: |
473 explicit ExternalElementsAccessor(const char* name) | 482 explicit ExternalElementsAccessor(const char* name) |
474 : ElementsAccessorBase<ExternalElementsAccessorSubclass, | 483 : ElementsAccessorBase<ExternalElementsAccessorSubclass, |
475 ExternalArray>(name) {} | 484 ExternalArray>(name) {} |
476 | 485 |
477 protected: | 486 protected: |
478 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass, | 487 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass, |
479 ExternalArray>; | 488 ExternalArray>; |
480 | 489 |
481 static MaybeObject* GetImpl(ExternalArray* backing_store, | 490 static MaybeObject* GetImpl(Object* receiver, |
| 491 JSObject* obj, |
482 uint32_t key, | 492 uint32_t key, |
483 JSObject* obj, | 493 ExternalArray* backing_store) { |
484 Object* receiver) { | |
485 return | 494 return |
486 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store) | 495 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store) |
487 ? backing_store->get(key) | 496 ? backing_store->get(key) |
488 : backing_store->GetHeap()->undefined_value(); | 497 : backing_store->GetHeap()->undefined_value(); |
489 } | 498 } |
490 | 499 |
491 static MaybeObject* SetLengthImpl(ExternalArray* backing_store, | 500 static MaybeObject* SetLengthImpl(JSObject* obj, |
492 JSObject* obj, | 501 Object* length, |
493 Object* length) { | 502 ExternalArray* backing_store) { |
494 // External arrays do not support changing their length. | 503 // External arrays do not support changing their length. |
495 UNREACHABLE(); | 504 UNREACHABLE(); |
496 return obj; | 505 return obj; |
497 } | 506 } |
498 | 507 |
499 virtual MaybeObject* Delete(JSObject* obj, | 508 virtual MaybeObject* Delete(JSObject* obj, |
500 uint32_t key, | 509 uint32_t key, |
501 JSReceiver::DeleteMode mode) { | 510 JSReceiver::DeleteMode mode) { |
502 // External arrays always ignore deletes. | 511 // External arrays always ignore deletes. |
503 return obj->GetHeap()->true_value(); | 512 return obj->GetHeap()->true_value(); |
504 } | 513 } |
505 | 514 |
506 static bool HasElementImpl(ExternalArray* backing_store, | 515 static bool HasElementImpl(Object* receiver, |
| 516 JSObject* holder, |
507 uint32_t key, | 517 uint32_t key, |
508 JSObject* holder, | 518 ExternalArray* backing_store) { |
509 Object* receiver) { | |
510 uint32_t capacity = | 519 uint32_t capacity = |
511 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store); | 520 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store); |
512 return key < capacity; | 521 return key < capacity; |
513 } | 522 } |
514 }; | 523 }; |
515 | 524 |
516 | 525 |
517 class ExternalByteElementsAccessor | 526 class ExternalByteElementsAccessor |
518 : public ExternalElementsAccessor<ExternalByteElementsAccessor, | 527 : public ExternalElementsAccessor<ExternalByteElementsAccessor, |
519 ExternalByteArray> { | 528 ExternalByteArray> { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 protected: | 726 protected: |
718 friend class ElementsAccessorBase<DictionaryElementsAccessor, | 727 friend class ElementsAccessorBase<DictionaryElementsAccessor, |
719 SeededNumberDictionary>; | 728 SeededNumberDictionary>; |
720 | 729 |
721 virtual MaybeObject* Delete(JSObject* obj, | 730 virtual MaybeObject* Delete(JSObject* obj, |
722 uint32_t key, | 731 uint32_t key, |
723 JSReceiver::DeleteMode mode) { | 732 JSReceiver::DeleteMode mode) { |
724 return DeleteCommon(obj, key, mode); | 733 return DeleteCommon(obj, key, mode); |
725 } | 734 } |
726 | 735 |
727 static MaybeObject* GetImpl(SeededNumberDictionary* backing_store, | 736 static MaybeObject* GetImpl(Object* receiver, |
| 737 JSObject* obj, |
728 uint32_t key, | 738 uint32_t key, |
729 JSObject* obj, | 739 SeededNumberDictionary* backing_store) { |
730 Object* receiver) { | |
731 int entry = backing_store->FindEntry(key); | 740 int entry = backing_store->FindEntry(key); |
732 if (entry != SeededNumberDictionary::kNotFound) { | 741 if (entry != SeededNumberDictionary::kNotFound) { |
733 Object* element = backing_store->ValueAt(entry); | 742 Object* element = backing_store->ValueAt(entry); |
734 PropertyDetails details = backing_store->DetailsAt(entry); | 743 PropertyDetails details = backing_store->DetailsAt(entry); |
735 if (details.type() == CALLBACKS) { | 744 if (details.type() == CALLBACKS) { |
736 return obj->GetElementWithCallback(receiver, | 745 return obj->GetElementWithCallback(receiver, |
737 element, | 746 element, |
738 key, | 747 key, |
739 obj); | 748 obj); |
740 } else { | 749 } else { |
741 return element; | 750 return element; |
742 } | 751 } |
743 } | 752 } |
744 return obj->GetHeap()->the_hole_value(); | 753 return obj->GetHeap()->the_hole_value(); |
745 } | 754 } |
746 | 755 |
747 static bool HasElementImpl(SeededNumberDictionary* backing_store, | 756 static bool HasElementImpl(Object* receiver, |
| 757 JSObject* holder, |
748 uint32_t key, | 758 uint32_t key, |
749 JSObject* holder, | 759 SeededNumberDictionary* backing_store) { |
750 Object* receiver) { | |
751 return backing_store->FindEntry(key) != | 760 return backing_store->FindEntry(key) != |
752 SeededNumberDictionary::kNotFound; | 761 SeededNumberDictionary::kNotFound; |
753 } | 762 } |
754 | 763 |
755 static uint32_t GetKeyForIndexImpl(SeededNumberDictionary* dict, | 764 static uint32_t GetKeyForIndexImpl(SeededNumberDictionary* dict, |
756 uint32_t index) { | 765 uint32_t index) { |
757 Object* key = dict->KeyAt(index); | 766 Object* key = dict->KeyAt(index); |
758 return Smi::cast(key)->value(); | 767 return Smi::cast(key)->value(); |
759 } | 768 } |
760 }; | 769 }; |
761 | 770 |
762 | 771 |
763 class NonStrictArgumentsElementsAccessor | 772 class NonStrictArgumentsElementsAccessor |
764 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor, | 773 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor, |
765 FixedArray> { | 774 FixedArray> { |
766 public: | 775 public: |
767 explicit NonStrictArgumentsElementsAccessor(const char* name) | 776 explicit NonStrictArgumentsElementsAccessor(const char* name) |
768 : ElementsAccessorBase<NonStrictArgumentsElementsAccessor, | 777 : ElementsAccessorBase<NonStrictArgumentsElementsAccessor, |
769 FixedArray>(name) {} | 778 FixedArray>(name) {} |
770 protected: | 779 protected: |
771 friend class ElementsAccessorBase<NonStrictArgumentsElementsAccessor, | 780 friend class ElementsAccessorBase<NonStrictArgumentsElementsAccessor, |
772 FixedArray>; | 781 FixedArray>; |
773 | 782 |
774 static MaybeObject* GetImpl(FixedArray* parameter_map, | 783 static MaybeObject* GetImpl(Object* receiver, |
| 784 JSObject* obj, |
775 uint32_t key, | 785 uint32_t key, |
776 JSObject* obj, | 786 FixedArray* parameter_map) { |
777 Object* receiver) { | |
778 Object* probe = GetParameterMapArg(obj, parameter_map, key); | 787 Object* probe = GetParameterMapArg(obj, parameter_map, key); |
779 if (!probe->IsTheHole()) { | 788 if (!probe->IsTheHole()) { |
780 Context* context = Context::cast(parameter_map->get(0)); | 789 Context* context = Context::cast(parameter_map->get(0)); |
781 int context_index = Smi::cast(probe)->value(); | 790 int context_index = Smi::cast(probe)->value(); |
782 ASSERT(!context->get(context_index)->IsTheHole()); | 791 ASSERT(!context->get(context_index)->IsTheHole()); |
783 return context->get(context_index); | 792 return context->get(context_index); |
784 } else { | 793 } else { |
785 // Object is not mapped, defer to the arguments. | 794 // Object is not mapped, defer to the arguments. |
786 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 795 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
787 MaybeObject* maybe_result = ElementsAccessor::ForArray(arguments)->Get( | 796 MaybeObject* maybe_result = ElementsAccessor::ForArray(arguments)->Get( |
788 arguments, key, obj, receiver); | 797 receiver, obj, key, arguments); |
789 Object* result; | 798 Object* result; |
790 if (!maybe_result->ToObject(&result)) return maybe_result; | 799 if (!maybe_result->ToObject(&result)) return maybe_result; |
791 // Elements of the arguments object in slow mode might be slow aliases. | 800 // Elements of the arguments object in slow mode might be slow aliases. |
792 if (result->IsAliasedArgumentsEntry()) { | 801 if (result->IsAliasedArgumentsEntry()) { |
793 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(result); | 802 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(result); |
794 Context* context = Context::cast(parameter_map->get(0)); | 803 Context* context = Context::cast(parameter_map->get(0)); |
795 int context_index = entry->aliased_context_slot(); | 804 int context_index = entry->aliased_context_slot(); |
796 ASSERT(!context->get(context_index)->IsTheHole()); | 805 ASSERT(!context->get(context_index)->IsTheHole()); |
797 return context->get(context_index); | 806 return context->get(context_index); |
798 } else { | 807 } else { |
799 return result; | 808 return result; |
800 } | 809 } |
801 } | 810 } |
802 } | 811 } |
803 | 812 |
804 static MaybeObject* SetLengthImpl(FixedArray* parameter_map, | 813 static MaybeObject* SetLengthImpl(JSObject* obj, |
805 JSObject* obj, | 814 Object* length, |
806 Object* length) { | 815 FixedArray* parameter_map) { |
807 // TODO(mstarzinger): This was never implemented but will be used once we | 816 // TODO(mstarzinger): This was never implemented but will be used once we |
808 // correctly implement [[DefineOwnProperty]] on arrays. | 817 // correctly implement [[DefineOwnProperty]] on arrays. |
809 UNIMPLEMENTED(); | 818 UNIMPLEMENTED(); |
810 return obj; | 819 return obj; |
811 } | 820 } |
812 | 821 |
813 virtual MaybeObject* Delete(JSObject* obj, | 822 virtual MaybeObject* Delete(JSObject* obj, |
814 uint32_t key, | 823 uint32_t key, |
815 JSReceiver::DeleteMode mode) { | 824 JSReceiver::DeleteMode mode) { |
816 FixedArray* parameter_map = FixedArray::cast(obj->elements()); | 825 FixedArray* parameter_map = FixedArray::cast(obj->elements()); |
(...skipping 18 matching lines...) Expand all Loading... |
835 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 844 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
836 return Max(static_cast<uint32_t>(parameter_map->length() - 2), | 845 return Max(static_cast<uint32_t>(parameter_map->length() - 2), |
837 ForArray(arguments)->GetCapacity(arguments)); | 846 ForArray(arguments)->GetCapacity(arguments)); |
838 } | 847 } |
839 | 848 |
840 static uint32_t GetKeyForIndexImpl(FixedArray* dict, | 849 static uint32_t GetKeyForIndexImpl(FixedArray* dict, |
841 uint32_t index) { | 850 uint32_t index) { |
842 return index; | 851 return index; |
843 } | 852 } |
844 | 853 |
845 static bool HasElementImpl(FixedArray* parameter_map, | 854 static bool HasElementImpl(Object* receiver, |
| 855 JSObject* holder, |
846 uint32_t key, | 856 uint32_t key, |
847 JSObject* holder, | 857 FixedArray* parameter_map) { |
848 Object* receiver) { | |
849 Object* probe = GetParameterMapArg(holder, parameter_map, key); | 858 Object* probe = GetParameterMapArg(holder, parameter_map, key); |
850 if (!probe->IsTheHole()) { | 859 if (!probe->IsTheHole()) { |
851 return true; | 860 return true; |
852 } else { | 861 } else { |
853 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 862 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
854 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); | 863 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); |
855 return !accessor->Get(arguments, key, holder, receiver)->IsTheHole(); | 864 return !accessor->Get(receiver, holder, key, arguments)->IsTheHole(); |
856 } | 865 } |
857 } | 866 } |
858 | 867 |
859 private: | 868 private: |
860 static Object* GetParameterMapArg(JSObject* holder, | 869 static Object* GetParameterMapArg(JSObject* holder, |
861 FixedArray* parameter_map, | 870 FixedArray* parameter_map, |
862 uint32_t key) { | 871 uint32_t key) { |
863 uint32_t length = holder->IsJSArray() | 872 uint32_t length = holder->IsJSArray() |
864 ? Smi::cast(JSArray::cast(holder)->length())->value() | 873 ? Smi::cast(JSArray::cast(holder)->length())->value() |
865 : parameter_map->length(); | 874 : parameter_map->length(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 | 954 |
946 STATIC_ASSERT((sizeof(accessor_array) / sizeof(*accessor_array)) == | 955 STATIC_ASSERT((sizeof(accessor_array) / sizeof(*accessor_array)) == |
947 kElementsKindCount); | 956 kElementsKindCount); |
948 | 957 |
949 elements_accessors_ = accessor_array; | 958 elements_accessors_ = accessor_array; |
950 } | 959 } |
951 | 960 |
952 | 961 |
953 template <typename ElementsAccessorSubclass, typename BackingStoreClass> | 962 template <typename ElementsAccessorSubclass, typename BackingStoreClass> |
954 MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, BackingStoreClass>:: | 963 MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, BackingStoreClass>:: |
955 SetLengthImpl(BackingStoreClass* backing_store, | 964 SetLengthImpl(JSObject* obj, |
956 JSObject* obj, | 965 Object* length, |
957 Object* length) { | 966 BackingStoreClass* backing_store) { |
958 JSArray* array = JSArray::cast(obj); | 967 JSArray* array = JSArray::cast(obj); |
959 | 968 |
960 // Fast case: The new length fits into a Smi. | 969 // Fast case: The new length fits into a Smi. |
961 MaybeObject* maybe_smi_length = length->ToSmi(); | 970 MaybeObject* maybe_smi_length = length->ToSmi(); |
962 Object* smi_length = Smi::FromInt(0); | 971 Object* smi_length = Smi::FromInt(0); |
963 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { | 972 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { |
964 const int value = Smi::cast(smi_length)->value(); | 973 const int value = Smi::cast(smi_length)->value(); |
965 if (value >= 0) { | 974 if (value >= 0) { |
966 Object* new_length; | 975 Object* new_length; |
967 MaybeObject* result = ElementsAccessorSubclass:: | 976 MaybeObject* result = ElementsAccessorSubclass:: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 1013 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
1005 new_backing_store->set(0, length); | 1014 new_backing_store->set(0, length); |
1006 { MaybeObject* result = array->SetContent(new_backing_store); | 1015 { MaybeObject* result = array->SetContent(new_backing_store); |
1007 if (result->IsFailure()) return result; | 1016 if (result->IsFailure()) return result; |
1008 } | 1017 } |
1009 return array; | 1018 return array; |
1010 } | 1019 } |
1011 | 1020 |
1012 | 1021 |
1013 } } // namespace v8::internal | 1022 } } // namespace v8::internal |
OLD | NEW |