| 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 return CallJsBuiltin(isolate, "ArraySplice", args); | 746 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 747 } | 747 } |
| 748 FixedArray* elms = FixedArray::cast(elms_obj); | 748 FixedArray* elms = FixedArray::cast(elms_obj); |
| 749 JSArray* array = JSArray::cast(receiver); | 749 JSArray* array = JSArray::cast(receiver); |
| 750 ASSERT(array->HasFastElements()); | 750 ASSERT(array->HasFastElements()); |
| 751 | 751 |
| 752 int len = Smi::cast(array->length())->value(); | 752 int len = Smi::cast(array->length())->value(); |
| 753 | 753 |
| 754 int n_arguments = args.length() - 1; | 754 int n_arguments = args.length() - 1; |
| 755 | 755 |
| 756 // Return empty array when no arguments are supplied. | |
| 757 if (n_arguments == 0) { | |
| 758 return AllocateEmptyJSArray(heap); | |
| 759 } | |
| 760 | |
| 761 int relative_start = 0; | 756 int relative_start = 0; |
| 762 Object* arg1 = args[1]; | 757 if (n_arguments > 0) { |
| 763 if (arg1->IsSmi()) { | 758 Object* arg1 = args[1]; |
| 764 relative_start = Smi::cast(arg1)->value(); | 759 if (arg1->IsSmi()) { |
| 765 } else if (!arg1->IsUndefined()) { | 760 relative_start = Smi::cast(arg1)->value(); |
| 766 return CallJsBuiltin(isolate, "ArraySplice", args); | 761 } else if (!arg1->IsUndefined()) { |
| 762 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 763 } |
| 767 } | 764 } |
| 768 int actual_start = (relative_start < 0) ? Max(len + relative_start, 0) | 765 int actual_start = (relative_start < 0) ? Max(len + relative_start, 0) |
| 769 : Min(relative_start, len); | 766 : Min(relative_start, len); |
| 770 | 767 |
| 771 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is | 768 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is |
| 772 // given differently from when an undefined delete count is given. | 769 // given as a request to delete all the elements from the start. |
| 770 // And it differs from the case of undefined delete count. |
| 773 // This does not follow ECMA-262, but we do the same for | 771 // This does not follow ECMA-262, but we do the same for |
| 774 // compatibility. | 772 // compatibility. |
| 775 int delete_count = len; | 773 int actual_delete_count; |
| 776 if (n_arguments > 1) { | 774 if (n_arguments == 1) { |
| 777 Object* arg2 = args[2]; | 775 ASSERT(len - actual_start >= 0); |
| 778 if (arg2->IsSmi()) { | 776 actual_delete_count = len - actual_start; |
| 779 delete_count = Smi::cast(arg2)->value(); | 777 } else { |
| 780 } else { | 778 int value = 0; // ToInteger(undefined) == 0 |
| 781 return CallJsBuiltin(isolate, "ArraySplice", args); | 779 if (n_arguments > 1) { |
| 780 Object* arg2 = args[2]; |
| 781 if (arg2->IsSmi()) { |
| 782 value = Smi::cast(arg2)->value(); |
| 783 } else { |
| 784 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 785 } |
| 782 } | 786 } |
| 787 actual_delete_count = Min(Max(value, 0), len - actual_start); |
| 783 } | 788 } |
| 784 int actual_delete_count = Min(Max(delete_count, 0), len - actual_start); | |
| 785 | 789 |
| 786 JSArray* result_array = NULL; | 790 JSArray* result_array = NULL; |
| 787 if (actual_delete_count == 0) { | 791 if (actual_delete_count == 0) { |
| 788 Object* result; | 792 Object* result; |
| 789 { MaybeObject* maybe_result = AllocateEmptyJSArray(heap); | 793 { MaybeObject* maybe_result = AllocateEmptyJSArray(heap); |
| 790 if (!maybe_result->ToObject(&result)) return maybe_result; | 794 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 791 } | 795 } |
| 792 result_array = JSArray::cast(result); | 796 result_array = JSArray::cast(result); |
| 793 } else { | 797 } else { |
| 794 // Allocate result array. | 798 // Allocate result array. |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 if (entry->contains(pc)) { | 1607 if (entry->contains(pc)) { |
| 1604 return names_[i]; | 1608 return names_[i]; |
| 1605 } | 1609 } |
| 1606 } | 1610 } |
| 1607 } | 1611 } |
| 1608 return NULL; | 1612 return NULL; |
| 1609 } | 1613 } |
| 1610 | 1614 |
| 1611 | 1615 |
| 1612 } } // namespace v8::internal | 1616 } } // namespace v8::internal |
| OLD | NEW |