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

Side by Side Diff: src/objects.cc

Issue 2303533004: Revert of [api] Add interceptor for defineProperty(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@DefineProperty
Patch Set: Created 4 years, 3 months 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
1745 } // namespace 1680 } // namespace
1746 1681
1747 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( 1682 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck(
1748 LookupIterator* it) { 1683 LookupIterator* it) {
1749 Isolate* isolate = it->isolate(); 1684 Isolate* isolate = it->isolate();
1750 Handle<JSObject> checked = it->GetHolder<JSObject>(); 1685 Handle<JSObject> checked = it->GetHolder<JSObject>();
1751 Handle<InterceptorInfo> interceptor = 1686 Handle<InterceptorInfo> interceptor =
1752 it->GetInterceptorForFailedAccessCheck(); 1687 it->GetInterceptorForFailedAccessCheck();
1753 if (interceptor.is_null()) { 1688 if (interceptor.is_null()) {
1754 while (AllCanRead(it)) { 1689 while (AllCanRead(it)) {
(...skipping 4837 matching lines...) Expand 10 before | Expand all | Expand 10 after
6592 6527
6593 // Deal with access checks first. 6528 // Deal with access checks first.
6594 if (it.state() == LookupIterator::ACCESS_CHECK) { 6529 if (it.state() == LookupIterator::ACCESS_CHECK) {
6595 if (!it.HasAccess()) { 6530 if (!it.HasAccess()) {
6596 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); 6531 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>());
6597 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); 6532 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>());
6598 return Just(true); 6533 return Just(true);
6599 } 6534 }
6600 it.Next(); 6535 it.Next();
6601 } 6536 }
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 it.Next();
6630 }
6631 6537
6632 return OrdinaryDefineOwnProperty(&it, desc, should_throw); 6538 return OrdinaryDefineOwnProperty(&it, desc, should_throw);
6633 } 6539 }
6634 6540
6635 6541
6636 // ES6 9.1.6.1 6542 // ES6 9.1.6.1
6637 // static 6543 // static
6638 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it, 6544 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
6639 PropertyDescriptor* desc, 6545 PropertyDescriptor* desc,
6640 ShouldThrow should_throw) { 6546 ShouldThrow should_throw) {
(...skipping 12791 matching lines...) Expand 10 before | Expand all | Expand 10 after
19432 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 19338 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
19433 PrototypeIterator::END_AT_NULL); 19339 PrototypeIterator::END_AT_NULL);
19434 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 19340 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
19435 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 19341 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
19436 } 19342 }
19437 return false; 19343 return false;
19438 } 19344 }
19439 19345
19440 } // namespace internal 19346 } // namespace internal
19441 } // namespace v8 19347 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698