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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 Heap* heap = isolate->heap(); | 518 Heap* heap = isolate->heap(); |
519 Object* receiver = *args.receiver(); | 519 Object* receiver = *args.receiver(); |
520 FixedArrayBase* elms_obj; | 520 FixedArrayBase* elms_obj; |
521 MaybeObject* maybe_elms_obj = | 521 MaybeObject* maybe_elms_obj = |
522 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 1); | 522 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 1); |
523 if (maybe_elms_obj == NULL) { | 523 if (maybe_elms_obj == NULL) { |
524 return CallJsBuiltin(isolate, "ArrayPush", args); | 524 return CallJsBuiltin(isolate, "ArrayPush", args); |
525 } | 525 } |
526 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; | 526 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; |
527 | 527 |
528 if (FLAG_harmony_observation && | 528 JSArray* array = JSArray::cast(receiver); |
529 JSObject::cast(receiver)->map()->is_observed()) { | 529 ASSERT(!array->map()->is_observed()); |
530 return CallJsBuiltin(isolate, "ArrayPush", args); | |
531 } | |
532 | 530 |
533 JSArray* array = JSArray::cast(receiver); | |
534 ElementsKind kind = array->GetElementsKind(); | 531 ElementsKind kind = array->GetElementsKind(); |
535 | 532 |
536 if (IsFastSmiOrObjectElementsKind(kind)) { | 533 if (IsFastSmiOrObjectElementsKind(kind)) { |
537 FixedArray* elms = FixedArray::cast(elms_obj); | 534 FixedArray* elms = FixedArray::cast(elms_obj); |
538 | 535 |
539 int len = Smi::cast(array->length())->value(); | 536 int len = Smi::cast(array->length())->value(); |
540 int to_add = args.length() - 1; | 537 int to_add = args.length() - 1; |
541 if (to_add == 0) { | 538 if (to_add == 0) { |
542 return Smi::FromInt(len); | 539 return Smi::FromInt(len); |
543 } | 540 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 BUILTIN(ArrayPop) { | 632 BUILTIN(ArrayPop) { |
636 Heap* heap = isolate->heap(); | 633 Heap* heap = isolate->heap(); |
637 Object* receiver = *args.receiver(); | 634 Object* receiver = *args.receiver(); |
638 FixedArrayBase* elms_obj; | 635 FixedArrayBase* elms_obj; |
639 MaybeObject* maybe_elms = | 636 MaybeObject* maybe_elms = |
640 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 637 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); |
641 if (maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); | 638 if (maybe_elms == NULL) return CallJsBuiltin(isolate, "ArrayPop", args); |
642 if (!maybe_elms->To(&elms_obj)) return maybe_elms; | 639 if (!maybe_elms->To(&elms_obj)) return maybe_elms; |
643 | 640 |
644 JSArray* array = JSArray::cast(receiver); | 641 JSArray* array = JSArray::cast(receiver); |
645 | 642 ASSERT(!array->map()->is_observed()); |
646 if (FLAG_harmony_observation && array->map()->is_observed()) { | |
647 return CallJsBuiltin(isolate, "ArrayPop", args); | |
648 } | |
649 | 643 |
650 int len = Smi::cast(array->length())->value(); | 644 int len = Smi::cast(array->length())->value(); |
651 if (len == 0) return heap->undefined_value(); | 645 if (len == 0) return heap->undefined_value(); |
652 | 646 |
653 ElementsAccessor* accessor = array->GetElementsAccessor(); | 647 ElementsAccessor* accessor = array->GetElementsAccessor(); |
654 int new_length = len - 1; | 648 int new_length = len - 1; |
655 MaybeObject* maybe_result; | 649 MaybeObject* maybe_result; |
656 if (accessor->HasElement(array, array, new_length, elms_obj)) { | 650 if (accessor->HasElement(array, array, new_length, elms_obj)) { |
657 maybe_result = accessor->Get(array, array, new_length, elms_obj); | 651 maybe_result = accessor->Get(array, array, new_length, elms_obj); |
658 } else { | 652 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
673 MaybeObject* maybe_elms_obj = | 667 MaybeObject* maybe_elms_obj = |
674 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 668 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); |
675 if (maybe_elms_obj == NULL) | 669 if (maybe_elms_obj == NULL) |
676 return CallJsBuiltin(isolate, "ArrayShift", args); | 670 return CallJsBuiltin(isolate, "ArrayShift", args); |
677 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; | 671 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; |
678 | 672 |
679 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | 673 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
680 return CallJsBuiltin(isolate, "ArrayShift", args); | 674 return CallJsBuiltin(isolate, "ArrayShift", args); |
681 } | 675 } |
682 JSArray* array = JSArray::cast(receiver); | 676 JSArray* array = JSArray::cast(receiver); |
683 | 677 ASSERT(!array->map()->is_observed()); |
684 if (FLAG_harmony_observation && array->map()->is_observed()) { | |
685 return CallJsBuiltin(isolate, "ArrayShift", args); | |
686 } | |
687 | 678 |
688 int len = Smi::cast(array->length())->value(); | 679 int len = Smi::cast(array->length())->value(); |
689 if (len == 0) return heap->undefined_value(); | 680 if (len == 0) return heap->undefined_value(); |
690 | 681 |
691 // Get first element | 682 // Get first element |
692 ElementsAccessor* accessor = array->GetElementsAccessor(); | 683 ElementsAccessor* accessor = array->GetElementsAccessor(); |
693 Object* first; | 684 Object* first; |
694 MaybeObject* maybe_first = accessor->Get(receiver, array, 0, elms_obj); | 685 MaybeObject* maybe_first = accessor->Get(receiver, array, 0, elms_obj); |
695 if (!maybe_first->To(&first)) return maybe_first; | 686 if (!maybe_first->To(&first)) return maybe_first; |
696 if (first->IsTheHole()) { | 687 if (first->IsTheHole()) { |
(...skipping 30 matching lines...) Expand all Loading... |
727 MaybeObject* maybe_elms_obj = | 718 MaybeObject* maybe_elms_obj = |
728 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 719 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); |
729 if (maybe_elms_obj == NULL) | 720 if (maybe_elms_obj == NULL) |
730 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 721 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
731 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; | 722 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; |
732 | 723 |
733 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | 724 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
734 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 725 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
735 } | 726 } |
736 JSArray* array = JSArray::cast(receiver); | 727 JSArray* array = JSArray::cast(receiver); |
| 728 ASSERT(!array->map()->is_observed()); |
737 if (!array->HasFastSmiOrObjectElements()) { | 729 if (!array->HasFastSmiOrObjectElements()) { |
738 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 730 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
739 } | 731 } |
740 FixedArray* elms = FixedArray::cast(elms_obj); | 732 FixedArray* elms = FixedArray::cast(elms_obj); |
741 | 733 |
742 if (FLAG_harmony_observation && array->map()->is_observed()) { | |
743 return CallJsBuiltin(isolate, "ArrayUnshift", args); | |
744 } | |
745 | |
746 int len = Smi::cast(array->length())->value(); | 734 int len = Smi::cast(array->length())->value(); |
747 int to_add = args.length() - 1; | 735 int to_add = args.length() - 1; |
748 int new_length = len + to_add; | 736 int new_length = len + to_add; |
749 // Currently fixed arrays cannot grow too big, so | 737 // Currently fixed arrays cannot grow too big, so |
750 // we should never hit this case. | 738 // we should never hit this case. |
751 ASSERT(to_add <= (Smi::kMaxValue - len)); | 739 ASSERT(to_add <= (Smi::kMaxValue - len)); |
752 | 740 |
753 MaybeObject* maybe_object = | 741 MaybeObject* maybe_object = |
754 array->EnsureCanContainElements(&args, 1, to_add, | 742 array->EnsureCanContainElements(&args, 1, to_add, |
755 DONT_ALLOW_DOUBLE_ELEMENTS); | 743 DONT_ALLOW_DOUBLE_ELEMENTS); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 3); | 919 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 3); |
932 if (maybe_elms == NULL) { | 920 if (maybe_elms == NULL) { |
933 return CallJsBuiltin(isolate, "ArraySplice", args); | 921 return CallJsBuiltin(isolate, "ArraySplice", args); |
934 } | 922 } |
935 if (!maybe_elms->To(&elms_obj)) return maybe_elms; | 923 if (!maybe_elms->To(&elms_obj)) return maybe_elms; |
936 | 924 |
937 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | 925 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { |
938 return CallJsBuiltin(isolate, "ArraySplice", args); | 926 return CallJsBuiltin(isolate, "ArraySplice", args); |
939 } | 927 } |
940 JSArray* array = JSArray::cast(receiver); | 928 JSArray* array = JSArray::cast(receiver); |
941 | 929 ASSERT(!array->map()->is_observed()); |
942 if (FLAG_harmony_observation && array->map()->is_observed()) { | |
943 return CallJsBuiltin(isolate, "ArraySplice", args); | |
944 } | |
945 | 930 |
946 int len = Smi::cast(array->length())->value(); | 931 int len = Smi::cast(array->length())->value(); |
947 | 932 |
948 int n_arguments = args.length() - 1; | 933 int n_arguments = args.length() - 1; |
949 | 934 |
950 int relative_start = 0; | 935 int relative_start = 0; |
951 if (n_arguments > 0) { | 936 if (n_arguments > 0) { |
952 Object* arg1 = args[1]; | 937 Object* arg1 = args[1]; |
953 if (arg1->IsSmi()) { | 938 if (arg1->IsSmi()) { |
954 relative_start = Smi::cast(arg1)->value(); | 939 relative_start = Smi::cast(arg1)->value(); |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 return Handle<Code>(code_address); \ | 1875 return Handle<Code>(code_address); \ |
1891 } | 1876 } |
1892 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1877 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1893 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1878 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1894 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1879 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1895 #undef DEFINE_BUILTIN_ACCESSOR_C | 1880 #undef DEFINE_BUILTIN_ACCESSOR_C |
1896 #undef DEFINE_BUILTIN_ACCESSOR_A | 1881 #undef DEFINE_BUILTIN_ACCESSOR_A |
1897 | 1882 |
1898 | 1883 |
1899 } } // namespace v8::internal | 1884 } } // namespace v8::internal |
OLD | NEW |