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