OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 Object* length) { | 127 Object* length) { |
128 ASSERT(obj->IsJSArray()); | 128 ASSERT(obj->IsJSArray()); |
129 return ElementsAccessorSubclass::SetLength( | 129 return ElementsAccessorSubclass::SetLength( |
130 BackingStoreClass::cast(obj->elements()), obj, length); | 130 BackingStoreClass::cast(obj->elements()), obj, length); |
131 } | 131 } |
132 | 132 |
133 static MaybeObject* SetLength(BackingStoreClass* backing_store, | 133 static MaybeObject* SetLength(BackingStoreClass* backing_store, |
134 JSObject* obj, | 134 JSObject* obj, |
135 Object* length); | 135 Object* length); |
136 | 136 |
| 137 virtual MaybeObject* SetCapacityAndLength(JSArray* array, |
| 138 int capacity, |
| 139 int length) { |
| 140 return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( |
| 141 array, |
| 142 capacity, |
| 143 length); |
| 144 } |
| 145 |
| 146 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
| 147 int capacity, |
| 148 int length) { |
| 149 UNIMPLEMENTED(); |
| 150 return obj; |
| 151 } |
| 152 |
137 virtual MaybeObject* Delete(JSObject* obj, | 153 virtual MaybeObject* Delete(JSObject* obj, |
138 uint32_t key, | 154 uint32_t key, |
139 JSReceiver::DeleteMode mode) = 0; | 155 JSReceiver::DeleteMode mode) = 0; |
140 | 156 |
141 virtual MaybeObject* AddElementsToFixedArray(FixedArrayBase* from, | 157 virtual MaybeObject* AddElementsToFixedArray(FixedArrayBase* from, |
142 FixedArray* to, | 158 FixedArray* to, |
143 JSObject* holder, | 159 JSObject* holder, |
144 Object* receiver) { | 160 Object* receiver) { |
145 int len0 = to->length(); | 161 int len0 = to->length(); |
146 #ifdef DEBUG | 162 #ifdef DEBUG |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 385 } |
370 if (4 * num_used <= backing_store->length()) { | 386 if (4 * num_used <= backing_store->length()) { |
371 MaybeObject* result = obj->NormalizeElements(); | 387 MaybeObject* result = obj->NormalizeElements(); |
372 if (result->IsFailure()) return result; | 388 if (result->IsFailure()) return result; |
373 } | 389 } |
374 } | 390 } |
375 } | 391 } |
376 return heap->true_value(); | 392 return heap->true_value(); |
377 } | 393 } |
378 | 394 |
379 protected: | |
380 friend class FastElementsAccessor<FastObjectElementsAccessor, | |
381 FixedArray, | |
382 kPointerSize>; | |
383 | |
384 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | 395 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
385 uint32_t capacity, | 396 uint32_t capacity, |
386 uint32_t length) { | 397 uint32_t length) { |
387 JSObject::SetFastElementsCapacityMode set_capacity_mode = | 398 JSObject::SetFastElementsCapacityMode set_capacity_mode = |
388 obj->HasFastSmiOnlyElements() | 399 obj->HasFastSmiOnlyElements() |
389 ? JSObject::kAllowSmiOnlyElements | 400 ? JSObject::kAllowSmiOnlyElements |
390 : JSObject::kDontAllowSmiOnlyElements; | 401 : JSObject::kDontAllowSmiOnlyElements; |
391 return obj->SetFastElementsCapacityAndLength(capacity, | 402 return obj->SetFastElementsCapacityAndLength(capacity, |
392 length, | 403 length, |
393 set_capacity_mode); | 404 set_capacity_mode); |
394 } | 405 } |
395 | 406 |
| 407 protected: |
| 408 friend class FastElementsAccessor<FastObjectElementsAccessor, |
| 409 FixedArray, |
| 410 kPointerSize>; |
| 411 |
396 virtual MaybeObject* Delete(JSObject* obj, | 412 virtual MaybeObject* Delete(JSObject* obj, |
397 uint32_t key, | 413 uint32_t key, |
398 JSReceiver::DeleteMode mode) { | 414 JSReceiver::DeleteMode mode) { |
399 return DeleteCommon(obj, key); | 415 return DeleteCommon(obj, key); |
400 } | 416 } |
401 }; | 417 }; |
402 | 418 |
403 | 419 |
404 class FastDoubleElementsAccessor | 420 class FastDoubleElementsAccessor |
405 : public FastElementsAccessor<FastDoubleElementsAccessor, | 421 : public FastElementsAccessor<FastDoubleElementsAccessor, |
406 FixedDoubleArray, | 422 FixedDoubleArray, |
407 kDoubleSize> { | 423 kDoubleSize> { |
| 424 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
| 425 uint32_t capacity, |
| 426 uint32_t length) { |
| 427 return obj->SetFastDoubleElementsCapacityAndLength(capacity, length); |
| 428 } |
| 429 |
408 protected: | 430 protected: |
409 friend class ElementsAccessorBase<FastDoubleElementsAccessor, | 431 friend class ElementsAccessorBase<FastDoubleElementsAccessor, |
410 FixedDoubleArray>; | 432 FixedDoubleArray>; |
411 friend class FastElementsAccessor<FastDoubleElementsAccessor, | 433 friend class FastElementsAccessor<FastDoubleElementsAccessor, |
412 FixedDoubleArray, | 434 FixedDoubleArray, |
413 kDoubleSize>; | 435 kDoubleSize>; |
414 | 436 |
415 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | |
416 uint32_t capacity, | |
417 uint32_t length) { | |
418 return obj->SetFastDoubleElementsCapacityAndLength(capacity, length); | |
419 } | |
420 | |
421 virtual MaybeObject* Delete(JSObject* obj, | 437 virtual MaybeObject* Delete(JSObject* obj, |
422 uint32_t key, | 438 uint32_t key, |
423 JSReceiver::DeleteMode mode) { | 439 JSReceiver::DeleteMode mode) { |
424 int length = obj->IsJSArray() | 440 int length = obj->IsJSArray() |
425 ? Smi::cast(JSArray::cast(obj)->length())->value() | 441 ? Smi::cast(JSArray::cast(obj)->length())->value() |
426 : FixedDoubleArray::cast(obj->elements())->length(); | 442 : FixedDoubleArray::cast(obj->elements())->length(); |
427 if (key < static_cast<uint32_t>(length)) { | 443 if (key < static_cast<uint32_t>(length)) { |
428 FixedDoubleArray::cast(obj->elements())->set_the_hole(key); | 444 FixedDoubleArray::cast(obj->elements())->set_the_hole(key); |
429 } | 445 } |
430 return obj->GetHeap()->true_value(); | 446 return obj->GetHeap()->true_value(); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 FixedArray* new_backing_store; | 915 FixedArray* new_backing_store; |
900 MaybeObject* maybe_obj = array->GetHeap()->AllocateFixedArray(1); | 916 MaybeObject* maybe_obj = array->GetHeap()->AllocateFixedArray(1); |
901 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 917 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
902 new_backing_store->set(0, length); | 918 new_backing_store->set(0, length); |
903 array->SetContent(new_backing_store); | 919 array->SetContent(new_backing_store); |
904 return array; | 920 return array; |
905 } | 921 } |
906 | 922 |
907 | 923 |
908 } } // namespace v8::internal | 924 } } // namespace v8::internal |
OLD | NEW |