OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 } | 507 } |
508 | 508 |
509 JSArray* array = JSArray::cast(*args.receiver()); | 509 JSArray* array = JSArray::cast(*args.receiver()); |
510 ASSERT(array->HasFastElements()); | 510 ASSERT(array->HasFastElements()); |
511 | 511 |
512 int len = Smi::cast(array->length())->value(); | 512 int len = Smi::cast(array->length())->value(); |
513 | 513 |
514 int n_arguments = args.length() - 1; | 514 int n_arguments = args.length() - 1; |
515 | 515 |
516 // Note carefully choosen defaults---if argument is missing, | 516 // Note carefully choosen defaults---if argument is missing, |
517 // it's undefined which gets converted to 0 for relativeStart | 517 // it's undefined which gets converted to 0 for relative_start |
518 // and to len for relativeEnd. | 518 // and to len for relative_end. |
519 int relativeStart = 0; | 519 int relative_start = 0; |
520 int relativeEnd = len; | 520 int relative_end = len; |
521 if (n_arguments > 0) { | 521 if (n_arguments > 0) { |
522 Object* arg1 = args[1]; | 522 Object* arg1 = args[1]; |
523 if (arg1->IsSmi()) { | 523 if (arg1->IsSmi()) { |
524 relativeStart = Smi::cast(arg1)->value(); | 524 relative_start = Smi::cast(arg1)->value(); |
525 } else if (!arg1->IsUndefined()) { | 525 } else if (!arg1->IsUndefined()) { |
526 return CallJsBuiltin("ArraySlice", args); | 526 return CallJsBuiltin("ArraySlice", args); |
527 } | 527 } |
528 if (n_arguments > 1) { | 528 if (n_arguments > 1) { |
529 Object* arg2 = args[2]; | 529 Object* arg2 = args[2]; |
530 if (arg2->IsSmi()) { | 530 if (arg2->IsSmi()) { |
531 relativeEnd = Smi::cast(arg2)->value(); | 531 relative_end = Smi::cast(arg2)->value(); |
532 } else if (!arg2->IsUndefined()) { | 532 } else if (!arg2->IsUndefined()) { |
533 return CallJsBuiltin("ArraySlice", args); | 533 return CallJsBuiltin("ArraySlice", args); |
534 } | 534 } |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. | 538 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. |
539 int k = (relativeStart < 0) ? Max(len + relativeStart, 0) | 539 int k = (relative_start < 0) ? Max(len + relative_start, 0) |
540 : Min(relativeStart, len); | 540 : Min(relative_start, len); |
541 | 541 |
542 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. | 542 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. |
543 int final = (relativeEnd < 0) ? Max(len + relativeEnd, 0) | 543 int final = (relative_end < 0) ? Max(len + relative_end, 0) |
544 : Min(relativeEnd, len); | 544 : Min(relative_end, len); |
545 | 545 |
546 // Calculate the length of result array. | 546 // Calculate the length of result array. |
547 int result_len = final - k; | 547 int result_len = final - k; |
548 if (result_len <= 0) { | 548 if (result_len <= 0) { |
549 return AllocateEmptyJSArray(); | 549 return AllocateEmptyJSArray(); |
550 } | 550 } |
551 | 551 |
552 Object* result = AllocateJSArray(); | 552 Object* result = AllocateJSArray(); |
553 if (result->IsFailure()) return result; | 553 if (result->IsFailure()) return result; |
554 JSArray* result_array = JSArray::cast(result); | 554 JSArray* result_array = JSArray::cast(result); |
(...skipping 30 matching lines...) Expand all Loading... |
585 | 585 |
586 // SpiderMonkey and JSC return undefined in the case where no | 586 // SpiderMonkey and JSC return undefined in the case where no |
587 // arguments are given instead of using the implicit undefined | 587 // arguments are given instead of using the implicit undefined |
588 // arguments. This does not follow ECMA-262, but we do the same for | 588 // arguments. This does not follow ECMA-262, but we do the same for |
589 // compatibility. | 589 // compatibility. |
590 // TraceMonkey follows ECMA-262 though. | 590 // TraceMonkey follows ECMA-262 though. |
591 if (n_arguments == 0) { | 591 if (n_arguments == 0) { |
592 return Heap::undefined_value(); | 592 return Heap::undefined_value(); |
593 } | 593 } |
594 | 594 |
595 int relativeStart = 0; | 595 int relative_start = 0; |
596 Object* arg1 = args[1]; | 596 Object* arg1 = args[1]; |
597 if (arg1->IsSmi()) { | 597 if (arg1->IsSmi()) { |
598 relativeStart = Smi::cast(arg1)->value(); | 598 relative_start = Smi::cast(arg1)->value(); |
599 } else if (!arg1->IsUndefined()) { | 599 } else if (!arg1->IsUndefined()) { |
600 return CallJsBuiltin("ArraySplice", args); | 600 return CallJsBuiltin("ArraySplice", args); |
601 } | 601 } |
602 int actualStart = (relativeStart < 0) ? Max(len + relativeStart, 0) | 602 int actual_start = (relative_start < 0) ? Max(len + relative_start, 0) |
603 : Min(relativeStart, len); | 603 : Min(relative_start, len); |
604 | 604 |
605 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is | 605 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is |
606 // given differently from when an undefined delete count is given. | 606 // given differently from when an undefined delete count is given. |
607 // This does not follow ECMA-262, but we do the same for | 607 // This does not follow ECMA-262, but we do the same for |
608 // compatibility. | 608 // compatibility. |
609 int deleteCount = len; | 609 int delete_count = len; |
610 if (n_arguments > 1) { | 610 if (n_arguments > 1) { |
611 Object* arg2 = args[2]; | 611 Object* arg2 = args[2]; |
612 if (arg2->IsSmi()) { | 612 if (arg2->IsSmi()) { |
613 deleteCount = Smi::cast(arg2)->value(); | 613 delete_count = Smi::cast(arg2)->value(); |
614 } else { | 614 } else { |
615 return CallJsBuiltin("ArraySplice", args); | 615 return CallJsBuiltin("ArraySplice", args); |
616 } | 616 } |
617 } | 617 } |
618 int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart); | 618 int actual_delete_count = Min(Max(delete_count, 0), len - actual_start); |
619 | 619 |
620 FixedArray* elms = FixedArray::cast(array->elements()); | 620 FixedArray* elms = FixedArray::cast(array->elements()); |
621 | 621 |
622 JSArray* result_array = NULL; | 622 JSArray* result_array = NULL; |
623 if (actualDeleteCount == 0) { | 623 if (actual_delete_count == 0) { |
624 Object* result = AllocateEmptyJSArray(); | 624 Object* result = AllocateEmptyJSArray(); |
625 if (result->IsFailure()) return result; | 625 if (result->IsFailure()) return result; |
626 result_array = JSArray::cast(result); | 626 result_array = JSArray::cast(result); |
627 } else { | 627 } else { |
628 // Allocate result array. | 628 // Allocate result array. |
629 Object* result = AllocateJSArray(); | 629 Object* result = AllocateJSArray(); |
630 if (result->IsFailure()) return result; | 630 if (result->IsFailure()) return result; |
631 result_array = JSArray::cast(result); | 631 result_array = JSArray::cast(result); |
632 | 632 |
633 result = Heap::AllocateUninitializedFixedArray(actualDeleteCount); | 633 result = Heap::AllocateUninitializedFixedArray(actual_delete_count); |
634 if (result->IsFailure()) return result; | 634 if (result->IsFailure()) return result; |
635 FixedArray* result_elms = FixedArray::cast(result); | 635 FixedArray* result_elms = FixedArray::cast(result); |
636 | 636 |
637 AssertNoAllocation no_gc; | 637 AssertNoAllocation no_gc; |
638 // Fill newly created array. | 638 // Fill newly created array. |
639 CopyElements(&no_gc, result_elms, 0, elms, actualStart, actualDeleteCount); | 639 CopyElements(&no_gc, |
| 640 result_elms, 0, |
| 641 elms, actual_start, |
| 642 actual_delete_count); |
640 | 643 |
641 // Set elements. | 644 // Set elements. |
642 result_array->set_elements(result_elms); | 645 result_array->set_elements(result_elms); |
643 | 646 |
644 // Set the length. | 647 // Set the length. |
645 result_array->set_length(Smi::FromInt(actualDeleteCount)); | 648 result_array->set_length(Smi::FromInt(actual_delete_count)); |
646 } | 649 } |
647 | 650 |
648 int itemCount = (n_arguments > 1) ? (n_arguments - 2) : 0; | 651 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; |
649 | 652 |
650 int new_length = len - actualDeleteCount + itemCount; | 653 int new_length = len - actual_delete_count + item_count; |
651 | 654 |
652 if (itemCount < actualDeleteCount) { | 655 if (item_count < actual_delete_count) { |
653 // Shrink the array. | 656 // Shrink the array. |
654 AssertNoAllocation no_gc; | 657 AssertNoAllocation no_gc; |
655 MoveElements(&no_gc, | 658 MoveElements(&no_gc, |
656 elms, actualStart + itemCount, | 659 elms, actual_start + item_count, |
657 elms, actualStart + actualDeleteCount, | 660 elms, actual_start + actual_delete_count, |
658 (len - actualDeleteCount - actualStart)); | 661 (len - actual_delete_count - actual_start)); |
659 FillWithHoles(elms, new_length, len); | 662 FillWithHoles(elms, new_length, len); |
660 } else if (itemCount > actualDeleteCount) { | 663 } else if (item_count > actual_delete_count) { |
661 // Currently fixed arrays cannot grow too big, so | 664 // Currently fixed arrays cannot grow too big, so |
662 // we should never hit this case. | 665 // we should never hit this case. |
663 ASSERT((itemCount - actualDeleteCount) <= (Smi::kMaxValue - len)); | 666 ASSERT((item_count - actual_delete_count) <= (Smi::kMaxValue - len)); |
664 | 667 |
665 FixedArray* source_elms = elms; | 668 FixedArray* source_elms = elms; |
666 | 669 |
667 // Check if array need to grow. | 670 // Check if array need to grow. |
668 if (new_length > elms->length()) { | 671 if (new_length > elms->length()) { |
669 // New backing storage is needed. | 672 // New backing storage is needed. |
670 int capacity = new_length + (new_length >> 1) + 16; | 673 int capacity = new_length + (new_length >> 1) + 16; |
671 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); | 674 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); |
672 if (obj->IsFailure()) return obj; | 675 if (obj->IsFailure()) return obj; |
673 FixedArray* new_elms = FixedArray::cast(obj); | 676 FixedArray* new_elms = FixedArray::cast(obj); |
674 | 677 |
675 AssertNoAllocation no_gc; | 678 AssertNoAllocation no_gc; |
676 // Copy the part before actualStart as is. | 679 // Copy the part before actual_start as is. |
677 CopyElements(&no_gc, new_elms, 0, elms, 0, actualStart); | 680 CopyElements(&no_gc, new_elms, 0, elms, 0, actual_start); |
678 FillWithHoles(new_elms, new_length, capacity); | 681 FillWithHoles(new_elms, new_length, capacity); |
679 | 682 |
680 source_elms = elms; | 683 source_elms = elms; |
681 elms = new_elms; | 684 elms = new_elms; |
682 array->set_elements(elms); | 685 array->set_elements(elms); |
683 } | 686 } |
684 | 687 |
685 AssertNoAllocation no_gc; | 688 AssertNoAllocation no_gc; |
686 MoveElements(&no_gc, | 689 MoveElements(&no_gc, |
687 elms, actualStart + itemCount, | 690 elms, actual_start + item_count, |
688 source_elms, actualStart + actualDeleteCount, | 691 source_elms, actual_start + actual_delete_count, |
689 (len - actualDeleteCount - actualStart)); | 692 (len - actual_delete_count - actual_start)); |
690 } | 693 } |
691 | 694 |
692 AssertNoAllocation no_gc; | 695 AssertNoAllocation no_gc; |
693 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 696 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
694 for (int k = actualStart; k < actualStart + itemCount; k++) { | 697 for (int k = actual_start; k < actual_start + item_count; k++) { |
695 elms->set(k, args[3 + k - actualStart], mode); | 698 elms->set(k, args[3 + k - actual_start], mode); |
696 } | 699 } |
697 | 700 |
698 // Set the length. | 701 // Set the length. |
699 array->set_length(Smi::FromInt(new_length)); | 702 array->set_length(Smi::FromInt(new_length)); |
700 | 703 |
701 return result_array; | 704 return result_array; |
702 } | 705 } |
703 | 706 |
704 | 707 |
705 // ----------------------------------------------------------------------------- | 708 // ----------------------------------------------------------------------------- |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 if (entry->contains(pc)) { | 1349 if (entry->contains(pc)) { |
1347 return names_[i]; | 1350 return names_[i]; |
1348 } | 1351 } |
1349 } | 1352 } |
1350 } | 1353 } |
1351 return NULL; | 1354 return NULL; |
1352 } | 1355 } |
1353 | 1356 |
1354 | 1357 |
1355 } } // namespace v8::internal | 1358 } } // namespace v8::internal |
OLD | NEW |