Chromium Code Reviews| 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 // ES6 9.5.1 | |
| 849 // static | |
| 850 MaybeHandle<Object> JSProxy::GetPrototype(Handle<JSProxy> proxy) { | |
| 851 Isolate* isolate = proxy->GetIsolate(); | |
| 852 // 1. Let handler be the value of the [[ProxyHandler]] internal slot. | |
| 853 Handle<Object> raw_handler(proxy->handler(), isolate); | |
| 854 // 2. If handler is null, throw a TypeError exception. | |
| 855 // 3. Assert: Type(handler) is Object. | |
| 856 if (!raw_handler->IsSpecObject()) { | |
| 857 // TODO(cbruni): Throw correct error message. | |
| 858 THROW_NEW_ERROR( | |
| 859 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject), Object); | |
| 860 } | |
| 861 Handle<JSReceiver> handler = Handle<JSReceiver>::cast(raw_handler); | |
| 862 // 4. Let target be the value of the [[ProxyTarget]] internal slot. | |
| 863 // TODO(cbruni): Change target type to JSReceiver by default. | |
| 864 Handle<JSReceiver> target(JSReceiver::cast(proxy->target()), isolate); | |
| 865 // 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). | |
| 866 Handle<Object> trap; | |
| 867 Handle<String> trap_name = isolate->factory()->getPrototypeOf_string(); | |
| 868 ASSIGN_RETURN_ON_EXCEPTION(isolate, trap, GetMethod(handler, trap_name), | |
| 869 Object); | |
| 870 // 6. If trap is undefined, then return target.[[GetPrototypeOf]](). | |
| 871 if (trap->IsUndefined()) { | |
| 872 return Object::GetPrototype(isolate, target); | |
| 873 } | |
| 874 // 7. Let handlerProto be ? Call(trap, handler, «target»). | |
| 875 Handle<Object> argv[] = {target}; | |
| 876 Handle<Object> handler_proto; | |
| 877 ASSIGN_RETURN_ON_EXCEPTION( | |
| 878 isolate, handler_proto, | |
| 879 Execution::Call(isolate, trap, handler, arraysize(argv), argv), Object); | |
| 880 // 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError. | |
| 881 if (!(handler_proto->IsSpecObject() || handler_proto->IsNull())) { | |
| 882 THROW_NEW_ERROR(isolate, | |
| 883 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, | |
| 884 handler, trap_name), | |
| 885 Object); | |
| 886 } | |
| 887 // 9. Let extensibleTarget be ? IsExtensible(target). | |
| 888 Maybe<bool> isExtensible = JSReceiver::IsExtensible(target); | |
|
Jakob Kummerow
2015/11/13 10:47:51
nit: is_extensible
| |
| 889 if (isExtensible.IsNothing()) return MaybeHandle<Object>(); | |
| 890 // 10. If extensibleTarget is true, return handlerProto. | |
| 891 if (isExtensible.FromJust()) return handler_proto; | |
| 892 // 11. Let targetProto be ? target.[[GetPrototypeOf]](). | |
| 893 Handle<Object> target_proto; | |
| 894 ASSIGN_RETURN_ON_EXCEPTION(isolate, handler_proto, | |
| 895 Object::GetPrototype(isolate, target), Object); | |
| 896 // 12. If SameValue(handlerProto, targetProto) is false, throw a TypeError. | |
| 897 if (!handler_proto->SameValue(*target_proto)) { | |
| 898 THROW_NEW_ERROR(isolate, | |
| 899 NewTypeError(MessageTemplate::kProxyHandlerTrapMissing, | |
| 900 handler, trap_name), | |
| 901 Object); | |
| 902 } | |
| 903 // 13. Return handlerProto. | |
| 904 return handler_proto; | |
| 905 } | |
| 906 | |
| 907 | |
| 848 MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy, | 908 MaybeHandle<Object> JSProxy::GetPropertyWithHandler(Handle<JSProxy> proxy, |
| 849 Handle<Object> receiver, | 909 Handle<Object> receiver, |
| 850 Handle<Name> name) { | 910 Handle<Name> name) { |
| 851 Isolate* isolate = proxy->GetIsolate(); | 911 Isolate* isolate = proxy->GetIsolate(); |
| 852 | 912 |
| 853 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 913 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 854 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | 914 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
| 855 | 915 |
| 856 Handle<Object> args[] = { receiver, name }; | 916 Handle<Object> args[] = { receiver, name }; |
| 857 return CallTrap( | 917 return CallTrap( |
| (...skipping 4697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5555 proxy->set_hash(*hash); | 5615 proxy->set_hash(*hash); |
| 5556 return hash; | 5616 return hash; |
| 5557 } | 5617 } |
| 5558 | 5618 |
| 5559 | 5619 |
| 5560 Object* JSObject::GetIdentityHash() { | 5620 Object* JSObject::GetIdentityHash() { |
| 5561 DisallowHeapAllocation no_gc; | 5621 DisallowHeapAllocation no_gc; |
| 5562 Isolate* isolate = GetIsolate(); | 5622 Isolate* isolate = GetIsolate(); |
| 5563 if (IsJSGlobalProxy()) { | 5623 if (IsJSGlobalProxy()) { |
| 5564 return JSGlobalProxy::cast(this)->hash(); | 5624 return JSGlobalProxy::cast(this)->hash(); |
| 5625 } else if (IsJSProxy()) { | |
| 5626 return JSProxy::cast(this)->GetIdentityHash(); | |
| 5565 } | 5627 } |
| 5566 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); | 5628 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); |
| 5567 Handle<Object> stored_value = | 5629 Handle<Object> stored_value = |
| 5568 Object::GetPropertyOrElement(Handle<Object>(this, isolate), | 5630 Object::GetPropertyOrElement(Handle<Object>(this, isolate), |
| 5569 hash_code_symbol).ToHandleChecked(); | 5631 hash_code_symbol).ToHandleChecked(); |
| 5570 return stored_value->IsSmi() ? *stored_value | 5632 return stored_value->IsSmi() ? *stored_value |
| 5571 : isolate->heap()->undefined_value(); | 5633 : isolate->heap()->undefined_value(); |
| 5572 } | 5634 } |
| 5573 | 5635 |
| 5574 | 5636 |
| 5575 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { | 5637 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
| 5576 if (object->IsJSGlobalProxy()) { | 5638 if (object->IsJSGlobalProxy()) { |
| 5577 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); | 5639 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); |
| 5640 } else if (object->IsJSProxy()) { | |
| 5641 return JSProxy::GetOrCreateIdentityHash(Handle<JSProxy>::cast(object)); | |
| 5578 } | 5642 } |
| 5579 | 5643 |
| 5580 Isolate* isolate = object->GetIsolate(); | 5644 Isolate* isolate = object->GetIsolate(); |
| 5581 | 5645 |
| 5582 Handle<Object> maybe_hash(object->GetIdentityHash(), isolate); | 5646 Handle<Object> maybe_hash(object->GetIdentityHash(), isolate); |
| 5583 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); | 5647 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5584 | 5648 |
| 5585 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); | 5649 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5586 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); | 5650 Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); |
| 5587 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); | 5651 JSObject::AddProperty(object, hash_code_symbol, hash, NONE); |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6872 RETURN_ON_EXCEPTION_VALUE( | 6936 RETURN_ON_EXCEPTION_VALUE( |
| 6873 isolate, | 6937 isolate, |
| 6874 EnqueueChangeRecord(object, "preventExtensions", Handle<Name>(), | 6938 EnqueueChangeRecord(object, "preventExtensions", Handle<Name>(), |
| 6875 isolate->factory()->the_hole_value()), | 6939 isolate->factory()->the_hole_value()), |
| 6876 Nothing<bool>()); | 6940 Nothing<bool>()); |
| 6877 } | 6941 } |
| 6878 return Just(true); | 6942 return Just(true); |
| 6879 } | 6943 } |
| 6880 | 6944 |
| 6881 | 6945 |
| 6946 // static | |
| 6947 Maybe<bool> JSReceiver::IsExtensible(Handle<JSReceiver> object) { | |
| 6948 if (object->IsJSProxy()) { | |
| 6949 // TODO(neis,cbruni): Redirect to the trap on JSProxy. | |
| 6950 return Just(true); | |
| 6951 } | |
| 6952 return Just(JSObject::IsExtensible(Handle<JSObject>::cast(object))); | |
| 6953 } | |
| 6954 | |
| 6955 | |
| 6882 bool JSObject::IsExtensible(Handle<JSObject> object) { | 6956 bool JSObject::IsExtensible(Handle<JSObject> object) { |
| 6883 Isolate* isolate = object->GetIsolate(); | 6957 Isolate* isolate = object->GetIsolate(); |
| 6884 if (object->IsAccessCheckNeeded() && | 6958 if (object->IsAccessCheckNeeded() && |
| 6885 !isolate->MayAccess(handle(isolate->context()), object)) { | 6959 !isolate->MayAccess(handle(isolate->context()), object)) { |
| 6886 return true; | 6960 return true; |
| 6887 } | 6961 } |
| 6888 if (object->IsJSGlobalProxy()) { | 6962 if (object->IsJSGlobalProxy()) { |
| 6889 PrototypeIterator iter(isolate, *object); | 6963 PrototypeIterator iter(isolate, *object); |
| 6890 if (iter.IsAtEnd()) return false; | 6964 if (iter.IsAtEnd()) return false; |
| 6891 DCHECK(iter.GetCurrent()->IsJSGlobalObject()); | 6965 DCHECK(iter.GetCurrent()->IsJSGlobalObject()); |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8064 } | 8138 } |
| 8065 | 8139 |
| 8066 return result; | 8140 return result; |
| 8067 } | 8141 } |
| 8068 | 8142 |
| 8069 | 8143 |
| 8070 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { | 8144 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { |
| 8071 Handle<Map> result = RawCopy(map, map->instance_size()); | 8145 Handle<Map> result = RawCopy(map, map->instance_size()); |
| 8072 | 8146 |
| 8073 // Please note instance_type and instance_size are set when allocated. | 8147 // Please note instance_type and instance_size are set when allocated. |
| 8074 result->SetInObjectProperties(map->GetInObjectProperties()); | 8148 if (map->IsJSObjectMap()) { |
| 8075 result->set_unused_property_fields(map->unused_property_fields()); | 8149 result->SetInObjectProperties(map->GetInObjectProperties()); |
| 8076 | 8150 result->set_unused_property_fields(map->unused_property_fields()); |
| 8151 } | |
| 8077 result->ClearCodeCache(map->GetHeap()); | 8152 result->ClearCodeCache(map->GetHeap()); |
| 8078 map->NotifyLeafMapLayoutChange(); | 8153 map->NotifyLeafMapLayoutChange(); |
| 8079 return result; | 8154 return result; |
| 8080 } | 8155 } |
| 8081 | 8156 |
| 8082 | 8157 |
| 8083 Handle<Map> Map::ShareDescriptor(Handle<Map> map, | 8158 Handle<Map> Map::ShareDescriptor(Handle<Map> map, |
| 8084 Handle<DescriptorArray> descriptors, | 8159 Handle<DescriptorArray> descriptors, |
| 8085 Descriptor* descriptor) { | 8160 Descriptor* descriptor) { |
| 8086 // Sanity check. This path is only to be taken if the map owns its descriptor | 8161 // Sanity check. This path is only to be taken if the map owns its descriptor |
| (...skipping 5847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13934 | 14009 |
| 13935 | 14010 |
| 13936 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, | 14011 Maybe<bool> JSObject::SetPrototype(Handle<JSObject> object, |
| 13937 Handle<Object> value, bool from_javascript, | 14012 Handle<Object> value, bool from_javascript, |
| 13938 ShouldThrow should_throw) { | 14013 ShouldThrow should_throw) { |
| 13939 Isolate* isolate = object->GetIsolate(); | 14014 Isolate* isolate = object->GetIsolate(); |
| 13940 | 14015 |
| 13941 const bool observed = from_javascript && object->map()->is_observed(); | 14016 const bool observed = from_javascript && object->map()->is_observed(); |
| 13942 Handle<Object> old_value; | 14017 Handle<Object> old_value; |
| 13943 if (observed) { | 14018 if (observed) { |
| 13944 old_value = Object::GetPrototype(isolate, object); | 14019 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, old_value, |
| 14020 Object::GetPrototype(isolate, object), | |
| 14021 Nothing<bool>()); | |
| 13945 } | 14022 } |
| 13946 | 14023 |
| 13947 Maybe<bool> result = | 14024 Maybe<bool> result = |
| 13948 SetPrototypeUnobserved(object, value, from_javascript, should_throw); | 14025 SetPrototypeUnobserved(object, value, from_javascript, should_throw); |
| 13949 MAYBE_RETURN(result, Nothing<bool>()); | 14026 MAYBE_RETURN(result, Nothing<bool>()); |
| 13950 | 14027 |
| 13951 if (result.FromJust() && observed) { | 14028 if (result.FromJust() && observed) { |
| 13952 Handle<Object> new_value = Object::GetPrototype(isolate, object); | 14029 Handle<Object> new_value; |
| 14030 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, new_value, | |
| 14031 Object::GetPrototype(isolate, object), | |
| 14032 Nothing<bool>()); | |
| 13953 if (!new_value->SameValue(*old_value)) { | 14033 if (!new_value->SameValue(*old_value)) { |
| 13954 RETURN_ON_EXCEPTION_VALUE( | 14034 RETURN_ON_EXCEPTION_VALUE( |
| 13955 isolate, JSObject::EnqueueChangeRecord( | 14035 isolate, JSObject::EnqueueChangeRecord( |
| 13956 object, "setPrototype", | 14036 object, "setPrototype", |
| 13957 isolate->factory()->proto_string(), old_value), | 14037 isolate->factory()->proto_string(), old_value), |
| 13958 Nothing<bool>()); | 14038 Nothing<bool>()); |
| 13959 } | 14039 } |
| 13960 } | 14040 } |
| 13961 | 14041 |
| 13962 return result; | 14042 return result; |
| (...skipping 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17901 if (cell->value() != *new_value) { | 17981 if (cell->value() != *new_value) { |
| 17902 cell->set_value(*new_value); | 17982 cell->set_value(*new_value); |
| 17903 Isolate* isolate = cell->GetIsolate(); | 17983 Isolate* isolate = cell->GetIsolate(); |
| 17904 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17984 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 17905 isolate, DependentCode::kPropertyCellChangedGroup); | 17985 isolate, DependentCode::kPropertyCellChangedGroup); |
| 17906 } | 17986 } |
| 17907 } | 17987 } |
| 17908 | 17988 |
| 17909 } // namespace internal | 17989 } // namespace internal |
| 17910 } // namespace v8 | 17990 } // namespace v8 |
| OLD | NEW |