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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate); | 838 Handle<FixedArray> elems(FixedArray::cast(object->elements()), isolate); |
839 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; | 839 if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; |
840 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap( | 840 Handle<FixedArray> writable_elems = isolate->factory()->CopyFixedArrayWithMap( |
841 elems, isolate->factory()->fixed_array_map()); | 841 elems, isolate->factory()->fixed_array_map()); |
842 object->set_elements(*writable_elems); | 842 object->set_elements(*writable_elems); |
843 isolate->counters()->cow_arrays_converted()->Increment(); | 843 isolate->counters()->cow_arrays_converted()->Increment(); |
844 return writable_elems; | 844 return writable_elems; |
845 } | 845 } |
846 | 846 |
847 | 847 |
848 // static | |
Jakob Kummerow
2015/11/12 12:04:24
Please also mention the spec chapter:
// ES6 9.5.1
| |
849 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { | |
850 Isolate* isolate = proxy->GetIsolate(); | |
851 // 1. Let handler be the value of the [[ProxyHandler]] internal slot. | |
852 Handle<Object> raw_handler(proxy->handler(), isolate); | |
853 // 2. If handler is null, throw a TypeError exception. | |
Jakob Kummerow
2015/11/12 12:04:24
nit: drop a space before "If"
| |
854 // 3. Assert: Type(handler) is Object. | |
855 if (!raw_handler->IsSpecObject()) { | |
856 // TODO(cbruni): throw correct error message | |
Jakob Kummerow
2015/11/12 12:04:24
nit: comments, including TODOs, should begin capit
| |
857 THROW_NEW_ERROR( | |
858 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); | |
859 } | |
860 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); | |
861 // 4. Let target be the value of the [[ProxyTarget]] internal slot. | |
862 // TODO(cbruni): Probably change the type of target to JSObject directly | |
Jakob Kummerow
2015/11/12 12:04:24
Can a target not be another Proxy? :-)
Camillo Bruni
2015/11/12 20:20:55
changed to JSReceiver
| |
863 Handle<JSObject> target(JSObject::cast(proxy->target()), isolate); | |
864 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). | |
865 Handle<Object> trap; | |
866 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string(); | |
867 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), | |
868 Object); | |
869 // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). | |
870 if (trap->IsUndefined()) { | |
871 return Object::GetPrototype(isolate, target); | |
872 } | |
873 // 7. Let handlerProto be ? Call(trap, handler, «target»). | |
874 Handle<Object> argv[] = {target}; | |
875 Handle<Object> handler_proto; | |
876 ASSIGN_RETURN_ON_EXCEPTION( | |
877 isolate, handler_proto, | |
878 Execution::Call(isolate, trap, handler, arraysize(argv), argv), Object); | |
879 // 8. If Type(handlerProto) is either Object nor Null, throw a TypeError. | |
Jakob Kummerow
2015/11/12 12:04:24
s/either/neither/
| |
880 if (!handler_proto->IsSpecObject() || !handler_proto->IsNull()) { | |
Jakob Kummerow
2015/11/12 12:04:24
s/||/&&/
| |
881 THROW_NEW_ERROR(isolate, | |
882 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, | |
883 handler, trap_name), | |
884 Object); | |
885 } | |
886 // 9. Let extensibleTarget be ? IsExtensible(target). | |
887 // 10. If extensibleTarget is true, return handlerProto. | |
888 if (JSObject::IsExtensible(target)) return handler_proto; | |
889 // 11. Let targetProto be ? target.[[GetPrototypeOf]](). | |
890 Handle<Object> target_proto; | |
891 ASSIGN_RETURN_ON_EXCEPTION(isolate, handler_proto, | |
892 Object::GetPrototype(isolate, target), Object); | |
893 // 12. If SameValue(handlerProto, targetProto) is false, throw a TypeError. | |
894 if (!handler_proto->SameValue(*target_proto)) { | |
895 THROW_NEW_ERROR(isolate, | |
896 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, | |
897 handler, trap_name), | |
898 Object); | |
899 } | |
900 // 13. Return handlerProto. | |
901 return handler_proto; | |
902 } | |
903 | |
Jakob Kummerow
2015/11/12 12:04:24
nit: two blank lines
| |
848 MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy, | 904 MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy, |
849 Handle<Object> receiver, | 905 Handle<Object> receiver, |
850 Handle<Name> name) { | 906 Handle<Name> name) { |
851 Isolate* isolate = proxy->GetIsolate(); | 907 Isolate* isolate = proxy->GetIsolate(); |
852 | 908 |
853 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 909 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
854 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | 910 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
855 | 911 |
856 Handle<Object> args[] = { receiver, name }; | 912 Handle<Object> args[] = { receiver, name }; |
857 return CallTrap( | 913 return CallTrap( |
(...skipping 7196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8054 } | 8110 } |
8055 | 8111 |
8056 return result; | 8112 return result; |
8057 } | 8113 } |
8058 | 8114 |
8059 | 8115 |
8060 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { | 8116 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { |
8061 Handle<Map> result = RawCopy(map, map->instance_size()); | 8117 Handle<Map> result = RawCopy(map, map->instance_size()); |
8062 | 8118 |
8063 // Please note instance_type and instance_size are set when allocated. | 8119 // Please note instance_type and instance_size are set when allocated. |
8064 result->SetInObjectProperties(map->GetInObjectProperties()); | 8120 if (map->IsJSObjectMap()) { |
8065 result->set_unused_property_fields(map->unused_property_fields()); | 8121 result->SetInObjectProperties(map->GetInObjectProperties()); |
8066 | 8122 result->set_unused_property_fields(map->unused_property_fields()); |
8123 } | |
8067 result->ClearCodeCache(map->GetHeap()); | 8124 result->ClearCodeCache(map->GetHeap()); |
8068 map->NotifyLeafMapLayoutChange(); | 8125 map->NotifyLeafMapLayoutChange(); |
8069 return result; | 8126 return result; |
8070 } | 8127 } |
8071 | 8128 |
8072 | 8129 |
8073 Handle<Map> Map::ShareDescriptor(Handle<Map> map, | 8130 Handle<Map> Map::ShareDescriptor(Handle<Map> map, |
8074 Handle<DescriptorArray> descriptors, | 8131 Handle<DescriptorArray> descriptors, |
8075 Descriptor* descriptor) { | 8132 Descriptor* descriptor) { |
8076 // Sanity check. This path is only to be taken if the map owns its descriptor | 8133 // Sanity check. This path is only to be taken if the map owns its descriptor |
(...skipping 5838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13915 | 13972 |
13916 | 13973 |
13917 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, | 13974 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, |
13918 Handle<Object> value, bool from_javascript, | 13975 Handle<Object> value, bool from_javascript, |
13919 ShouldThrow should_throw) { | 13976 ShouldThrow should_throw) { |
13920 Isolate* isolate = object->GetIsolate(); | 13977 Isolate* isolate = object->GetIsolate(); |
13921 | 13978 |
13922 const bool observed = from_javascript && object->map()->is_observed(); | 13979 const bool observed = from_javascript && object->map()->is_observed(); |
13923 Handle<Object> old_value; | 13980 Handle<Object> old_value; |
13924 if (observed) { | 13981 if (observed) { |
13925 old_value = Object::GetPrototype(isolate, object); | 13982 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, |
13983 Object::GetPrototype(isolate, object), | |
13984 Nothing<bool>()); | |
13926 } | 13985 } |
13927 | 13986 |
13928 Maybe<bool> result = | 13987 Maybe<bool> result = |
13929 SetPrototypeUnobserved(object, value, from_javascript, should_throw); | 13988 SetPrototypeUnobserved(object, value, from_javascript, should_throw); |
13930 MAYBE_RETURN(result, Nothing<bool>()); | 13989 MAYBE_RETURN(result, Nothing<bool>()); |
13931 | 13990 |
13932 if (result.FromJust() && observed) { | 13991 if (result.FromJust() && observed) { |
13933 Handle<Object> new_value = Object::GetPrototype(isolate, object); | 13992 Handle<Object> new_value; |
13993 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, new_value, | |
13994 Object::GetPrototype(isolate, object), | |
13995 Nothing<bool>()); | |
13934 if (!new_value->SameValue(*old_value)) { | 13996 if (!new_value->SameValue(*old_value)) { |
13935 RETURN_ON_EXCEPTION_VALUE( | 13997 RETURN_ON_EXCEPTION_VALUE( |
13936 isolate, JSObject::EnqueueChangeRecord( | 13998 isolate, JSObject::EnqueueChangeRecord( |
13937 object, "setPrototype", | 13999 object, "setPrototype", |
13938 isolate->factory()->proto_string(), old_value), | 14000 isolate->factory()->proto_string(), old_value), |
13939 Nothing<bool>()); | 14001 Nothing<bool>()); |
13940 } | 14002 } |
13941 } | 14003 } |
13942 | 14004 |
13943 return result; | 14005 return result; |
(...skipping 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17882 if (cell->value() != *new_value) { | 17944 if (cell->value() != *new_value) { |
17883 cell->set_value(*new_value); | 17945 cell->set_value(*new_value); |
17884 Isolate* isolate = cell->GetIsolate(); | 17946 Isolate* isolate = cell->GetIsolate(); |
17885 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17947 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
17886 isolate, DependentCode::kPropertyCellChangedGroup); | 17948 isolate, DependentCode::kPropertyCellChangedGroup); |
17887 } | 17949 } |
17888 } | 17950 } |
17889 | 17951 |
17890 } // namespace internal | 17952 } // namespace internal |
17891 } // namespace v8 | 17953 } // namespace v8 |
OLD | NEW |