OLD | NEW |
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 <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 8664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8675 result->set_migration_target(false); | 8675 result->set_migration_target(false); |
8676 result->set_construction_counter(kNoSlackTracking); | 8676 result->set_construction_counter(kNoSlackTracking); |
8677 | 8677 |
8678 #ifdef VERIFY_HEAP | 8678 #ifdef VERIFY_HEAP |
8679 if (FLAG_verify_heap) result->DictionaryMapVerify(); | 8679 if (FLAG_verify_heap) result->DictionaryMapVerify(); |
8680 #endif | 8680 #endif |
8681 | 8681 |
8682 return result; | 8682 return result; |
8683 } | 8683 } |
8684 | 8684 |
| 8685 // Return an immutable prototype exotic object version of the input map. |
| 8686 // Never even try to cache it in the transition tree, as it is intended |
| 8687 // for the global object and its prototype chain, and excluding it saves |
| 8688 // memory on the map transition tree. |
| 8689 |
| 8690 // static |
| 8691 Handle<Map> Map::TransitionToImmutableProto(Handle<Map> map) { |
| 8692 Handle<Map> new_map = Map::Copy(map, "ImmutablePrototype"); |
| 8693 new_map->set_immutable_proto(true); |
| 8694 return new_map; |
| 8695 } |
8685 | 8696 |
8686 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, | 8697 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, |
8687 int in_object_properties, | 8698 int in_object_properties, |
8688 int unused_property_fields) { | 8699 int unused_property_fields) { |
8689 #ifdef DEBUG | 8700 #ifdef DEBUG |
8690 Isolate* isolate = map->GetIsolate(); | 8701 Isolate* isolate = map->GetIsolate(); |
8691 // Strict function maps have Function as a constructor but the | 8702 // Strict function maps have Function as a constructor but the |
8692 // Function's initial map is a sloppy function map. Same holds for | 8703 // Function's initial map is a sloppy function map. Same holds for |
8693 // GeneratorFunction and its initial map. | 8704 // GeneratorFunction and its initial map. |
8694 Object* constructor = map->GetConstructor(); | 8705 Object* constructor = map->GetConstructor(); |
(...skipping 6218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14913 real_receiver = PrototypeIterator::GetCurrent<JSObject>(iter); | 14924 real_receiver = PrototypeIterator::GetCurrent<JSObject>(iter); |
14914 iter.Advance(); | 14925 iter.Advance(); |
14915 all_extensible = all_extensible && real_receiver->map()->is_extensible(); | 14926 all_extensible = all_extensible && real_receiver->map()->is_extensible(); |
14916 } | 14927 } |
14917 } | 14928 } |
14918 Handle<Map> map(real_receiver->map()); | 14929 Handle<Map> map(real_receiver->map()); |
14919 | 14930 |
14920 // Nothing to do if prototype is already set. | 14931 // Nothing to do if prototype is already set. |
14921 if (map->prototype() == *value) return Just(true); | 14932 if (map->prototype() == *value) return Just(true); |
14922 | 14933 |
| 14934 bool immutable_proto = object->map()->is_immutable_proto(); |
| 14935 if (immutable_proto) { |
| 14936 RETURN_FAILURE( |
| 14937 isolate, should_throw, |
| 14938 NewTypeError(MessageTemplate::kImmutablePrototypeSet, object)); |
| 14939 } |
| 14940 |
14923 // From 8.6.2 Object Internal Methods | 14941 // From 8.6.2 Object Internal Methods |
14924 // ... | 14942 // ... |
14925 // In addition, if [[Extensible]] is false the value of the [[Class]] and | 14943 // In addition, if [[Extensible]] is false the value of the [[Class]] and |
14926 // [[Prototype]] internal properties of the object may not be modified. | 14944 // [[Prototype]] internal properties of the object may not be modified. |
14927 // ... | 14945 // ... |
14928 // Implementation specific extensions that modify [[Class]], [[Prototype]] | 14946 // Implementation specific extensions that modify [[Class]], [[Prototype]] |
14929 // or [[Extensible]] must not violate the invariants defined in the preceding | 14947 // or [[Extensible]] must not violate the invariants defined in the preceding |
14930 // paragraph. | 14948 // paragraph. |
14931 if (!all_extensible) { | 14949 if (!all_extensible) { |
14932 RETURN_FAILURE(isolate, should_throw, | 14950 RETURN_FAILURE(isolate, should_throw, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14964 // KeyedStoreICs need to be cleared to ensure any that involve this | 14982 // KeyedStoreICs need to be cleared to ensure any that involve this |
14965 // map go generic. | 14983 // map go generic. |
14966 TypeFeedbackVector::ClearAllKeyedStoreICs(isolate); | 14984 TypeFeedbackVector::ClearAllKeyedStoreICs(isolate); |
14967 } | 14985 } |
14968 | 14986 |
14969 heap->ClearInstanceofCache(); | 14987 heap->ClearInstanceofCache(); |
14970 DCHECK(size == object->Size()); | 14988 DCHECK(size == object->Size()); |
14971 return Just(true); | 14989 return Just(true); |
14972 } | 14990 } |
14973 | 14991 |
| 14992 // static |
| 14993 void JSObject::SetImmutableProto(Handle<JSObject> object) { |
| 14994 DCHECK(!object->IsAccessCheckNeeded()); // Never called from JS |
| 14995 Handle<Map> map(object->map()); |
| 14996 |
| 14997 // Nothing to do if prototype is already set. |
| 14998 if (map->is_immutable_proto()) return; |
| 14999 |
| 15000 Handle<Map> new_map = Map::TransitionToImmutableProto(map); |
| 15001 object->set_map(*new_map); |
| 15002 } |
14974 | 15003 |
14975 void JSObject::EnsureCanContainElements(Handle<JSObject> object, | 15004 void JSObject::EnsureCanContainElements(Handle<JSObject> object, |
14976 Arguments* args, | 15005 Arguments* args, |
14977 uint32_t first_arg, | 15006 uint32_t first_arg, |
14978 uint32_t arg_count, | 15007 uint32_t arg_count, |
14979 EnsureElementsMode mode) { | 15008 EnsureElementsMode mode) { |
14980 // Elements in |Arguments| are ordered backwards (because they're on the | 15009 // Elements in |Arguments| are ordered backwards (because they're on the |
14981 // stack), but the method that's called here iterates over them in forward | 15010 // stack), but the method that's called here iterates over them in forward |
14982 // direction. | 15011 // direction. |
14983 return EnsureCanContainElements( | 15012 return EnsureCanContainElements( |
(...skipping 3965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18949 | 18978 |
18950 Object* data_obj = | 18979 Object* data_obj = |
18951 constructor->shared()->get_api_func_data()->access_check_info(); | 18980 constructor->shared()->get_api_func_data()->access_check_info(); |
18952 if (data_obj->IsUndefined(isolate)) return nullptr; | 18981 if (data_obj->IsUndefined(isolate)) return nullptr; |
18953 | 18982 |
18954 return AccessCheckInfo::cast(data_obj); | 18983 return AccessCheckInfo::cast(data_obj); |
18955 } | 18984 } |
18956 | 18985 |
18957 } // namespace internal | 18986 } // namespace internal |
18958 } // namespace v8 | 18987 } // namespace v8 |
OLD | NEW |