| OLD | NEW |
| 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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 851 |
| 852 | 852 |
| 853 // ES6 9.5.1 | 853 // ES6 9.5.1 |
| 854 // static | 854 // static |
| 855 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { | 855 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { |
| 856 Isolate* isolate = proxy->GetIsolate(); | 856 Isolate* isolate = proxy->GetIsolate(); |
| 857 // 1. Let handler be the value of the [[ProxyHandler]] internal slot. | 857 // 1. Let handler be the value of the [[ProxyHandler]] internal slot. |
| 858 Handle<Object> raw_handler(proxy->handler(), isolate); | 858 Handle<Object> raw_handler(proxy->handler(), isolate); |
| 859 // 2. If handler is null, throw a TypeError exception. | 859 // 2. If handler is null, throw a TypeError exception. |
| 860 // 3. Assert: Type(handler) is Object. | 860 // 3. Assert: Type(handler) is Object. |
| 861 if (!raw_handler->IsSpecObject()) { | 861 if (!raw_handler->IsJSReceiver()) { |
| 862 // TODO(cbruni): Throw correct error message. | 862 // TODO(cbruni): Throw correct error message. |
| 863 THROW_NEW_ERROR( | 863 THROW_NEW_ERROR( |
| 864 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); | 864 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); |
| 865 } | 865 } |
| 866 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); | 866 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); |
| 867 // 4. Let target be the value of the [[ProxyTarget]] internal slot. | 867 // 4. Let target be the value of the [[ProxyTarget]] internal slot. |
| 868 // TODO(cbruni): Change target type to JSReceiver by default. | 868 // TODO(cbruni): Change target type to JSReceiver by default. |
| 869 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | 869 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
| 870 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). | 870 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). |
| 871 Handle<Object> trap; | 871 Handle<Object> trap; |
| 872 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string(); | 872 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string(); |
| 873 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), | 873 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), |
| 874 Object); | 874 Object); |
| 875 // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). | 875 // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). |
| 876 if (trap->IsUndefined()) { | 876 if (trap->IsUndefined()) { |
| 877 return Object::GetPrototype(isolate, target); | 877 return Object::GetPrototype(isolate, target); |
| 878 } | 878 } |
| 879 // 7. Let handlerProto be ? Call(trap, handler, «target»). | 879 // 7. Let handlerProto be ? Call(trap, handler, «target»). |
| 880 Handle<Object> argv[] = {target}; | 880 Handle<Object> argv[] = {target}; |
| 881 Handle<Object> handler_proto; | 881 Handle<Object> handler_proto; |
| 882 ASSIGN_RETURN_ON_EXCEPTION( | 882 ASSIGN_RETURN_ON_EXCEPTION( |
| 883 isolate, handler_proto, | 883 isolate, handler_proto, |
| 884 Execution::Call(isolate, trap, handler, arraysize(argv), argv), Object); | 884 Execution::Call(isolate, trap, handler, arraysize(argv), argv), Object); |
| 885 // 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError. | 885 // 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError. |
| 886 if (!(handler_proto->IsSpecObject() || handler_proto->IsNull())) { | 886 if (!(handler_proto->IsJSReceiver() || handler_proto->IsNull())) { |
| 887 THROW_NEW_ERROR(isolate, | 887 THROW_NEW_ERROR(isolate, |
| 888 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, | 888 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, |
| 889 handler, trap_name), | 889 handler, trap_name), |
| 890 Object); | 890 Object); |
| 891 } | 891 } |
| 892 // 9. Let extensibleTarget be ? IsExtensible(target). | 892 // 9. Let extensibleTarget be ? IsExtensible(target). |
| 893 Maybe<bool> is_extensible = JSReceiver::IsExtensible(target); | 893 Maybe<bool> is_extensible = JSReceiver::IsExtensible(target); |
| 894 if (is_extensible.IsNothing()) return MaybeHandle<Object>(); | 894 if (is_extensible.IsNothing()) return MaybeHandle<Object>(); |
| 895 // 10. If extensibleTarget is true, return handlerProto. | 895 // 10. If extensibleTarget is true, return handlerProto. |
| 896 if (is_extensible.FromJust()) return handler_proto; | 896 if (is_extensible.FromJust()) return handler_proto; |
| (...skipping 5182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6079 return Object::ToString(isolate, key); | 6079 return Object::ToString(isolate, key); |
| 6080 } | 6080 } |
| 6081 | 6081 |
| 6082 | 6082 |
| 6083 // ES6 19.1.2.4 | 6083 // ES6 19.1.2.4 |
| 6084 // static | 6084 // static |
| 6085 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, | 6085 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, |
| 6086 Handle<Object> key, | 6086 Handle<Object> key, |
| 6087 Handle<Object> attributes) { | 6087 Handle<Object> attributes) { |
| 6088 // 1. If Type(O) is not Object, throw a TypeError exception. | 6088 // 1. If Type(O) is not Object, throw a TypeError exception. |
| 6089 if (!object->IsSpecObject()) { | 6089 if (!object->IsJSReceiver()) { |
| 6090 Handle<String> fun_name = | 6090 Handle<String> fun_name = |
| 6091 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); | 6091 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); |
| 6092 THROW_NEW_ERROR_RETURN_FAILURE( | 6092 THROW_NEW_ERROR_RETURN_FAILURE( |
| 6093 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); | 6093 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
| 6094 } | 6094 } |
| 6095 // 2. Let key be ToPropertyKey(P). | 6095 // 2. Let key be ToPropertyKey(P). |
| 6096 // 3. ReturnIfAbrupt(key). | 6096 // 3. ReturnIfAbrupt(key). |
| 6097 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); | 6097 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); |
| 6098 // 4. Let desc be ToPropertyDescriptor(Attributes). | 6098 // 4. Let desc be ToPropertyDescriptor(Attributes). |
| 6099 // 5. ReturnIfAbrupt(desc). | 6099 // 5. ReturnIfAbrupt(desc). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6110 // 8. Return O. | 6110 // 8. Return O. |
| 6111 return *object; | 6111 return *object; |
| 6112 } | 6112 } |
| 6113 | 6113 |
| 6114 | 6114 |
| 6115 // ES6 19.1.2.3.1 | 6115 // ES6 19.1.2.3.1 |
| 6116 // static | 6116 // static |
| 6117 Object* JSReceiver::DefineProperties(Isolate* isolate, Handle<Object> object, | 6117 Object* JSReceiver::DefineProperties(Isolate* isolate, Handle<Object> object, |
| 6118 Handle<Object> properties) { | 6118 Handle<Object> properties) { |
| 6119 // 1. If Type(O) is not Object, throw a TypeError exception. | 6119 // 1. If Type(O) is not Object, throw a TypeError exception. |
| 6120 if (!object->IsSpecObject()) { | 6120 if (!object->IsJSReceiver()) { |
| 6121 Handle<String> fun_name = | 6121 Handle<String> fun_name = |
| 6122 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); | 6122 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); |
| 6123 THROW_NEW_ERROR_RETURN_FAILURE( | 6123 THROW_NEW_ERROR_RETURN_FAILURE( |
| 6124 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); | 6124 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
| 6125 } | 6125 } |
| 6126 // 2. Let props be ToObject(Properties). | 6126 // 2. Let props be ToObject(Properties). |
| 6127 // 3. ReturnIfAbrupt(props). | 6127 // 3. ReturnIfAbrupt(props). |
| 6128 Handle<JSReceiver> props; | 6128 Handle<JSReceiver> props; |
| 6129 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { | 6129 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { |
| 6130 THROW_NEW_ERROR_RETURN_FAILURE( | 6130 THROW_NEW_ERROR_RETURN_FAILURE( |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6791 Handle<Object> handler(proxy->handler(), isolate); | 6791 Handle<Object> handler(proxy->handler(), isolate); |
| 6792 // 3. If handler is null, throw a TypeError exception. | 6792 // 3. If handler is null, throw a TypeError exception. |
| 6793 if (proxy->IsRevoked()) { | 6793 if (proxy->IsRevoked()) { |
| 6794 isolate->Throw(*isolate->factory()->NewTypeError( | 6794 isolate->Throw(*isolate->factory()->NewTypeError( |
| 6795 MessageTemplate::kProxyRevoked, trap_name)); | 6795 MessageTemplate::kProxyRevoked, trap_name)); |
| 6796 return false; | 6796 return false; |
| 6797 } | 6797 } |
| 6798 // 4. Assert: Type(handler) is Object. | 6798 // 4. Assert: Type(handler) is Object. |
| 6799 DCHECK(handler->IsJSReceiver()); | 6799 DCHECK(handler->IsJSReceiver()); |
| 6800 // If the handler is not null, the target can't be null either. | 6800 // If the handler is not null, the target can't be null either. |
| 6801 DCHECK(proxy->target()->IsSpecObject()); | 6801 DCHECK(proxy->target()->IsJSReceiver()); |
| 6802 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 6802 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
| 6803 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | 6803 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); |
| 6804 // 6. Let trap be ? GetMethod(handler, "defineProperty"). | 6804 // 6. Let trap be ? GetMethod(handler, "defineProperty"). |
| 6805 Handle<Object> trap; | 6805 Handle<Object> trap; |
| 6806 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 6806 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 6807 isolate, trap, | 6807 isolate, trap, |
| 6808 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); | 6808 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); |
| 6809 // 7. If trap is undefined, then: | 6809 // 7. If trap is undefined, then: |
| 6810 if (trap->IsUndefined()) { | 6810 if (trap->IsUndefined()) { |
| 6811 // 7a. Return target.[[DefineOwnProperty]](P, Desc). | 6811 // 7a. Return target.[[DefineOwnProperty]](P, Desc). |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6974 // 1. (Assert) | 6974 // 1. (Assert) |
| 6975 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 6975 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
| 6976 Handle<Object> handler(proxy->handler(), isolate); | 6976 Handle<Object> handler(proxy->handler(), isolate); |
| 6977 // 3. If handler is null, throw a TypeError exception. | 6977 // 3. If handler is null, throw a TypeError exception. |
| 6978 if (proxy->IsRevoked()) { | 6978 if (proxy->IsRevoked()) { |
| 6979 isolate->Throw(*isolate->factory()->NewTypeError( | 6979 isolate->Throw(*isolate->factory()->NewTypeError( |
| 6980 MessageTemplate::kProxyRevoked, trap_name)); | 6980 MessageTemplate::kProxyRevoked, trap_name)); |
| 6981 return false; | 6981 return false; |
| 6982 } | 6982 } |
| 6983 // 4. Assert: Type(handler) is Object. | 6983 // 4. Assert: Type(handler) is Object. |
| 6984 DCHECK(handler->IsSpecObject()); | 6984 DCHECK(handler->IsJSReceiver()); |
| 6985 // If the handler is not null, the target can't be null either. | 6985 // If the handler is not null, the target can't be null either. |
| 6986 DCHECK(it->GetHolder<JSProxy>()->target()->IsSpecObject()); | 6986 DCHECK(it->GetHolder<JSProxy>()->target()->IsJSReceiver()); |
| 6987 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 6987 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
| 6988 Handle<JSReceiver> target( | 6988 Handle<JSReceiver> target( |
| 6989 JSReceiver::cast(it->GetHolder<JSProxy>()->target()), isolate); | 6989 JSReceiver::cast(it->GetHolder<JSProxy>()->target()), isolate); |
| 6990 // 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). | 6990 // 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). |
| 6991 Handle<Object> trap; | 6991 Handle<Object> trap; |
| 6992 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 6992 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 6993 isolate, trap, | 6993 isolate, trap, |
| 6994 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); | 6994 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), false); |
| 6995 // 7. If trap is undefined, then | 6995 // 7. If trap is undefined, then |
| 6996 if (trap->IsUndefined()) { | 6996 if (trap->IsUndefined()) { |
| 6997 // 7a. Return target.[[GetOwnProperty]](P). | 6997 // 7a. Return target.[[GetOwnProperty]](P). |
| 6998 return JSReceiver::GetOwnPropertyDescriptor(isolate, target, property_name, | 6998 return JSReceiver::GetOwnPropertyDescriptor(isolate, target, property_name, |
| 6999 desc); | 6999 desc); |
| 7000 } | 7000 } |
| 7001 // 8. Let trapResultObj be ? Call(trap, handler, «target, P»). | 7001 // 8. Let trapResultObj be ? Call(trap, handler, «target, P»). |
| 7002 Handle<Object> trap_result_obj; | 7002 Handle<Object> trap_result_obj; |
| 7003 Handle<Object> args[] = {target, property_name}; | 7003 Handle<Object> args[] = {target, property_name}; |
| 7004 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 7004 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 7005 isolate, trap_result_obj, | 7005 isolate, trap_result_obj, |
| 7006 Execution::Call(isolate, trap, handler, arraysize(args), args), false); | 7006 Execution::Call(isolate, trap, handler, arraysize(args), args), false); |
| 7007 // 9. If Type(trapResultObj) is neither Object nor Undefined, throw a | 7007 // 9. If Type(trapResultObj) is neither Object nor Undefined, throw a |
| 7008 // TypeError exception. | 7008 // TypeError exception. |
| 7009 if (!trap_result_obj->IsSpecObject() && !trap_result_obj->IsUndefined()) { | 7009 if (!trap_result_obj->IsJSReceiver() && !trap_result_obj->IsUndefined()) { |
| 7010 isolate->Throw(*isolate->factory()->NewTypeError( | 7010 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7011 MessageTemplate::kProxyHandlerReturned, handler, trap_result_obj, | 7011 MessageTemplate::kProxyHandlerReturned, handler, trap_result_obj, |
| 7012 property_name)); | 7012 property_name)); |
| 7013 return false; | 7013 return false; |
| 7014 } | 7014 } |
| 7015 // 10. Let targetDesc be ? target.[[GetOwnProperty]](P). | 7015 // 10. Let targetDesc be ? target.[[GetOwnProperty]](P). |
| 7016 PropertyDescriptor target_desc; | 7016 PropertyDescriptor target_desc; |
| 7017 JSReceiver::GetOwnPropertyDescriptor(isolate, target, property_name, | 7017 JSReceiver::GetOwnPropertyDescriptor(isolate, target, property_name, |
| 7018 &target_desc); | 7018 &target_desc); |
| 7019 if (isolate->has_pending_exception()) return false; | 7019 if (isolate->has_pending_exception()) return false; |
| (...skipping 11969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18989 if (cell->value() != *new_value) { | 18989 if (cell->value() != *new_value) { |
| 18990 cell->set_value(*new_value); | 18990 cell->set_value(*new_value); |
| 18991 Isolate* isolate = cell->GetIsolate(); | 18991 Isolate* isolate = cell->GetIsolate(); |
| 18992 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18992 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18993 isolate, DependentCode::kPropertyCellChangedGroup); | 18993 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18994 } | 18994 } |
| 18995 } | 18995 } |
| 18996 | 18996 |
| 18997 } // namespace internal | 18997 } // namespace internal |
| 18998 } // namespace v8 | 18998 } // namespace v8 |
| OLD | NEW |