| OLD | NEW |
| 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 #include "src/elements.h" | 5 #include "src/elements.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 length = fixed_array_base->length(); | 496 length = fixed_array_base->length(); |
| 497 } | 497 } |
| 498 ElementsAccessorSubclass::ValidateContents(holder, length); | 498 ElementsAccessorSubclass::ValidateContents(holder, length); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void Validate(Handle<JSObject> holder) final { | 501 void Validate(Handle<JSObject> holder) final { |
| 502 DisallowHeapAllocation no_gc; | 502 DisallowHeapAllocation no_gc; |
| 503 ElementsAccessorSubclass::ValidateImpl(holder); | 503 ElementsAccessorSubclass::ValidateImpl(holder); |
| 504 } | 504 } |
| 505 | 505 |
| 506 bool IsPacked(Handle<JSObject> holder, Handle<FixedArrayBase> backing_store, | |
| 507 uint32_t start, uint32_t end) final { | |
| 508 return ElementsAccessorSubclass::IsPackedImpl(holder, backing_store, start, | |
| 509 end); | |
| 510 } | |
| 511 | |
| 512 static bool IsPackedImpl(Handle<JSObject> holder, | 506 static bool IsPackedImpl(Handle<JSObject> holder, |
| 513 Handle<FixedArrayBase> backing_store, uint32_t start, | 507 Handle<FixedArrayBase> backing_store, uint32_t start, |
| 514 uint32_t end) { | 508 uint32_t end) { |
| 515 if (IsFastPackedElementsKind(kind())) return true; | 509 if (IsFastPackedElementsKind(kind())) return true; |
| 516 for (uint32_t i = start; i < end; i++) { | 510 for (uint32_t i = start; i < end; i++) { |
| 517 if (!ElementsAccessorSubclass::HasElementImpl(holder, i, backing_store, | 511 if (!ElementsAccessorSubclass::HasElementImpl(holder, i, backing_store, |
| 518 ALL_PROPERTIES)) { | 512 ALL_PROPERTIES)) { |
| 519 return false; | 513 return false; |
| 520 } | 514 } |
| 521 } | 515 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 ElementsAccessorSubclass::AddImpl(object, index, value, attributes, | 585 ElementsAccessorSubclass::AddImpl(object, index, value, attributes, |
| 592 new_capacity); | 586 new_capacity); |
| 593 } | 587 } |
| 594 | 588 |
| 595 static void AddImpl(Handle<JSObject> object, uint32_t index, | 589 static void AddImpl(Handle<JSObject> object, uint32_t index, |
| 596 Handle<Object> value, PropertyAttributes attributes, | 590 Handle<Object> value, PropertyAttributes attributes, |
| 597 uint32_t new_capacity) { | 591 uint32_t new_capacity) { |
| 598 UNREACHABLE(); | 592 UNREACHABLE(); |
| 599 } | 593 } |
| 600 | 594 |
| 601 uint32_t Push(Handle<JSArray> receiver, Handle<FixedArrayBase> backing_store, | 595 uint32_t Push(Handle<JSArray> receiver, Arguments* args, |
| 602 Arguments* args, uint32_t push_size) final { | 596 uint32_t push_size) final { |
| 603 return ElementsAccessorSubclass::PushImpl(receiver, backing_store, args, | 597 return ElementsAccessorSubclass::PushImpl(receiver, args, push_size); |
| 604 push_size); | |
| 605 } | 598 } |
| 606 | 599 |
| 607 static uint32_t PushImpl(Handle<JSArray> receiver, | 600 static uint32_t PushImpl(Handle<JSArray> receiver, Arguments* args, |
| 608 Handle<FixedArrayBase> elms_obj, Arguments* args, | |
| 609 uint32_t push_sized) { | 601 uint32_t push_sized) { |
| 610 UNREACHABLE(); | 602 UNREACHABLE(); |
| 611 return 0; | 603 return 0; |
| 612 } | 604 } |
| 613 | 605 |
| 614 uint32_t Unshift(Handle<JSArray> receiver, | 606 uint32_t Unshift(Handle<JSArray> receiver, Arguments* args, |
| 615 Handle<FixedArrayBase> backing_store, Arguments* args, | |
| 616 uint32_t unshift_size) final { | 607 uint32_t unshift_size) final { |
| 617 return ElementsAccessorSubclass::UnshiftImpl(receiver, backing_store, args, | 608 return ElementsAccessorSubclass::UnshiftImpl(receiver, args, unshift_size); |
| 618 unshift_size); | |
| 619 } | 609 } |
| 620 | 610 |
| 621 static uint32_t UnshiftImpl(Handle<JSArray> receiver, | 611 static uint32_t UnshiftImpl(Handle<JSArray> receiver, Arguments* args, |
| 622 Handle<FixedArrayBase> elms_obj, Arguments* args, | |
| 623 uint32_t unshift_size) { | 612 uint32_t unshift_size) { |
| 624 UNREACHABLE(); | 613 UNREACHABLE(); |
| 625 return 0; | 614 return 0; |
| 626 } | 615 } |
| 627 | 616 |
| 628 Handle<JSArray> Slice(Handle<JSObject> receiver, | 617 Handle<JSArray> Slice(Handle<JSObject> receiver, uint32_t start, |
| 629 Handle<FixedArrayBase> backing_store, uint32_t start, | |
| 630 uint32_t end) final { | 618 uint32_t end) final { |
| 631 return ElementsAccessorSubclass::SliceImpl(receiver, backing_store, start, | 619 return ElementsAccessorSubclass::SliceImpl(receiver, start, end); |
| 632 end); | |
| 633 } | 620 } |
| 634 | 621 |
| 635 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, | 622 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
| 636 Handle<FixedArrayBase> backing_store, | |
| 637 uint32_t start, uint32_t end) { | 623 uint32_t start, uint32_t end) { |
| 638 UNREACHABLE(); | 624 UNREACHABLE(); |
| 639 return Handle<JSArray>(); | 625 return Handle<JSArray>(); |
| 640 } | 626 } |
| 641 | 627 |
| 642 Handle<JSArray> Splice(Handle<JSArray> receiver, | 628 Handle<JSArray> Splice(Handle<JSArray> receiver, uint32_t start, |
| 643 Handle<FixedArrayBase> backing_store, uint32_t start, | |
| 644 uint32_t delete_count, Arguments* args, | 629 uint32_t delete_count, Arguments* args, |
| 645 uint32_t add_count) final { | 630 uint32_t add_count) final { |
| 646 return ElementsAccessorSubclass::SpliceImpl(receiver, backing_store, start, | 631 return ElementsAccessorSubclass::SpliceImpl(receiver, start, delete_count, |
| 647 delete_count, args, add_count); | 632 args, add_count); |
| 648 } | 633 } |
| 649 | 634 |
| 650 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, | 635 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
| 651 Handle<FixedArrayBase> backing_store, | |
| 652 uint32_t start, uint32_t delete_count, | 636 uint32_t start, uint32_t delete_count, |
| 653 Arguments* args, uint32_t add_count) { | 637 Arguments* args, uint32_t add_count) { |
| 654 UNREACHABLE(); | 638 UNREACHABLE(); |
| 655 return Handle<JSArray>(); | 639 return Handle<JSArray>(); |
| 656 } | 640 } |
| 657 | 641 |
| 658 Handle<Object> Pop(Handle<JSArray> receiver, | 642 Handle<Object> Pop(Handle<JSArray> receiver) final { |
| 659 Handle<FixedArrayBase> backing_store) final { | 643 return ElementsAccessorSubclass::PopImpl(receiver); |
| 660 return ElementsAccessorSubclass::PopImpl(receiver, backing_store); | |
| 661 } | 644 } |
| 662 | 645 |
| 663 static Handle<Object> PopImpl(Handle<JSArray> receiver, | 646 static Handle<Object> PopImpl(Handle<JSArray> receiver) { |
| 664 Handle<FixedArrayBase> backing_store) { | |
| 665 UNREACHABLE(); | 647 UNREACHABLE(); |
| 666 return Handle<Object>(); | 648 return Handle<Object>(); |
| 667 } | 649 } |
| 668 | 650 |
| 669 Handle<Object> Shift(Handle<JSArray> receiver, | 651 Handle<Object> Shift(Handle<JSArray> receiver) final { |
| 670 Handle<FixedArrayBase> backing_store) final { | 652 return ElementsAccessorSubclass::ShiftImpl(receiver); |
| 671 return ElementsAccessorSubclass::ShiftImpl(receiver, backing_store); | |
| 672 } | 653 } |
| 673 | 654 |
| 674 static Handle<Object> ShiftImpl(Handle<JSArray> receiver, | 655 static Handle<Object> ShiftImpl(Handle<JSArray> receiver) { |
| 675 Handle<FixedArrayBase> backing_store) { | |
| 676 UNREACHABLE(); | 656 UNREACHABLE(); |
| 677 return Handle<Object>(); | 657 return Handle<Object>(); |
| 678 } | 658 } |
| 679 | 659 |
| 680 void SetLength(Handle<JSArray> array, uint32_t length) final { | 660 void SetLength(Handle<JSArray> array, uint32_t length) final { |
| 681 ElementsAccessorSubclass::SetLengthImpl(array->GetIsolate(), array, length, | 661 ElementsAccessorSubclass::SetLengthImpl(array->GetIsolate(), array, length, |
| 682 handle(array->elements())); | 662 handle(array->elements())); |
| 683 } | 663 } |
| 684 | 664 |
| 685 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array, | 665 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 697 JSObject::TransitionElementsKind(array, kind); | 677 JSObject::TransitionElementsKind(array, kind); |
| 698 } | 678 } |
| 699 } | 679 } |
| 700 | 680 |
| 701 // Check whether the backing store should be shrunk. | 681 // Check whether the backing store should be shrunk. |
| 702 uint32_t capacity = backing_store->length(); | 682 uint32_t capacity = backing_store->length(); |
| 703 old_length = Min(old_length, capacity); | 683 old_length = Min(old_length, capacity); |
| 704 if (length == 0) { | 684 if (length == 0) { |
| 705 array->initialize_elements(); | 685 array->initialize_elements(); |
| 706 } else if (length <= capacity) { | 686 } else if (length <= capacity) { |
| 707 if (array->HasFastSmiOrObjectElements()) { | 687 if (IsFastSmiOrObjectElementsKind(kind())) { |
| 708 JSObject::EnsureWritableFastElements(array); | 688 JSObject::EnsureWritableFastElements(array); |
| 709 if (array->elements() != *backing_store) { | 689 if (array->elements() != *backing_store) { |
| 710 backing_store = handle(array->elements(), isolate); | 690 backing_store = handle(array->elements(), isolate); |
| 711 } | 691 } |
| 712 } | 692 } |
| 713 if (2 * length <= capacity) { | 693 if (2 * length <= capacity) { |
| 714 // If more than half the elements won't be used, trim the array. | 694 // If more than half the elements won't be used, trim the array. |
| 715 isolate->heap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>( | 695 isolate->heap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>( |
| 716 *backing_store, capacity - length); | 696 *backing_store, capacity - length); |
| 717 } else { | 697 } else { |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 if (IsFastSmiElementsKind(KindTraits::Kind)) { | 1331 if (IsFastSmiElementsKind(KindTraits::Kind)) { |
| 1352 for (int i = 0; i < length; i++) { | 1332 for (int i = 0; i < length; i++) { |
| 1353 DCHECK(BackingStore::get(*backing_store, i, isolate)->IsSmi() || | 1333 DCHECK(BackingStore::get(*backing_store, i, isolate)->IsSmi() || |
| 1354 (IsFastHoleyElementsKind(KindTraits::Kind) && | 1334 (IsFastHoleyElementsKind(KindTraits::Kind) && |
| 1355 backing_store->is_the_hole(i))); | 1335 backing_store->is_the_hole(i))); |
| 1356 } | 1336 } |
| 1357 } | 1337 } |
| 1358 #endif | 1338 #endif |
| 1359 } | 1339 } |
| 1360 | 1340 |
| 1361 static Handle<Object> PopImpl(Handle<JSArray> receiver, | 1341 static Handle<Object> PopImpl(Handle<JSArray> receiver) { |
| 1362 Handle<FixedArrayBase> backing_store) { | 1342 return FastElementsAccessorSubclass::RemoveElement(receiver, AT_END); |
| 1363 return FastElementsAccessorSubclass::RemoveElement(receiver, backing_store, | |
| 1364 AT_END); | |
| 1365 } | 1343 } |
| 1366 | 1344 |
| 1367 static Handle<Object> ShiftImpl(Handle<JSArray> receiver, | 1345 static Handle<Object> ShiftImpl(Handle<JSArray> receiver) { |
| 1368 Handle<FixedArrayBase> backing_store) { | 1346 return FastElementsAccessorSubclass::RemoveElement(receiver, AT_START); |
| 1369 return FastElementsAccessorSubclass::RemoveElement(receiver, backing_store, | |
| 1370 AT_START); | |
| 1371 } | 1347 } |
| 1372 | 1348 |
| 1373 static uint32_t PushImpl(Handle<JSArray> receiver, | 1349 static uint32_t PushImpl(Handle<JSArray> receiver, |
| 1374 Handle<FixedArrayBase> backing_store, | |
| 1375 Arguments* args, uint32_t push_size) { | 1350 Arguments* args, uint32_t push_size) { |
| 1351 Handle<FixedArrayBase> backing_store(receiver->elements()); |
| 1376 return FastElementsAccessorSubclass::AddArguments(receiver, backing_store, | 1352 return FastElementsAccessorSubclass::AddArguments(receiver, backing_store, |
| 1377 args, push_size, AT_END); | 1353 args, push_size, AT_END); |
| 1378 } | 1354 } |
| 1379 | 1355 |
| 1380 static uint32_t UnshiftImpl(Handle<JSArray> receiver, | 1356 static uint32_t UnshiftImpl(Handle<JSArray> receiver, |
| 1381 Handle<FixedArrayBase> backing_store, | |
| 1382 Arguments* args, uint32_t unshift_size) { | 1357 Arguments* args, uint32_t unshift_size) { |
| 1358 Handle<FixedArrayBase> backing_store(receiver->elements()); |
| 1383 return FastElementsAccessorSubclass::AddArguments( | 1359 return FastElementsAccessorSubclass::AddArguments( |
| 1384 receiver, backing_store, args, unshift_size, AT_START); | 1360 receiver, backing_store, args, unshift_size, AT_START); |
| 1385 } | 1361 } |
| 1386 | 1362 |
| 1387 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver, | 1363 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver, |
| 1388 Handle<FixedArrayBase> backing_store, int dst_index, | 1364 Handle<FixedArrayBase> backing_store, int dst_index, |
| 1389 int src_index, int len, int hole_start, | 1365 int src_index, int len, int hole_start, |
| 1390 int hole_end) { | 1366 int hole_end) { |
| 1391 UNREACHABLE(); | 1367 UNREACHABLE(); |
| 1392 } | 1368 } |
| 1393 | 1369 |
| 1394 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, | 1370 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
| 1395 Handle<FixedArrayBase> backing_store, | |
| 1396 uint32_t start, uint32_t end) { | 1371 uint32_t start, uint32_t end) { |
| 1397 DCHECK(start < end); | |
| 1398 Isolate* isolate = receiver->GetIsolate(); | 1372 Isolate* isolate = receiver->GetIsolate(); |
| 1399 int result_len = end - start; | 1373 Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
| 1374 int result_len = end < start ? 0u : end - start; |
| 1400 Handle<JSArray> result_array = isolate->factory()->NewJSArray( | 1375 Handle<JSArray> result_array = isolate->factory()->NewJSArray( |
| 1401 KindTraits::Kind, result_len, result_len); | 1376 KindTraits::Kind, result_len, result_len); |
| 1402 DisallowHeapAllocation no_gc; | 1377 DisallowHeapAllocation no_gc; |
| 1403 FastElementsAccessorSubclass::CopyElementsImpl( | 1378 FastElementsAccessorSubclass::CopyElementsImpl( |
| 1404 *backing_store, start, result_array->elements(), KindTraits::Kind, 0, | 1379 *backing_store, start, result_array->elements(), KindTraits::Kind, 0, |
| 1405 kPackedSizeNotKnown, result_len); | 1380 kPackedSizeNotKnown, result_len); |
| 1406 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked( | 1381 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked( |
| 1407 result_array); | 1382 result_array); |
| 1408 return result_array; | 1383 return result_array; |
| 1409 } | 1384 } |
| 1410 | 1385 |
| 1411 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, | 1386 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
| 1412 Handle<FixedArrayBase> backing_store, | |
| 1413 uint32_t start, uint32_t delete_count, | 1387 uint32_t start, uint32_t delete_count, |
| 1414 Arguments* args, uint32_t add_count) { | 1388 Arguments* args, uint32_t add_count) { |
| 1415 Isolate* isolate = receiver->GetIsolate(); | 1389 Isolate* isolate = receiver->GetIsolate(); |
| 1416 Heap* heap = isolate->heap(); | 1390 Heap* heap = isolate->heap(); |
| 1417 uint32_t length = Smi::cast(receiver->length())->value(); | 1391 uint32_t length = Smi::cast(receiver->length())->value(); |
| 1418 uint32_t new_length = length - delete_count + add_count; | 1392 uint32_t new_length = length - delete_count + add_count; |
| 1419 | 1393 |
| 1394 ElementsKind kind = KindTraits::Kind; |
| 1395 if (new_length <= static_cast<uint32_t>(receiver->elements()->length()) && |
| 1396 IsFastSmiOrObjectElementsKind(kind)) { |
| 1397 HandleScope scope(isolate); |
| 1398 JSObject::EnsureWritableFastElements(receiver); |
| 1399 } |
| 1400 |
| 1401 Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
| 1402 |
| 1420 if (new_length == 0) { | 1403 if (new_length == 0) { |
| 1421 receiver->set_elements(heap->empty_fixed_array()); | 1404 receiver->set_elements(heap->empty_fixed_array()); |
| 1422 receiver->set_length(Smi::FromInt(0)); | 1405 receiver->set_length(Smi::FromInt(0)); |
| 1423 return isolate->factory()->NewJSArrayWithElements( | 1406 return isolate->factory()->NewJSArrayWithElements( |
| 1424 backing_store, KindTraits::Kind, delete_count); | 1407 backing_store, KindTraits::Kind, delete_count); |
| 1425 } | 1408 } |
| 1426 | 1409 |
| 1427 // Construct the result array which holds the deleted elements. | 1410 // Construct the result array which holds the deleted elements. |
| 1428 Handle<JSArray> deleted_elements = isolate->factory()->NewJSArray( | 1411 Handle<JSArray> deleted_elements = isolate->factory()->NewJSArray( |
| 1429 KindTraits::Kind, delete_count, delete_count); | 1412 KindTraits::Kind, delete_count, delete_count); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 // Copy the trailing elements after start + delete_count | 1477 // Copy the trailing elements after start + delete_count |
| 1495 FastElementsAccessorSubclass::CopyElementsImpl( | 1478 FastElementsAccessorSubclass::CopyElementsImpl( |
| 1496 *backing_store, start + delete_count, *new_elms, KindTraits::Kind, | 1479 *backing_store, start + delete_count, *new_elms, KindTraits::Kind, |
| 1497 start + add_count, kPackedSizeNotKnown, | 1480 start + add_count, kPackedSizeNotKnown, |
| 1498 ElementsAccessor::kCopyToEndAndInitializeToHole); | 1481 ElementsAccessor::kCopyToEndAndInitializeToHole); |
| 1499 receiver->set_elements(*new_elms); | 1482 receiver->set_elements(*new_elms); |
| 1500 return new_elms; | 1483 return new_elms; |
| 1501 } | 1484 } |
| 1502 | 1485 |
| 1503 static Handle<Object> RemoveElement(Handle<JSArray> receiver, | 1486 static Handle<Object> RemoveElement(Handle<JSArray> receiver, |
| 1504 Handle<FixedArrayBase> backing_store, | |
| 1505 Where remove_position) { | 1487 Where remove_position) { |
| 1506 Isolate* isolate = receiver->GetIsolate(); | 1488 Isolate* isolate = receiver->GetIsolate(); |
| 1489 ElementsKind kind = KindTraits::Kind; |
| 1490 if (IsFastSmiOrObjectElementsKind(kind)) { |
| 1491 HandleScope scope(isolate); |
| 1492 JSObject::EnsureWritableFastElements(receiver); |
| 1493 } |
| 1494 Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
| 1507 uint32_t length = | 1495 uint32_t length = |
| 1508 static_cast<uint32_t>(Smi::cast(receiver->length())->value()); | 1496 static_cast<uint32_t>(Smi::cast(receiver->length())->value()); |
| 1509 DCHECK(length > 0); | 1497 DCHECK(length > 0); |
| 1510 int new_length = length - 1; | 1498 int new_length = length - 1; |
| 1511 int remove_index = remove_position == AT_START ? 0 : new_length; | 1499 int remove_index = remove_position == AT_START ? 0 : new_length; |
| 1512 Handle<Object> result = | 1500 Handle<Object> result = |
| 1513 FastElementsAccessorSubclass::GetImpl(*backing_store, remove_index); | 1501 FastElementsAccessorSubclass::GetImpl(*backing_store, remove_index); |
| 1514 if (remove_position == AT_START) { | 1502 if (remove_position == AT_START) { |
| 1515 FastElementsAccessorSubclass::MoveElements( | 1503 FastElementsAccessorSubclass::MoveElements( |
| 1516 isolate, receiver, backing_store, 0, 1, new_length, 0, 0); | 1504 isolate, receiver, backing_store, 0, 1, new_length, 0, 0); |
| 1517 } | 1505 } |
| 1518 FastElementsAccessorSubclass::SetLengthImpl(isolate, receiver, new_length, | 1506 FastElementsAccessorSubclass::SetLengthImpl(isolate, receiver, new_length, |
| 1519 backing_store); | 1507 backing_store); |
| 1520 | 1508 |
| 1521 if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) { | 1509 if (IsHoleyElementsKind(kind) && result->IsTheHole()) { |
| 1522 return receiver->GetIsolate()->factory()->undefined_value(); | 1510 return isolate->factory()->undefined_value(); |
| 1523 } | 1511 } |
| 1524 return result; | 1512 return result; |
| 1525 } | 1513 } |
| 1526 | 1514 |
| 1527 static uint32_t AddArguments(Handle<JSArray> receiver, | 1515 static uint32_t AddArguments(Handle<JSArray> receiver, |
| 1528 Handle<FixedArrayBase> backing_store, | 1516 Handle<FixedArrayBase> backing_store, |
| 1529 Arguments* args, uint32_t add_size, | 1517 Arguments* args, uint32_t add_size, |
| 1530 Where remove_position) { | 1518 Where remove_position) { |
| 1531 uint32_t length = Smi::cast(receiver->length())->value(); | 1519 uint32_t length = Smi::cast(receiver->length())->value(); |
| 1532 DCHECK(add_size > 0); | 1520 DCHECK(0 < add_size); |
| 1533 uint32_t elms_len = backing_store->length(); | 1521 uint32_t elms_len = backing_store->length(); |
| 1534 // Check we do not overflow the new_length. | 1522 // Check we do not overflow the new_length. |
| 1535 DCHECK(add_size <= static_cast<uint32_t>(Smi::kMaxValue - length)); | 1523 DCHECK(add_size <= static_cast<uint32_t>(Smi::kMaxValue - length)); |
| 1536 uint32_t new_length = length + add_size; | 1524 uint32_t new_length = length + add_size; |
| 1537 | 1525 |
| 1538 if (new_length > elms_len) { | 1526 if (new_length > elms_len) { |
| 1539 // New backing storage is needed. | 1527 // New backing storage is needed. |
| 1540 uint32_t capacity = JSObject::NewElementsCapacity(new_length); | 1528 uint32_t capacity = JSObject::NewElementsCapacity(new_length); |
| 1541 // If we add arguments to the start we have to shift the existing objects. | 1529 // If we add arguments to the start we have to shift the existing objects. |
| 1542 int copy_dst_index = remove_position == AT_START ? add_size : 0; | 1530 int copy_dst_index = remove_position == AT_START ? add_size : 0; |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 static uint32_t GetCapacityImpl(JSObject* holder, | 1919 static uint32_t GetCapacityImpl(JSObject* holder, |
| 1932 FixedArrayBase* backing_store) { | 1920 FixedArrayBase* backing_store) { |
| 1933 JSArrayBufferView* view = JSArrayBufferView::cast(holder); | 1921 JSArrayBufferView* view = JSArrayBufferView::cast(holder); |
| 1934 if (view->WasNeutered()) return 0; | 1922 if (view->WasNeutered()) return 0; |
| 1935 return backing_store->length(); | 1923 return backing_store->length(); |
| 1936 } | 1924 } |
| 1937 | 1925 |
| 1938 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, | 1926 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, |
| 1939 KeyAccumulator* accumulator, | 1927 KeyAccumulator* accumulator, |
| 1940 AddKeyConversion convert) { | 1928 AddKeyConversion convert) { |
| 1941 Handle<FixedArrayBase> elements(receiver->elements(), | 1929 Handle<FixedArrayBase> elements(receiver->elements()); |
| 1942 receiver->GetIsolate()); | |
| 1943 uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements); | 1930 uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements); |
| 1944 for (uint32_t i = 0; i < length; i++) { | 1931 for (uint32_t i = 0; i < length; i++) { |
| 1945 Handle<Object> value = AccessorClass::GetImpl(*elements, i); | 1932 Handle<Object> value = AccessorClass::GetImpl(*elements, i); |
| 1946 accumulator->AddKey(value, convert); | 1933 accumulator->AddKey(value, convert); |
| 1947 } | 1934 } |
| 1948 } | 1935 } |
| 1949 }; | 1936 }; |
| 1950 | 1937 |
| 1951 | 1938 |
| 1952 | 1939 |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2680 } | 2667 } |
| 2681 } | 2668 } |
| 2682 | 2669 |
| 2683 DCHECK(j == result_len); | 2670 DCHECK(j == result_len); |
| 2684 return result_array; | 2671 return result_array; |
| 2685 } | 2672 } |
| 2686 | 2673 |
| 2687 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 2674 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
| 2688 } // namespace internal | 2675 } // namespace internal |
| 2689 } // namespace v8 | 2676 } // namespace v8 |
| OLD | NEW |