OLD | NEW |
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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 if (!map->OnlyHasSimpleProperties()) return Just(false); | 1602 if (!map->OnlyHasSimpleProperties()) return Just(false); |
1603 | 1603 |
1604 Handle<JSObject> from = Handle<JSObject>::cast(next_source); | 1604 Handle<JSObject> from = Handle<JSObject>::cast(next_source); |
1605 if (from->elements() != isolate->heap()->empty_fixed_array()) { | 1605 if (from->elements() != isolate->heap()->empty_fixed_array()) { |
1606 return Just(false); | 1606 return Just(false); |
1607 } | 1607 } |
1608 | 1608 |
1609 Handle<DescriptorArray> descriptors(map->instance_descriptors(), isolate); | 1609 Handle<DescriptorArray> descriptors(map->instance_descriptors(), isolate); |
1610 int length = map->NumberOfOwnDescriptors(); | 1610 int length = map->NumberOfOwnDescriptors(); |
1611 | 1611 |
| 1612 bool stable = true; |
| 1613 |
1612 for (int i = 0; i < length; i++) { | 1614 for (int i = 0; i < length; i++) { |
1613 Handle<Name> next_key(descriptors->GetKey(i), isolate); | 1615 Handle<Name> next_key(descriptors->GetKey(i), isolate); |
1614 Handle<Object> prop_value; | 1616 Handle<Object> prop_value; |
1615 // Directly decode from the descriptor array if |from| did not change shape. | 1617 // Directly decode from the descriptor array if |from| did not change shape. |
1616 if (from->map() == *map) { | 1618 if (stable) { |
1617 PropertyDetails details = descriptors->GetDetails(i); | 1619 PropertyDetails details = descriptors->GetDetails(i); |
1618 if (!details.IsEnumerable()) continue; | 1620 if (!details.IsEnumerable()) continue; |
1619 if (details.kind() == kData) { | 1621 if (details.kind() == kData) { |
1620 if (details.location() == kDescriptor) { | 1622 if (details.location() == kDescriptor) { |
1621 prop_value = handle(descriptors->GetValue(i), isolate); | 1623 prop_value = handle(descriptors->GetValue(i), isolate); |
1622 } else { | 1624 } else { |
1623 Representation representation = details.representation(); | 1625 Representation representation = details.representation(); |
1624 FieldIndex index = FieldIndex::ForDescriptor(*map, i); | 1626 FieldIndex index = FieldIndex::ForDescriptor(*map, i); |
1625 prop_value = JSObject::FastPropertyAt(from, representation, index); | 1627 prop_value = JSObject::FastPropertyAt(from, representation, index); |
1626 } | 1628 } |
1627 } else { | 1629 } else { |
1628 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, | 1630 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, |
1629 Object::GetProperty(from, next_key), | 1631 Object::GetProperty(from, next_key), |
1630 Nothing<bool>()); | 1632 Nothing<bool>()); |
| 1633 stable = from->map() == *map; |
1631 } | 1634 } |
1632 } else { | 1635 } else { |
1633 // If the map did change, do a slower lookup. We are still guaranteed that | 1636 // If the map did change, do a slower lookup. We are still guaranteed that |
1634 // the object has a simple shape, and that the key is a name. | 1637 // the object has a simple shape, and that the key is a name. |
1635 LookupIterator it(from, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 1638 LookupIterator it(from, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
1636 if (!it.IsFound()) continue; | 1639 if (!it.IsFound()) continue; |
1637 DCHECK(it.state() == LookupIterator::DATA || | 1640 DCHECK(it.state() == LookupIterator::DATA || |
1638 it.state() == LookupIterator::ACCESSOR); | 1641 it.state() == LookupIterator::ACCESSOR); |
1639 if (!it.IsEnumerable()) continue; | 1642 if (!it.IsEnumerable()) continue; |
1640 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 1643 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
1641 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); | 1644 isolate, prop_value, Object::GetProperty(&it), Nothing<bool>()); |
1642 } | 1645 } |
1643 Handle<Object> status; | 1646 LookupIterator it(to, next_key); |
1644 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 1647 bool call_to_js = it.IsFound() && it.state() != LookupIterator::DATA; |
1645 isolate, status, | 1648 Maybe<bool> result = Object::SetProperty( |
1646 Object::SetProperty(to, next_key, prop_value, STRICT, | 1649 &it, prop_value, STRICT, Object::CERTAINLY_NOT_STORE_FROM_KEYED); |
1647 Object::CERTAINLY_NOT_STORE_FROM_KEYED), | 1650 if (result.IsNothing()) return result; |
1648 Nothing<bool>()); | 1651 if (stable && call_to_js) stable = from->map() == *map; |
1649 } | 1652 } |
1650 | 1653 |
1651 return Just(true); | 1654 return Just(true); |
1652 } | 1655 } |
1653 | 1656 |
1654 } // namespace | 1657 } // namespace |
1655 | 1658 |
1656 // ES6 19.1.2.1 Object.assign | 1659 // ES6 19.1.2.1 Object.assign |
1657 BUILTIN(ObjectAssign) { | 1660 BUILTIN(ObjectAssign) { |
1658 HandleScope scope(isolate); | 1661 HandleScope scope(isolate); |
(...skipping 2900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4559 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4562 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4560 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4563 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4561 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4564 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4562 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4565 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4563 #undef DEFINE_BUILTIN_ACCESSOR_C | 4566 #undef DEFINE_BUILTIN_ACCESSOR_C |
4564 #undef DEFINE_BUILTIN_ACCESSOR_A | 4567 #undef DEFINE_BUILTIN_ACCESSOR_A |
4565 | 4568 |
4566 | 4569 |
4567 } // namespace internal | 4570 } // namespace internal |
4568 } // namespace v8 | 4571 } // namespace v8 |
OLD | NEW |