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

Side by Side Diff: src/objects.cc

Issue 1496243003: [proxies] Implement Proxy.revocable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments. Created 5 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
« 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 <sstream> 9 #include <sstream>
10 10
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate, 751 MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate,
752 Handle<JSProxy> proxy, 752 Handle<JSProxy> proxy,
753 Handle<Name> name, 753 Handle<Name> name,
754 Handle<Object> receiver, 754 Handle<Object> receiver,
755 LanguageMode language_mode) { 755 LanguageMode language_mode) {
756 Handle<Name> trap_name = isolate->factory()->get_string(); 756 Handle<Name> trap_name = isolate->factory()->get_string();
757 // 1. Assert: IsPropertyKey(P) is true. 757 // 1. Assert: IsPropertyKey(P) is true.
758 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. 758 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
759 Handle<Object> handler(proxy->handler(), isolate); 759 Handle<Object> handler(proxy->handler(), isolate);
760 // 3. If handler is null, throw a TypeError exception. 760 // 3. If handler is null, throw a TypeError exception.
761 // 4. Assert: Type(handler) is Object.
761 if (proxy->IsRevoked()) { 762 if (proxy->IsRevoked()) {
762 THROW_NEW_ERROR(isolate, 763 THROW_NEW_ERROR(isolate,
763 NewTypeError(MessageTemplate::kProxyRevoked, trap_name), 764 NewTypeError(MessageTemplate::kProxyRevoked, trap_name),
764 Object); 765 Object);
765 } 766 }
766 // 4. Assert: Type(handler) is Object.
767 DCHECK(handler->IsJSReceiver());
768 DCHECK(proxy->target()->IsJSReceiver());
769 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. 767 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
770 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 768 Handle<JSReceiver> target(proxy->target(), isolate);
771 // 6. Let trap be ? GetMethod(handler, "get"). 769 // 6. Let trap be ? GetMethod(handler, "get").
772 Handle<Object> trap; 770 Handle<Object> trap;
773 ASSIGN_RETURN_ON_EXCEPTION( 771 ASSIGN_RETURN_ON_EXCEPTION(
774 isolate, trap, 772 isolate, trap,
775 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), Object); 773 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), Object);
776 // 7. If trap is undefined, then 774 // 7. If trap is undefined, then
777 if (trap->IsUndefined()) { 775 if (trap->IsUndefined()) {
778 // 7.a Return target.[[Get]](P, Receiver). 776 // 7.a Return target.[[Get]](P, Receiver).
779 LookupIterator it = 777 LookupIterator it =
780 LookupIterator::PropertyOrElement(isolate, receiver, name, target); 778 LookupIterator::PropertyOrElement(isolate, receiver, name, target);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 object->set_elements(*writable_elems); 948 object->set_elements(*writable_elems);
951 isolate->counters()->cow_arrays_converted()->Increment(); 949 isolate->counters()->cow_arrays_converted()->Increment();
952 return writable_elems; 950 return writable_elems;
953 } 951 }
954 952
955 953
956 // ES6 9.5.1 954 // ES6 9.5.1
957 // static 955 // static
958 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { 956 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) {
959 Isolate* isolate = proxy->GetIsolate(); 957 Isolate* isolate = proxy->GetIsolate();
958 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string();
959
960 // 1. Let handler be the value of the [[ProxyHandler]] internal slot. 960 // 1. Let handler be the value of the [[ProxyHandler]] internal slot.
961 Handle<Object> raw_handler(proxy->handler(), isolate);
962 // 2. If handler is null, throw a TypeError exception. 961 // 2. If handler is null, throw a TypeError exception.
963 // 3. Assert: Type(handler) is Object. 962 // 3. Assert: Type(handler) is Object.
964 if (!raw_handler->IsJSReceiver()) { 963 // 4. Let target be the value of the [[ProxyTarget]] internal slot.
965 // TODO(cbruni): Throw correct error message. 964 if (proxy->IsRevoked()) {
966 THROW_NEW_ERROR( 965 THROW_NEW_ERROR(isolate,
967 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); 966 NewTypeError(MessageTemplate::kProxyRevoked, trap_name),
967 Object);
968 } 968 }
969 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); 969 Handle<JSReceiver> target(proxy->target(), isolate);
970 // 4. Let target be the value of the [[ProxyTarget]] internal slot. 970 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate);
971 // TODO(cbruni): Change target type to JSReceiver by default. 971
972 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
973 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). 972 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf").
974 Handle<Object> trap; 973 Handle<Object> trap;
975 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string();
976 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), 974 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name),
977 Object); 975 Object);
978 // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). 976 // 6. If trap is undefined, then return target.[[GetPrototypeOf]]().
979 if (trap->IsUndefined()) { 977 if (trap->IsUndefined()) {
980 return Object::GetPrototype(isolate, target); 978 return Object::GetPrototype(isolate, target);
981 } 979 }
982 // 7. Let handlerProto be ? Call(trap, handler, «target»). 980 // 7. Let handlerProto be ? Call(trap, handler, «target»).
983 Handle<Object> argv[] = {target}; 981 Handle<Object> argv[] = {target};
984 Handle<Object> handler_proto; 982 Handle<Object> handler_proto;
985 ASSIGN_RETURN_ON_EXCEPTION( 983 ASSIGN_RETURN_ON_EXCEPTION(
(...skipping 20 matching lines...) Expand all
1006 THROW_NEW_ERROR(isolate, 1004 THROW_NEW_ERROR(isolate,
1007 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, 1005 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing,
1008 handler, trap_name), 1006 handler, trap_name),
1009 Object); 1007 Object);
1010 } 1008 }
1011 // 13. Return handlerProto. 1009 // 13. Return handlerProto.
1012 return handler_proto; 1010 return handler_proto;
1013 } 1011 }
1014 1012
1015 1013
1016 bool JSProxy::IsRevoked() const {
1017 // TODO(neis): Decide on how to represent revocation. For now, revocation is
1018 // unsupported.
1019 DCHECK(target()->IsJSReceiver());
1020 DCHECK(handler()->IsJSReceiver());
1021 return false;
1022 }
1023
1024
1025 MaybeHandle<Object> Object::GetPropertyWithAccessor( 1014 MaybeHandle<Object> Object::GetPropertyWithAccessor(
1026 LookupIterator* it, LanguageMode language_mode) { 1015 LookupIterator* it, LanguageMode language_mode) {
1027 Isolate* isolate = it->isolate(); 1016 Isolate* isolate = it->isolate();
1028 Handle<Object> structure = it->GetAccessors(); 1017 Handle<Object> structure = it->GetAccessors();
1029 Handle<Object> receiver = it->GetReceiver(); 1018 Handle<Object> receiver = it->GetReceiver();
1030 1019
1031 // We should never get here to initialize a const with the hole value since a 1020 // We should never get here to initialize a const with the hole value since a
1032 // const declaration would conflict with the getter. 1021 // const declaration would conflict with the getter.
1033 DCHECK(!structure->IsForeign()); 1022 DCHECK(!structure->IsForeign());
1034 1023
(...skipping 3578 matching lines...) Expand 10 before | Expand all | Expand 10 after
4613 } 4602 }
4614 4603
4615 4604
4616 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object, 4605 Handle<Map> JSObject::GetElementsTransitionMap(Handle<JSObject> object,
4617 ElementsKind to_kind) { 4606 ElementsKind to_kind) {
4618 Handle<Map> map(object->map()); 4607 Handle<Map> map(object->map());
4619 return Map::TransitionElementsTo(map, to_kind); 4608 return Map::TransitionElementsTo(map, to_kind);
4620 } 4609 }
4621 4610
4622 4611
4612 void JSProxy::Revoke(Handle<JSProxy> proxy) {
4613 Isolate* isolate = proxy->GetIsolate();
4614 if (!proxy->IsRevoked()) proxy->set_handler(isolate->heap()->null_value());
4615 DCHECK(proxy->IsRevoked());
4616 }
4617
4618
4623 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy, 4619 Maybe<bool> JSProxy::HasProperty(Isolate* isolate, Handle<JSProxy> proxy,
4624 Handle<Name> name) { 4620 Handle<Name> name) {
4625 // 1. (Assert) 4621 // 1. (Assert)
4626 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. 4622 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
4627 Handle<Object> handler(proxy->handler(), isolate); 4623 Handle<Object> handler(proxy->handler(), isolate);
4628 // 3. If handler is null, throw a TypeError exception. 4624 // 3. If handler is null, throw a TypeError exception.
4625 // 4. Assert: Type(handler) is Object.
4629 if (proxy->IsRevoked()) { 4626 if (proxy->IsRevoked()) {
4630 isolate->Throw(*isolate->factory()->NewTypeError( 4627 isolate->Throw(*isolate->factory()->NewTypeError(
4631 MessageTemplate::kProxyRevoked, isolate->factory()->has_string())); 4628 MessageTemplate::kProxyRevoked, isolate->factory()->has_string()));
4632 return Nothing<bool>(); 4629 return Nothing<bool>();
4633 } 4630 }
4634 // 4. Assert: Type(handler) is Object.
4635 DCHECK(handler->IsJSReceiver());
4636 DCHECK(proxy->target()->IsJSReceiver());
4637 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. 4631 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
4638 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 4632 Handle<JSReceiver> target(proxy->target(), isolate);
4639 // 6. Let trap be ? GetMethod(handler, "has"). 4633 // 6. Let trap be ? GetMethod(handler, "has").
4640 Handle<Object> trap; 4634 Handle<Object> trap;
4641 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 4635 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
4642 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), 4636 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler),
4643 isolate->factory()->has_string()), 4637 isolate->factory()->has_string()),
4644 Nothing<bool>()); 4638 Nothing<bool>());
4645 // 7. If trap is undefined, then 4639 // 7. If trap is undefined, then
4646 if (trap->IsUndefined()) { 4640 if (trap->IsUndefined()) {
4647 // 7a. Return target.[[HasProperty]](P). 4641 // 7a. Return target.[[HasProperty]](P).
4648 return JSReceiver::HasProperty(target, name); 4642 return JSReceiver::HasProperty(target, name);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4693 Factory* factory = isolate->factory(); 4687 Factory* factory = isolate->factory();
4694 Handle<String> trap_name = factory->set_string(); 4688 Handle<String> trap_name = factory->set_string();
4695 ShouldThrow should_throw = 4689 ShouldThrow should_throw =
4696 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; 4690 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR;
4697 4691
4698 if (proxy->IsRevoked()) { 4692 if (proxy->IsRevoked()) {
4699 isolate->Throw( 4693 isolate->Throw(
4700 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); 4694 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
4701 return Nothing<bool>(); 4695 return Nothing<bool>();
4702 } 4696 }
4703 4697 Handle<JSReceiver> target(proxy->target(), isolate);
4704 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
4705 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate); 4698 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate);
4706 4699
4707 Handle<Object> trap; 4700 Handle<Object> trap;
4708 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name), 4701 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name),
4709 Nothing<bool>()); 4702 Nothing<bool>());
4710 if (trap->IsUndefined()) { 4703 if (trap->IsUndefined()) {
4711 LookupIterator it = 4704 LookupIterator it =
4712 LookupIterator::PropertyOrElement(isolate, receiver, name, target); 4705 LookupIterator::PropertyOrElement(isolate, receiver, name, target);
4713 return Object::SetSuperProperty(&it, value, language_mode, 4706 return Object::SetSuperProperty(&it, value, language_mode,
4714 Object::MAY_BE_STORE_FROM_KEYED); 4707 Object::MAY_BE_STORE_FROM_KEYED);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4755 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; 4748 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR;
4756 Isolate* isolate = proxy->GetIsolate(); 4749 Isolate* isolate = proxy->GetIsolate();
4757 Factory* factory = isolate->factory(); 4750 Factory* factory = isolate->factory();
4758 Handle<String> trap_name = factory->deleteProperty_string(); 4751 Handle<String> trap_name = factory->deleteProperty_string();
4759 4752
4760 if (proxy->IsRevoked()) { 4753 if (proxy->IsRevoked()) {
4761 isolate->Throw( 4754 isolate->Throw(
4762 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); 4755 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
4763 return Nothing<bool>(); 4756 return Nothing<bool>();
4764 } 4757 }
4765 4758 Handle<JSReceiver> target(proxy->target(), isolate);
4766 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
4767 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate); 4759 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate);
4768 4760
4769 Handle<Object> trap; 4761 Handle<Object> trap;
4770 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name), 4762 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name),
4771 Nothing<bool>()); 4763 Nothing<bool>());
4772 if (trap->IsUndefined()) { 4764 if (trap->IsUndefined()) {
4773 return JSReceiver::DeletePropertyOrElement(target, name, language_mode); 4765 return JSReceiver::DeletePropertyOrElement(target, name, language_mode);
4774 } 4766 }
4775 4767
4776 Handle<Object> trap_result; 4768 Handle<Object> trap_result;
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after
6828 // static 6820 // static
6829 bool JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy, 6821 bool JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy,
6830 Handle<Object> key, PropertyDescriptor* desc, 6822 Handle<Object> key, PropertyDescriptor* desc,
6831 ShouldThrow should_throw) { 6823 ShouldThrow should_throw) {
6832 Handle<String> trap_name = isolate->factory()->defineProperty_string(); 6824 Handle<String> trap_name = isolate->factory()->defineProperty_string();
6833 // 1. Assert: IsPropertyKey(P) is true. 6825 // 1. Assert: IsPropertyKey(P) is true.
6834 DCHECK(key->IsName() || key->IsNumber()); 6826 DCHECK(key->IsName() || key->IsNumber());
6835 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. 6827 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
6836 Handle<Object> handler(proxy->handler(), isolate); 6828 Handle<Object> handler(proxy->handler(), isolate);
6837 // 3. If handler is null, throw a TypeError exception. 6829 // 3. If handler is null, throw a TypeError exception.
6830 // 4. Assert: Type(handler) is Object.
6838 if (proxy->IsRevoked()) { 6831 if (proxy->IsRevoked()) {
6839 isolate->Throw(*isolate->factory()->NewTypeError( 6832 isolate->Throw(*isolate->factory()->NewTypeError(
6840 MessageTemplate::kProxyRevoked, trap_name)); 6833 MessageTemplate::kProxyRevoked, trap_name));
6841 return false; 6834 return false;
6842 } 6835 }
6843 // 4. Assert: Type(handler) is Object.
6844 DCHECK(handler->IsJSReceiver());
6845 // If the handler is not null, the target can't be null either.
6846 DCHECK(proxy->target()->IsJSReceiver());
6847 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. 6836 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
6848 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 6837 Handle<JSReceiver> target(proxy->target(), isolate);
6849 // 6. Let trap be ? GetMethod(handler, "defineProperty"). 6838 // 6. Let trap be ? GetMethod(handler, "defineProperty").
6850 Handle<Object> trap; 6839 Handle<Object> trap;
6851 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 6840 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
6852 isolate, trap, 6841 isolate, trap,
6853 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); 6842 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false);
6854 // 7. If trap is undefined, then: 6843 // 7. If trap is undefined, then:
6855 if (trap->IsUndefined()) { 6844 if (trap->IsUndefined()) {
6856 // 7a. Return target.[[DefineOwnProperty]](P, Desc). 6845 // 7a. Return target.[[DefineOwnProperty]](P, Desc).
6857 return JSReceiver::DefineOwnProperty(isolate, target, key, desc, 6846 return JSReceiver::DefineOwnProperty(isolate, target, key, desc,
6858 should_throw); 6847 should_throw);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
7012 // static 7001 // static
7013 bool JSProxy::GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSProxy> proxy, 7002 bool JSProxy::GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSProxy> proxy,
7014 Handle<Name> name, 7003 Handle<Name> name,
7015 PropertyDescriptor* desc) { 7004 PropertyDescriptor* desc) {
7016 Handle<String> trap_name = 7005 Handle<String> trap_name =
7017 isolate->factory()->getOwnPropertyDescriptor_string(); 7006 isolate->factory()->getOwnPropertyDescriptor_string();
7018 // 1. (Assert) 7007 // 1. (Assert)
7019 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. 7008 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
7020 Handle<Object> handler(proxy->handler(), isolate); 7009 Handle<Object> handler(proxy->handler(), isolate);
7021 // 3. If handler is null, throw a TypeError exception. 7010 // 3. If handler is null, throw a TypeError exception.
7011 // 4. Assert: Type(handler) is Object.
7022 if (proxy->IsRevoked()) { 7012 if (proxy->IsRevoked()) {
7023 isolate->Throw(*isolate->factory()->NewTypeError( 7013 isolate->Throw(*isolate->factory()->NewTypeError(
7024 MessageTemplate::kProxyRevoked, trap_name)); 7014 MessageTemplate::kProxyRevoked, trap_name));
7025 return false; 7015 return false;
7026 } 7016 }
7027 // 4. Assert: Type(handler) is Object.
7028 DCHECK(handler->IsJSReceiver());
7029 // If the handler is not null, the target can't be null either.
7030 DCHECK(proxy->target()->IsJSReceiver());
7031 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. 7017 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
7032 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 7018 Handle<JSReceiver> target(proxy->target(), isolate);
7033 // 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). 7019 // 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
7034 Handle<Object> trap; 7020 Handle<Object> trap;
7035 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 7021 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
7036 isolate, trap, 7022 isolate, trap,
7037 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); 7023 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false);
7038 // 7. If trap is undefined, then 7024 // 7. If trap is undefined, then
7039 if (trap->IsUndefined()) { 7025 if (trap->IsUndefined()) {
7040 // 7a. Return target.[[GetOwnProperty]](P). 7026 // 7a. Return target.[[GetOwnProperty]](P).
7041 return JSReceiver::GetOwnPropertyDescriptor(isolate, target, name, desc); 7027 return JSReceiver::GetOwnPropertyDescriptor(isolate, target, name, desc);
7042 } 7028 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
7270 ShouldThrow should_throw) { 7256 ShouldThrow should_throw) {
7271 Isolate* isolate = proxy->GetIsolate(); 7257 Isolate* isolate = proxy->GetIsolate();
7272 Factory* factory = isolate->factory(); 7258 Factory* factory = isolate->factory();
7273 Handle<String> trap_name = factory->preventExtensions_string(); 7259 Handle<String> trap_name = factory->preventExtensions_string();
7274 7260
7275 if (proxy->IsRevoked()) { 7261 if (proxy->IsRevoked()) {
7276 isolate->Throw( 7262 isolate->Throw(
7277 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); 7263 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
7278 return Nothing<bool>(); 7264 return Nothing<bool>();
7279 } 7265 }
7280 7266 Handle<JSReceiver> target(proxy->target(), isolate);
7281 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
7282 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate); 7267 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate);
7283 7268
7284 Handle<Object> trap; 7269 Handle<Object> trap;
7285 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name), 7270 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name),
7286 Nothing<bool>()); 7271 Nothing<bool>());
7287 if (trap->IsUndefined()) { 7272 if (trap->IsUndefined()) {
7288 return JSReceiver::PreventExtensions(target, should_throw); 7273 return JSReceiver::PreventExtensions(target, should_throw);
7289 } 7274 }
7290 7275
7291 Handle<Object> trap_result; 7276 Handle<Object> trap_result;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
7380 Maybe<bool> JSProxy::IsExtensible(Handle<JSProxy> proxy) { 7365 Maybe<bool> JSProxy::IsExtensible(Handle<JSProxy> proxy) {
7381 Isolate* isolate = proxy->GetIsolate(); 7366 Isolate* isolate = proxy->GetIsolate();
7382 Factory* factory = isolate->factory(); 7367 Factory* factory = isolate->factory();
7383 Handle<String> trap_name = factory->isExtensible_string(); 7368 Handle<String> trap_name = factory->isExtensible_string();
7384 7369
7385 if (proxy->IsRevoked()) { 7370 if (proxy->IsRevoked()) {
7386 isolate->Throw( 7371 isolate->Throw(
7387 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name)); 7372 *factory->NewTypeError(MessageTemplate::kProxyRevoked, trap_name));
7388 return Nothing<bool>(); 7373 return Nothing<bool>();
7389 } 7374 }
7390 7375 Handle<JSReceiver> target(proxy->target(), isolate);
7391 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate);
7392 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate); 7376 Handle<JSReceiver> handler(JSReceiver::cast(proxy->handler()), isolate);
7393 7377
7394 Handle<Object> trap; 7378 Handle<Object> trap;
7395 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name), 7379 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, trap, GetTrap(proxy, trap_name),
7396 Nothing<bool>()); 7380 Nothing<bool>());
7397 if (trap->IsUndefined()) { 7381 if (trap->IsUndefined()) {
7398 return JSReceiver::IsExtensible(target); 7382 return JSReceiver::IsExtensible(target);
7399 } 7383 }
7400 7384
7401 Handle<Object> trap_result; 7385 Handle<Object> trap_result;
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
8289 8273
8290 8274
8291 // ES6 9.5.11 8275 // ES6 9.5.11
8292 // Returns false in case of exception. 8276 // Returns false in case of exception.
8293 // static 8277 // static
8294 bool JSProxy::Enumerate(Isolate* isolate, Handle<JSReceiver> receiver, 8278 bool JSProxy::Enumerate(Isolate* isolate, Handle<JSReceiver> receiver,
8295 Handle<JSProxy> proxy, KeyAccumulator* accumulator) { 8279 Handle<JSProxy> proxy, KeyAccumulator* accumulator) {
8296 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. 8280 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
8297 Handle<Object> handler(proxy->handler(), isolate); 8281 Handle<Object> handler(proxy->handler(), isolate);
8298 // 2. If handler is null, throw a TypeError exception. 8282 // 2. If handler is null, throw a TypeError exception.
8283 // 3. Assert: Type(handler) is Object.
8299 if (proxy->IsRevoked()) { 8284 if (proxy->IsRevoked()) {
8300 isolate->Throw(*isolate->factory()->NewTypeError( 8285 isolate->Throw(*isolate->factory()->NewTypeError(
8301 MessageTemplate::kProxyRevoked, 8286 MessageTemplate::kProxyRevoked,
8302 isolate->factory()->enumerate_string())); 8287 isolate->factory()->enumerate_string()));
8303 return false; 8288 return false;
8304 } 8289 }
8305 // 3. Assert: Type(handler) is Object.
8306 DCHECK(handler->IsJSReceiver());
8307 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. 8290 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
8308 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 8291 Handle<JSReceiver> target(proxy->target(), isolate);
8309 // 5. Let trap be ? GetMethod(handler, "enumerate"). 8292 // 5. Let trap be ? GetMethod(handler, "enumerate").
8310 Handle<Object> trap; 8293 Handle<Object> trap;
8311 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8294 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8312 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), 8295 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler),
8313 isolate->factory()->enumerate_string()), 8296 isolate->factory()->enumerate_string()),
8314 false); 8297 false);
8315 // 6. If trap is undefined, then 8298 // 6. If trap is undefined, then
8316 if (trap->IsUndefined()) { 8299 if (trap->IsUndefined()) {
8317 // 6a. Return target.[[Enumerate]](). 8300 // 6a. Return target.[[Enumerate]]().
8318 return GetKeys_Internal(isolate, receiver, target, INCLUDE_PROTOS, 8301 return GetKeys_Internal(isolate, receiver, target, INCLUDE_PROTOS,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
8395 8378
8396 // ES6 9.5.12 8379 // ES6 9.5.12
8397 // Returns "false" in case of exception. 8380 // Returns "false" in case of exception.
8398 // static 8381 // static
8399 bool JSProxy::OwnPropertyKeys(Isolate* isolate, Handle<JSReceiver> receiver, 8382 bool JSProxy::OwnPropertyKeys(Isolate* isolate, Handle<JSReceiver> receiver,
8400 Handle<JSProxy> proxy, PropertyFilter filter, 8383 Handle<JSProxy> proxy, PropertyFilter filter,
8401 KeyAccumulator* accumulator) { 8384 KeyAccumulator* accumulator) {
8402 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. 8385 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
8403 Handle<Object> handler(proxy->handler(), isolate); 8386 Handle<Object> handler(proxy->handler(), isolate);
8404 // 2. If handler is null, throw a TypeError exception. 8387 // 2. If handler is null, throw a TypeError exception.
8388 // 3. Assert: Type(handler) is Object.
8405 if (proxy->IsRevoked()) { 8389 if (proxy->IsRevoked()) {
8406 isolate->Throw(*isolate->factory()->NewTypeError( 8390 isolate->Throw(*isolate->factory()->NewTypeError(
8407 MessageTemplate::kProxyRevoked, isolate->factory()->ownKeys_string())); 8391 MessageTemplate::kProxyRevoked, isolate->factory()->ownKeys_string()));
8408 return false; 8392 return false;
8409 } 8393 }
8410 // 3. Assert: Type(handler) is Object.
8411 DCHECK(handler->IsJSReceiver());
8412 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. 8394 // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
8413 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 8395 Handle<JSReceiver> target(proxy->target(), isolate);
8414 // 5. Let trap be ? GetMethod(handler, "ownKeys"). 8396 // 5. Let trap be ? GetMethod(handler, "ownKeys").
8415 Handle<Object> trap; 8397 Handle<Object> trap;
8416 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8398 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8417 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler), 8399 isolate, trap, Object::GetMethod(Handle<JSReceiver>::cast(handler),
8418 isolate->factory()->ownKeys_string()), 8400 isolate->factory()->ownKeys_string()),
8419 false); 8401 false);
8420 // 6. If trap is undefined, then 8402 // 6. If trap is undefined, then
8421 if (trap->IsUndefined()) { 8403 if (trap->IsUndefined()) {
8422 // 6a. Return target.[[OwnPropertyKeys]](). 8404 // 6a. Return target.[[OwnPropertyKeys]]().
8423 return GetKeys_Internal(isolate, receiver, target, OWN_ONLY, filter, 8405 return GetKeys_Internal(isolate, receiver, target, OWN_ONLY, filter,
(...skipping 6460 matching lines...) Expand 10 before | Expand all | Expand 10 after
14884 from_javascript, should_throw); 14866 from_javascript, should_throw);
14885 } 14867 }
14886 14868
14887 14869
14888 // ES6: 9.5.2 [[SetPrototypeOf]] (V) 14870 // ES6: 9.5.2 [[SetPrototypeOf]] (V)
14889 // static 14871 // static
14890 Maybe<bool> JSProxy::SetPrototype(Handle<JSProxy> proxy, Handle<Object> value, 14872 Maybe<bool> JSProxy::SetPrototype(Handle<JSProxy> proxy, Handle<Object> value,
14891 bool from_javascript, 14873 bool from_javascript,
14892 ShouldThrow should_throw) { 14874 ShouldThrow should_throw) {
14893 Isolate* isolate = proxy->GetIsolate(); 14875 Isolate* isolate = proxy->GetIsolate();
14894 Handle<JSReceiver> handle;
14895 Handle<Name> trap_name = isolate->factory()->setPrototypeOf_string(); 14876 Handle<Name> trap_name = isolate->factory()->setPrototypeOf_string();
14896 // 1. Assert: Either Type(V) is Object or Type(V) is Null. 14877 // 1. Assert: Either Type(V) is Object or Type(V) is Null.
14897 DCHECK(value->IsJSReceiver() || value->IsNull()); 14878 DCHECK(value->IsJSReceiver() || value->IsNull());
14898 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. 14879 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
14899 Handle<Object> raw_handler(proxy->handler(), isolate); 14880 Handle<Object> handler(proxy->handler(), isolate);
14900 // 3. If handler is null, throw a TypeError exception. 14881 // 3. If handler is null, throw a TypeError exception.
14901 // 4. Assert: Type(handler) is Object. 14882 // 4. Assert: Type(handler) is Object.
14902 if (proxy->IsRevoked()) { 14883 if (proxy->IsRevoked()) {
14903 DCHECK(raw_handler->IsNull()); 14884 isolate->Throw(*isolate->factory()->NewTypeError(
14904 DCHECK(proxy->target()->IsNull()); 14885 MessageTemplate::kProxyRevoked, trap_name));
14905 isolate->Throw(
14906 *isolate->factory()->NewTypeError(MessageTemplate::kProxyRevoked));
14907 return Nothing<bool>(); 14886 return Nothing<bool>();
14908 } 14887 }
14909 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler);
14910 // 5. Let target be the value of the [[ProxyTarget]] internal slot. 14888 // 5. Let target be the value of the [[ProxyTarget]] internal slot.
14911 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); 14889 Handle<JSReceiver> target(proxy->target(), isolate);
14912 // 6. Let trap be ? GetMethod(handler, "getPrototypeOf"). 14890 // 6. Let trap be ? GetMethod(handler, "getPrototypeOf").
14913 Handle<Object> trap; 14891 Handle<Object> trap;
14914 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 14892 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14915 isolate, trap, Object::GetMethod(handler, trap_name), Nothing<bool>()); 14893 isolate, trap,
14894 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name),
14895 Nothing<bool>());
14916 // 7. If trap is undefined, then return target.[[SetPrototypeOf]](). 14896 // 7. If trap is undefined, then return target.[[SetPrototypeOf]]().
14917 if (trap->IsUndefined()) { 14897 if (trap->IsUndefined()) {
14918 return JSReceiver::SetPrototype(target, value, from_javascript, 14898 return JSReceiver::SetPrototype(target, value, from_javascript,
14919 should_throw); 14899 should_throw);
14920 } 14900 }
14921 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, V»)). 14901 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «target, V»)).
14922 Handle<Object> argv[] = {target, value}; 14902 Handle<Object> argv[] = {target, value};
14923 Handle<Object> trap_result; 14903 Handle<Object> trap_result;
14924 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 14904 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
14925 isolate, trap_result, 14905 isolate, trap_result,
(...skipping 4203 matching lines...) Expand 10 before | Expand all | Expand 10 after
19129 if (cell->value() != *new_value) { 19109 if (cell->value() != *new_value) {
19130 cell->set_value(*new_value); 19110 cell->set_value(*new_value);
19131 Isolate* isolate = cell->GetIsolate(); 19111 Isolate* isolate = cell->GetIsolate();
19132 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19112 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19133 isolate, DependentCode::kPropertyCellChangedGroup); 19113 isolate, DependentCode::kPropertyCellChangedGroup);
19134 } 19114 }
19135 } 19115 }
19136 19116
19137 } // namespace internal 19117 } // namespace internal
19138 } // namespace v8 19118 } // 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