| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 v8::GenericNamedPropertySetterCallback setter = | 1670 v8::GenericNamedPropertySetterCallback setter = |
| 1671 v8::ToCData<v8::GenericNamedPropertySetterCallback>( | 1671 v8::ToCData<v8::GenericNamedPropertySetterCallback>( |
| 1672 interceptor->setter()); | 1672 interceptor->setter()); |
| 1673 result = !args.Call(setter, name, value).is_null(); | 1673 result = !args.Call(setter, name, value).is_null(); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(), Nothing<bool>()); | 1676 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(), Nothing<bool>()); |
| 1677 return Just(result); | 1677 return Just(result); |
| 1678 } | 1678 } |
| 1679 | 1679 |
| 1680 Maybe<bool> DefinePropertyWithInterceptorInternal( |
| 1681 LookupIterator* it, Handle<InterceptorInfo> interceptor, |
| 1682 Object::ShouldThrow should_throw, PropertyDescriptor& desc) { |
| 1683 Isolate* isolate = it->isolate(); |
| 1684 // Make sure that the top context does not change when doing callbacks or |
| 1685 // interceptor calls. |
| 1686 AssertNoContextChange ncc(isolate); |
| 1687 |
| 1688 if (interceptor->definer()->IsUndefined(isolate)) return Just(false); |
| 1689 |
| 1690 Handle<JSObject> holder = it->GetHolder<JSObject>(); |
| 1691 bool result; |
| 1692 Handle<Object> receiver = it->GetReceiver(); |
| 1693 if (!receiver->IsJSReceiver()) { |
| 1694 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, receiver, |
| 1695 Object::ConvertReceiver(isolate, receiver), |
| 1696 Nothing<bool>()); |
| 1697 } |
| 1698 PropertyCallbackArguments args(isolate, interceptor->data(), *receiver, |
| 1699 *holder, should_throw); |
| 1700 |
| 1701 std::unique_ptr<v8::PropertyDescriptor> descriptor( |
| 1702 new v8::PropertyDescriptor()); |
| 1703 if (PropertyDescriptor::IsAccessorDescriptor(&desc)) { |
| 1704 descriptor.reset(new v8::PropertyDescriptor( |
| 1705 v8::Utils::ToLocal(desc.get()), v8::Utils::ToLocal(desc.set()))); |
| 1706 } else if (PropertyDescriptor::IsDataDescriptor(&desc)) { |
| 1707 if (desc.has_writable()) { |
| 1708 descriptor.reset(new v8::PropertyDescriptor( |
| 1709 v8::Utils::ToLocal(desc.value()), desc.writable())); |
| 1710 } else { |
| 1711 descriptor.reset( |
| 1712 new v8::PropertyDescriptor(v8::Utils::ToLocal(desc.value()))); |
| 1713 } |
| 1714 } |
| 1715 if (desc.has_enumerable()) { |
| 1716 descriptor->set_enumerable(desc.enumerable()); |
| 1717 } |
| 1718 if (desc.has_configurable()) { |
| 1719 descriptor->set_configurable(desc.configurable()); |
| 1720 } |
| 1721 |
| 1722 if (it->IsElement()) { |
| 1723 uint32_t index = it->index(); |
| 1724 v8::IndexedPropertyDefinerCallback definer = |
| 1725 v8::ToCData<v8::IndexedPropertyDefinerCallback>(interceptor->definer()); |
| 1726 result = !args.Call(definer, index, *descriptor).is_null(); |
| 1727 } else { |
| 1728 Handle<Name> name = it->name(); |
| 1729 DCHECK(!name->IsPrivate()); |
| 1730 |
| 1731 if (name->IsSymbol() && !interceptor->can_intercept_symbols()) { |
| 1732 return Just(false); |
| 1733 } |
| 1734 |
| 1735 v8::GenericNamedPropertyDefinerCallback definer = |
| 1736 v8::ToCData<v8::GenericNamedPropertyDefinerCallback>( |
| 1737 interceptor->definer()); |
| 1738 result = !args.Call(definer, name, *descriptor).is_null(); |
| 1739 } |
| 1740 |
| 1741 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(), Nothing<bool>()); |
| 1742 return Just(result); |
| 1743 } |
| 1744 |
| 1680 } // namespace | 1745 } // namespace |
| 1681 | 1746 |
| 1682 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( | 1747 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( |
| 1683 LookupIterator* it) { | 1748 LookupIterator* it) { |
| 1684 Isolate* isolate = it->isolate(); | 1749 Isolate* isolate = it->isolate(); |
| 1685 Handle<JSObject> checked = it->GetHolder<JSObject>(); | 1750 Handle<JSObject> checked = it->GetHolder<JSObject>(); |
| 1686 Handle<InterceptorInfo> interceptor = | 1751 Handle<InterceptorInfo> interceptor = |
| 1687 it->GetInterceptorForFailedAccessCheck(); | 1752 it->GetInterceptorForFailedAccessCheck(); |
| 1688 if (interceptor.is_null()) { | 1753 if (interceptor.is_null()) { |
| 1689 while (AllCanRead(it)) { | 1754 while (AllCanRead(it)) { |
| (...skipping 4838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6528 // Deal with access checks first. | 6593 // Deal with access checks first. |
| 6529 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6594 if (it.state() == LookupIterator::ACCESS_CHECK) { |
| 6530 if (!it.HasAccess()) { | 6595 if (!it.HasAccess()) { |
| 6531 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); | 6596 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
| 6532 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); | 6597 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
| 6533 return Just(true); | 6598 return Just(true); |
| 6534 } | 6599 } |
| 6535 it.Next(); | 6600 it.Next(); |
| 6536 } | 6601 } |
| 6537 | 6602 |
| 6603 // Handle interceptor |
| 6604 if (it.state() == LookupIterator::INTERCEPTOR) { |
| 6605 Handle<Map> store_target_map; |
| 6606 if (it.GetReceiver()->IsJSObject()) { |
| 6607 store_target_map = handle(it.GetStoreTarget()->map(), it.isolate()); |
| 6608 } |
| 6609 if (it.HolderIsReceiverOrHiddenPrototype()) { |
| 6610 Maybe<bool> result = DefinePropertyWithInterceptorInternal( |
| 6611 &it, it.GetInterceptor(), should_throw, *desc); |
| 6612 if (result.IsNothing() || result.FromJust()) { |
| 6613 return result; |
| 6614 } |
| 6615 // Interceptor modified the store target but failed to set the |
| 6616 // property. |
| 6617 if (!store_target_map.is_null() && |
| 6618 *store_target_map != it.GetStoreTarget()->map()) { |
| 6619 it.isolate()->PushStackTraceAndDie( |
| 6620 0xabababaa, v8::ToCData<void*>(it.GetInterceptor()->setter()), |
| 6621 nullptr, 0xabababab); |
| 6622 } |
| 6623 Utils::ApiCheck(store_target_map.is_null() || |
| 6624 *store_target_map == it.GetStoreTarget()->map(), |
| 6625 it.IsElement() ? "v8::IndexedPropertySetterCallback" |
| 6626 : "v8::NamedPropertySetterCallback", |
| 6627 "Interceptor silently changed store target."); |
| 6628 } |
| 6629 } |
| 6630 |
| 6538 return OrdinaryDefineOwnProperty(&it, desc, should_throw); | 6631 return OrdinaryDefineOwnProperty(&it, desc, should_throw); |
| 6539 } | 6632 } |
| 6540 | 6633 |
| 6541 | 6634 |
| 6542 // ES6 9.1.6.1 | 6635 // ES6 9.1.6.1 |
| 6543 // static | 6636 // static |
| 6544 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it, | 6637 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it, |
| 6545 PropertyDescriptor* desc, | 6638 PropertyDescriptor* desc, |
| 6546 ShouldThrow should_throw) { | 6639 ShouldThrow should_throw) { |
| 6547 Isolate* isolate = it->isolate(); | 6640 Isolate* isolate = it->isolate(); |
| (...skipping 12790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19338 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, | 19431 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, |
| 19339 PrototypeIterator::END_AT_NULL); | 19432 PrototypeIterator::END_AT_NULL); |
| 19340 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { | 19433 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { |
| 19341 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; | 19434 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; |
| 19342 } | 19435 } |
| 19343 return false; | 19436 return false; |
| 19344 } | 19437 } |
| 19345 | 19438 |
| 19346 } // namespace internal | 19439 } // namespace internal |
| 19347 } // namespace v8 | 19440 } // namespace v8 |
| OLD | NEW |