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 8663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8674 result->set_migration_target(false); | 8674 result->set_migration_target(false); |
8675 result->set_construction_counter(kNoSlackTracking); | 8675 result->set_construction_counter(kNoSlackTracking); |
8676 | 8676 |
8677 #ifdef VERIFY_HEAP | 8677 #ifdef VERIFY_HEAP |
8678 if (FLAG_verify_heap) result->DictionaryMapVerify(); | 8678 if (FLAG_verify_heap) result->DictionaryMapVerify(); |
8679 #endif | 8679 #endif |
8680 | 8680 |
8681 return result; | 8681 return result; |
8682 } | 8682 } |
8683 | 8683 |
| 8684 // Return an immutable prototype exotic object version of the input map. |
| 8685 // Never even try to cache it in the transition tree, as it is intended |
| 8686 // for the global object and its prototype chain, and excluding it saves |
| 8687 // memory on the map transition tree. |
| 8688 |
| 8689 // static |
| 8690 Handle<Map> Map::TransitionToImmutableProto(Handle<Map> map) { |
| 8691 Handle<Map> new_map = Map::Copy(map, "ImmutablePrototype"); |
| 8692 new_map->set_immutable_proto(true); |
| 8693 return new_map; |
| 8694 } |
8684 | 8695 |
8685 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, | 8696 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, |
8686 int in_object_properties, | 8697 int in_object_properties, |
8687 int unused_property_fields) { | 8698 int unused_property_fields) { |
8688 #ifdef DEBUG | 8699 #ifdef DEBUG |
8689 Isolate* isolate = map->GetIsolate(); | 8700 Isolate* isolate = map->GetIsolate(); |
8690 // Strict function maps have Function as a constructor but the | 8701 // Strict function maps have Function as a constructor but the |
8691 // Function's initial map is a sloppy function map. Same holds for | 8702 // Function's initial map is a sloppy function map. Same holds for |
8692 // GeneratorFunction and its initial map. | 8703 // GeneratorFunction and its initial map. |
8693 Object* constructor = map->GetConstructor(); | 8704 Object* constructor = map->GetConstructor(); |
(...skipping 6254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14948 real_receiver = PrototypeIterator::GetCurrent<JSObject>(iter); | 14959 real_receiver = PrototypeIterator::GetCurrent<JSObject>(iter); |
14949 iter.Advance(); | 14960 iter.Advance(); |
14950 all_extensible = all_extensible && real_receiver->map()->is_extensible(); | 14961 all_extensible = all_extensible && real_receiver->map()->is_extensible(); |
14951 } | 14962 } |
14952 } | 14963 } |
14953 Handle<Map> map(real_receiver->map()); | 14964 Handle<Map> map(real_receiver->map()); |
14954 | 14965 |
14955 // Nothing to do if prototype is already set. | 14966 // Nothing to do if prototype is already set. |
14956 if (map->prototype() == *value) return Just(true); | 14967 if (map->prototype() == *value) return Just(true); |
14957 | 14968 |
| 14969 bool immutable_proto = object->map()->is_immutable_proto(); |
| 14970 if (immutable_proto) { |
| 14971 RETURN_FAILURE( |
| 14972 isolate, should_throw, |
| 14973 NewTypeError(MessageTemplate::kImmutablePrototypeSet, object)); |
| 14974 } |
| 14975 |
14958 // From 8.6.2 Object Internal Methods | 14976 // From 8.6.2 Object Internal Methods |
14959 // ... | 14977 // ... |
14960 // In addition, if [[Extensible]] is false the value of the [[Class]] and | 14978 // In addition, if [[Extensible]] is false the value of the [[Class]] and |
14961 // [[Prototype]] internal properties of the object may not be modified. | 14979 // [[Prototype]] internal properties of the object may not be modified. |
14962 // ... | 14980 // ... |
14963 // Implementation specific extensions that modify [[Class]], [[Prototype]] | 14981 // Implementation specific extensions that modify [[Class]], [[Prototype]] |
14964 // or [[Extensible]] must not violate the invariants defined in the preceding | 14982 // or [[Extensible]] must not violate the invariants defined in the preceding |
14965 // paragraph. | 14983 // paragraph. |
14966 if (!all_extensible) { | 14984 if (!all_extensible) { |
14967 RETURN_FAILURE(isolate, should_throw, | 14985 RETURN_FAILURE(isolate, should_throw, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14999 // KeyedStoreICs need to be cleared to ensure any that involve this | 15017 // KeyedStoreICs need to be cleared to ensure any that involve this |
15000 // map go generic. | 15018 // map go generic. |
15001 TypeFeedbackVector::ClearAllKeyedStoreICs(isolate); | 15019 TypeFeedbackVector::ClearAllKeyedStoreICs(isolate); |
15002 } | 15020 } |
15003 | 15021 |
15004 heap->ClearInstanceofCache(); | 15022 heap->ClearInstanceofCache(); |
15005 DCHECK(size == object->Size()); | 15023 DCHECK(size == object->Size()); |
15006 return Just(true); | 15024 return Just(true); |
15007 } | 15025 } |
15008 | 15026 |
| 15027 // static |
| 15028 void JSObject::SetImmutableProto(Handle<JSObject> object) { |
| 15029 DCHECK(!object->IsAccessCheckNeeded()); // Never called from JS |
| 15030 Handle<Map> map(object->map()); |
| 15031 |
| 15032 // Nothing to do if prototype is already set. |
| 15033 if (map->is_immutable_proto()) return; |
| 15034 |
| 15035 Handle<Map> new_map = Map::TransitionToImmutableProto(map); |
| 15036 object->set_map(*new_map); |
| 15037 } |
15009 | 15038 |
15010 void JSObject::EnsureCanContainElements(Handle<JSObject> object, | 15039 void JSObject::EnsureCanContainElements(Handle<JSObject> object, |
15011 Arguments* args, | 15040 Arguments* args, |
15012 uint32_t first_arg, | 15041 uint32_t first_arg, |
15013 uint32_t arg_count, | 15042 uint32_t arg_count, |
15014 EnsureElementsMode mode) { | 15043 EnsureElementsMode mode) { |
15015 // Elements in |Arguments| are ordered backwards (because they're on the | 15044 // Elements in |Arguments| are ordered backwards (because they're on the |
15016 // stack), but the method that's called here iterates over them in forward | 15045 // stack), but the method that's called here iterates over them in forward |
15017 // direction. | 15046 // direction. |
15018 return EnsureCanContainElements( | 15047 return EnsureCanContainElements( |
(...skipping 3913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18932 | 18961 |
18933 Object* data_obj = | 18962 Object* data_obj = |
18934 constructor->shared()->get_api_func_data()->access_check_info(); | 18963 constructor->shared()->get_api_func_data()->access_check_info(); |
18935 if (data_obj->IsUndefined(isolate)) return nullptr; | 18964 if (data_obj->IsUndefined(isolate)) return nullptr; |
18936 | 18965 |
18937 return AccessCheckInfo::cast(data_obj); | 18966 return AccessCheckInfo::cast(data_obj); |
18938 } | 18967 } |
18939 | 18968 |
18940 } // namespace internal | 18969 } // namespace internal |
18941 } // namespace v8 | 18970 } // namespace v8 |
OLD | NEW |