Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: src/elements.cc

Issue 772533003: Support strict and aliased arguments in Array.prototype.slice Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/builtins.cc ('K') | « src/builtins.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/v8.h" 5 #include "src/v8.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/elements.h" 9 #include "src/elements.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, mode); 1673 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, mode);
1674 } 1674 }
1675 } 1675 }
1676 return isolate->factory()->true_value(); 1676 return isolate->factory()->true_value();
1677 } 1677 }
1678 1678
1679 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 1679 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
1680 FixedArrayBase* to, ElementsKind from_kind, 1680 FixedArrayBase* to, ElementsKind from_kind,
1681 uint32_t to_start, int packed_size, 1681 uint32_t to_start, int packed_size,
1682 int copy_size) { 1682 int copy_size) {
1683 UNREACHABLE(); 1683 DCHECK_LE(0, copy_size);
1684 if (copy_size == 0) return;
1685 Isolate* isolate = from->GetIsolate();
1686 FixedArray* parameter_map = FixedArray::cast(from);
1687 FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
1688 // Since we may need to call back into JS if arguments is a dictionary,
1689 // disallow copying it here.
1690 DCHECK(!arguments->IsDictionary());
1691 Context* context = Context::cast(parameter_map->get(0));
1692 Object* the_hole = isolate->heap()->the_hole_value();
1693
1694 int max_copy_size = to->length() - to_start;
1695 // Limit up to which we copy.
1696 int copy_length = Min(max_copy_size, copy_size) + from_start;
1697 // Portion of this limit that are mapped.
1698 int mapped = Min(copy_length, parameter_map->length() - 2);
1699 // Portion of the limit that is unmapped.
1700 int actual = Min(copy_length, arguments->length());
1701
1702 // Copy arguments that may be mapped.
1703 int limit = mapped - from_start;
1704 int i;
1705 for (i = 0; i < limit; i++) {
1706 Object* probe = parameter_map->get(from_start + 2 + i);
1707 Object* value;
1708 if (probe->IsTheHole()) {
1709 value = arguments->get(from_start + i);
1710 } else {
1711 int context_index = Smi::cast(probe)->value();
1712 DCHECK(!context->get(context_index)->IsTheHole());
1713 value = context->get(context_index);
1714 }
1715 FixedArray::cast(to)->set(to_start + i, value);
Igor Sheludko 2015/01/30 14:13:29 I would suggest to move casts to FixedArray out of
1716 }
1717
1718 // Copy unmapped actual arguments.
1719 limit = actual - from_start;
1720 for (; i < limit; i++) {
1721 Object* value = arguments->get(from_start + i);
1722 FixedArray::cast(to)->set(to_start + i, value);
1723 }
1724
1725 // Fill holes for "arguments" beyond the length of the actual arguments.
1726 for (i += to_start; i < to->length(); i++) {
1727 FixedArray::cast(to)->set(i, the_hole);
1728 }
1684 } 1729 }
1685 1730
1686 static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) { 1731 static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) {
1687 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store); 1732 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store);
1688 Handle<FixedArrayBase> arguments( 1733 Handle<FixedArrayBase> arguments(
1689 FixedArrayBase::cast(parameter_map->get(1))); 1734 FixedArrayBase::cast(parameter_map->get(1)));
1690 return Max(static_cast<uint32_t>(parameter_map->length() - 2), 1735 return Max(static_cast<uint32_t>(parameter_map->length() - 2),
1691 ForArray(arguments)->GetCapacity(arguments)); 1736 ForArray(arguments)->GetCapacity(arguments));
1692 } 1737 }
1693 1738
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 UNREACHABLE(); 1961 UNREACHABLE();
1917 break; 1962 break;
1918 } 1963 }
1919 1964
1920 array->set_elements(*elms); 1965 array->set_elements(*elms);
1921 array->set_length(Smi::FromInt(number_of_elements)); 1966 array->set_length(Smi::FromInt(number_of_elements));
1922 return array; 1967 return array;
1923 } 1968 }
1924 1969
1925 } } // namespace v8::internal 1970 } } // namespace v8::internal
OLDNEW
« src/builtins.cc ('K') | « src/builtins.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698