| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 return top; | 521 return top; |
| 522 } | 522 } |
| 523 | 523 |
| 524 | 524 |
| 525 BUILTIN(ArrayShift) { | 525 BUILTIN(ArrayShift) { |
| 526 Heap* heap = isolate->heap(); | 526 Heap* heap = isolate->heap(); |
| 527 Object* receiver = *args.receiver(); | 527 Object* receiver = *args.receiver(); |
| 528 Object* elms_obj; | 528 Object* elms_obj; |
| 529 { MaybeObject* maybe_elms_obj = | 529 { MaybeObject* maybe_elms_obj = |
| 530 EnsureJSArrayWithWritableFastElements(heap, receiver); | 530 EnsureJSArrayWithWritableFastElements(heap, receiver); |
| 531 if (maybe_elms_obj == NULL) |
| 532 return CallJsBuiltin(isolate, "ArrayShift", args); |
| 531 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 533 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; |
| 532 } | 534 } |
| 533 if (elms_obj == NULL || | 535 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
| 534 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | |
| 535 return CallJsBuiltin(isolate, "ArrayShift", args); | 536 return CallJsBuiltin(isolate, "ArrayShift", args); |
| 536 } | 537 } |
| 537 FixedArray* elms = FixedArray::cast(elms_obj); | 538 FixedArray* elms = FixedArray::cast(elms_obj); |
| 538 JSArray* array = JSArray::cast(receiver); | 539 JSArray* array = JSArray::cast(receiver); |
| 539 ASSERT(array->HasFastElements()); | 540 ASSERT(array->HasFastElements()); |
| 540 | 541 |
| 541 int len = Smi::cast(array->length())->value(); | 542 int len = Smi::cast(array->length())->value(); |
| 542 if (len == 0) return heap->undefined_value(); | 543 if (len == 0) return heap->undefined_value(); |
| 543 | 544 |
| 544 // Get first element | 545 // Get first element |
| (...skipping 19 matching lines...) Expand all Loading... |
| 564 return first; | 565 return first; |
| 565 } | 566 } |
| 566 | 567 |
| 567 | 568 |
| 568 BUILTIN(ArrayUnshift) { | 569 BUILTIN(ArrayUnshift) { |
| 569 Heap* heap = isolate->heap(); | 570 Heap* heap = isolate->heap(); |
| 570 Object* receiver = *args.receiver(); | 571 Object* receiver = *args.receiver(); |
| 571 Object* elms_obj; | 572 Object* elms_obj; |
| 572 { MaybeObject* maybe_elms_obj = | 573 { MaybeObject* maybe_elms_obj = |
| 573 EnsureJSArrayWithWritableFastElements(heap, receiver); | 574 EnsureJSArrayWithWritableFastElements(heap, receiver); |
| 575 if (maybe_elms_obj == NULL) |
| 576 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
| 574 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 577 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; |
| 575 } | 578 } |
| 576 if (elms_obj == NULL || | 579 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
| 577 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | |
| 578 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 580 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
| 579 } | 581 } |
| 580 FixedArray* elms = FixedArray::cast(elms_obj); | 582 FixedArray* elms = FixedArray::cast(elms_obj); |
| 581 JSArray* array = JSArray::cast(receiver); | 583 JSArray* array = JSArray::cast(receiver); |
| 582 ASSERT(array->HasFastElements()); | 584 ASSERT(array->HasFastElements()); |
| 583 | 585 |
| 584 int len = Smi::cast(array->length())->value(); | 586 int len = Smi::cast(array->length())->value(); |
| 585 int to_add = args.length() - 1; | 587 int to_add = args.length() - 1; |
| 586 int new_length = len + to_add; | 588 int new_length = len + to_add; |
| 587 // Currently fixed arrays cannot grow too big, so | 589 // Currently fixed arrays cannot grow too big, so |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 621 |
| 620 // Set the length. | 622 // Set the length. |
| 621 array->set_length(Smi::FromInt(new_length)); | 623 array->set_length(Smi::FromInt(new_length)); |
| 622 return Smi::FromInt(new_length); | 624 return Smi::FromInt(new_length); |
| 623 } | 625 } |
| 624 | 626 |
| 625 | 627 |
| 626 BUILTIN(ArraySlice) { | 628 BUILTIN(ArraySlice) { |
| 627 Heap* heap = isolate->heap(); | 629 Heap* heap = isolate->heap(); |
| 628 Object* receiver = *args.receiver(); | 630 Object* receiver = *args.receiver(); |
| 629 Object* elms_obj; | 631 FixedArray* elms; |
| 632 int len = -1; |
| 630 { MaybeObject* maybe_elms_obj = | 633 { MaybeObject* maybe_elms_obj = |
| 631 EnsureJSArrayWithWritableFastElements(heap, receiver); | 634 EnsureJSArrayWithWritableFastElements(heap, receiver); |
| 632 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 635 Object* elms_obj; |
| 636 if (maybe_elms_obj != NULL && maybe_elms_obj->ToObject(&elms_obj)) { |
| 637 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
| 638 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 639 } |
| 640 elms = FixedArray::cast(elms_obj); |
| 641 JSArray* array = JSArray::cast(receiver); |
| 642 ASSERT(array->HasFastElements()); |
| 643 |
| 644 len = Smi::cast(array->length())->value(); |
| 645 } else { |
| 646 // Array.slice(arguments, ...) is quite a common idiom (notably more |
| 647 // than 50% of invocations in Web apps). Treat it in C++ as well. |
| 648 Map* arguments_map = |
| 649 isolate->context()->global_context()->arguments_boilerplate()->map(); |
| 650 |
| 651 bool is_arguments_object_with_fast_elements = |
| 652 receiver->IsJSObject() |
| 653 && JSObject::cast(receiver)->map() == arguments_map |
| 654 && JSObject::cast(receiver)->HasFastElements(); |
| 655 if (!is_arguments_object_with_fast_elements) { |
| 656 return CallJsBuiltin(isolate, "ArraySlice", args); |
| 657 } |
| 658 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); |
| 659 len = elms->length(); |
| 660 #ifdef DEBUG |
| 661 // Arguments object by construction should have no holes, check it. |
| 662 if (FLAG_enable_slow_asserts) { |
| 663 for (int i = 0; i < len; i++) { |
| 664 ASSERT(elms->get(i) != heap->the_hole_value()); |
| 665 } |
| 666 } |
| 667 #endif |
| 668 } |
| 633 } | 669 } |
| 634 if (elms_obj == NULL || | 670 ASSERT(len >= 0); |
| 635 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | |
| 636 return CallJsBuiltin(isolate, "ArraySlice", args); | |
| 637 } | |
| 638 FixedArray* elms = FixedArray::cast(elms_obj); | |
| 639 JSArray* array = JSArray::cast(receiver); | |
| 640 ASSERT(array->HasFastElements()); | |
| 641 | |
| 642 int len = Smi::cast(array->length())->value(); | |
| 643 | |
| 644 int n_arguments = args.length() - 1; | 671 int n_arguments = args.length() - 1; |
| 645 | 672 |
| 646 // Note carefully choosen defaults---if argument is missing, | 673 // Note carefully choosen defaults---if argument is missing, |
| 647 // it's undefined which gets converted to 0 for relative_start | 674 // it's undefined which gets converted to 0 for relative_start |
| 648 // and to len for relative_end. | 675 // and to len for relative_end. |
| 649 int relative_start = 0; | 676 int relative_start = 0; |
| 650 int relative_end = len; | 677 int relative_end = len; |
| 651 if (n_arguments > 0) { | 678 if (n_arguments > 0) { |
| 652 Object* arg1 = args[1]; | 679 Object* arg1 = args[1]; |
| 653 if (arg1->IsSmi()) { | 680 if (arg1->IsSmi()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 return result_array; | 729 return result_array; |
| 703 } | 730 } |
| 704 | 731 |
| 705 | 732 |
| 706 BUILTIN(ArraySplice) { | 733 BUILTIN(ArraySplice) { |
| 707 Heap* heap = isolate->heap(); | 734 Heap* heap = isolate->heap(); |
| 708 Object* receiver = *args.receiver(); | 735 Object* receiver = *args.receiver(); |
| 709 Object* elms_obj; | 736 Object* elms_obj; |
| 710 { MaybeObject* maybe_elms_obj = | 737 { MaybeObject* maybe_elms_obj = |
| 711 EnsureJSArrayWithWritableFastElements(heap, receiver); | 738 EnsureJSArrayWithWritableFastElements(heap, receiver); |
| 739 if (maybe_elms_obj == NULL) |
| 740 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 712 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 741 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; |
| 713 } | 742 } |
| 714 if (elms_obj == NULL || | 743 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
| 715 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | |
| 716 return CallJsBuiltin(isolate, "ArraySplice", args); | 744 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 717 } | 745 } |
| 718 FixedArray* elms = FixedArray::cast(elms_obj); | 746 FixedArray* elms = FixedArray::cast(elms_obj); |
| 719 JSArray* array = JSArray::cast(receiver); | 747 JSArray* array = JSArray::cast(receiver); |
| 720 ASSERT(array->HasFastElements()); | 748 ASSERT(array->HasFastElements()); |
| 721 | 749 |
| 722 int len = Smi::cast(array->length())->value(); | 750 int len = Smi::cast(array->length())->value(); |
| 723 | 751 |
| 724 int n_arguments = args.length() - 1; | 752 int n_arguments = args.length() - 1; |
| 725 | 753 |
| (...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 if (entry->contains(pc)) { | 1668 if (entry->contains(pc)) { |
| 1641 return names_[i]; | 1669 return names_[i]; |
| 1642 } | 1670 } |
| 1643 } | 1671 } |
| 1644 } | 1672 } |
| 1645 return NULL; | 1673 return NULL; |
| 1646 } | 1674 } |
| 1647 | 1675 |
| 1648 | 1676 |
| 1649 } } // namespace v8::internal | 1677 } } // namespace v8::internal |
| OLD | NEW |