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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 5732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5743 int transition_index = old_map->SearchTransition( | 5743 int transition_index = old_map->SearchTransition( |
| 5744 isolate->heap()->frozen_symbol()); | 5744 isolate->heap()->frozen_symbol()); |
| 5745 if (transition_index != TransitionArray::kNotFound) { | 5745 if (transition_index != TransitionArray::kNotFound) { |
| 5746 Handle<Map> transition_map(old_map->GetTransition(transition_index)); | 5746 Handle<Map> transition_map(old_map->GetTransition(transition_index)); |
| 5747 ASSERT(transition_map->has_dictionary_elements()); | 5747 ASSERT(transition_map->has_dictionary_elements()); |
| 5748 ASSERT(transition_map->is_frozen()); | 5748 ASSERT(transition_map->is_frozen()); |
| 5749 ASSERT(!transition_map->is_extensible()); | 5749 ASSERT(!transition_map->is_extensible()); |
| 5750 JSObject::MigrateToMap(object, transition_map); | 5750 JSObject::MigrateToMap(object, transition_map); |
| 5751 } else if (object->HasFastProperties() && old_map->CanHaveMoreTransitions()) { | 5751 } else if (object->HasFastProperties() && old_map->CanHaveMoreTransitions()) { |
| 5752 // Create a new descriptor array with fully-frozen properties | 5752 // Create a new descriptor array with fully-frozen properties |
| 5753 int num_descriptors = old_map->NumberOfOwnDescriptors(); | 5753 Handle<Map> new_map = Map::CopyForFreeze(old_map); |
| 5754 Handle<DescriptorArray> new_descriptors = | |
| 5755 DescriptorArray::CopyUpToAddAttributes( | |
| 5756 handle(old_map->instance_descriptors()), num_descriptors, FROZEN); | |
| 5757 Handle<Map> new_map = Map::CopyReplaceDescriptors( | |
| 5758 old_map, new_descriptors, INSERT_TRANSITION, | |
| 5759 isolate->factory()->frozen_symbol()); | |
| 5760 new_map->freeze(); | |
| 5761 new_map->set_is_extensible(false); | |
| 5762 new_map->set_elements_kind(DICTIONARY_ELEMENTS); | |
| 5763 JSObject::MigrateToMap(object, new_map); | 5754 JSObject::MigrateToMap(object, new_map); |
| 5764 } else { | 5755 } else { |
| 5765 // Slow path: need to normalize properties for safety | 5756 // Slow path: need to normalize properties for safety |
| 5766 NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0); | 5757 NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0); |
| 5767 | 5758 |
| 5768 // Create a new map, since other objects with this map may be extensible. | 5759 // Create a new map, since other objects with this map may be extensible. |
| 5769 // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps. | 5760 // TODO(adamk): Extend the NormalizedMapCache to handle non-extensible maps. |
| 5770 Handle<Map> new_map = Map::Copy(handle(object->map())); | 5761 Handle<Map> new_map = Map::Copy(handle(object->map())); |
| 5771 new_map->freeze(); | 5762 new_map->freeze(); |
| 5772 new_map->set_is_extensible(false); | 5763 new_map->set_is_extensible(false); |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6949 map->set_transitions(*transitions); | 6940 map->set_transitions(*transitions); |
| 6950 map->set_owns_descriptors(false); | 6941 map->set_owns_descriptors(false); |
| 6951 | 6942 |
| 6952 return result; | 6943 return result; |
| 6953 } | 6944 } |
| 6954 | 6945 |
| 6955 | 6946 |
| 6956 Handle<Map> Map::CopyReplaceDescriptors(Handle<Map> map, | 6947 Handle<Map> Map::CopyReplaceDescriptors(Handle<Map> map, |
| 6957 Handle<DescriptorArray> descriptors, | 6948 Handle<DescriptorArray> descriptors, |
| 6958 TransitionFlag flag, | 6949 TransitionFlag flag, |
| 6959 SimpleTransitionFlag simple_flag) { | |
| 6960 return CopyReplaceDescriptors( | |
| 6961 map, descriptors, flag, Handle<Name>::null(), simple_flag); | |
| 6962 } | |
| 6963 | |
| 6964 | |
| 6965 Handle<Map> Map::CopyReplaceDescriptors(Handle<Map> map, | |
| 6966 Handle<DescriptorArray> descriptors, | |
| 6967 TransitionFlag flag, | |
| 6968 Handle<Name> name, | 6950 Handle<Name> name, |
|
Igor Sheludko
2014/04/16 10:26:21
While we are here: since name can be null handle p
Toon Verwaest
2014/04/16 11:16:47
Done.
| |
| 6969 SimpleTransitionFlag simple_flag) { | 6951 SimpleTransitionFlag simple_flag) { |
| 6970 ASSERT(descriptors->IsSortedNoDuplicates()); | 6952 ASSERT(descriptors->IsSortedNoDuplicates()); |
| 6971 | 6953 |
| 6972 Handle<Map> result = CopyDropDescriptors(map); | 6954 Handle<Map> result = CopyDropDescriptors(map); |
| 6973 result->InitializeDescriptors(*descriptors); | 6955 result->InitializeDescriptors(*descriptors); |
| 6974 | 6956 |
| 6975 if (flag == INSERT_TRANSITION && map->CanHaveMoreTransitions()) { | 6957 if (flag == INSERT_TRANSITION && map->CanHaveMoreTransitions()) { |
| 6976 Handle<TransitionArray> transitions = TransitionArray::CopyInsert( | 6958 Handle<TransitionArray> transitions = TransitionArray::CopyInsert( |
| 6977 map, name, result, simple_flag); | 6959 map, name, result, simple_flag); |
|
Igor Sheludko
2014/04/16 10:26:21
... and name.ToHandleChecked() here as CopyInsert(
Toon Verwaest
2014/04/16 11:16:47
Done.
| |
| 6978 map->set_transitions(*transitions); | 6960 map->set_transitions(*transitions); |
| 6979 result->SetBackPointer(*map); | 6961 result->SetBackPointer(*map); |
| 6980 } else { | 6962 } else { |
| 6981 int length = descriptors->number_of_descriptors(); | 6963 int length = descriptors->number_of_descriptors(); |
| 6982 for (int i = 0; i < length; i++) { | 6964 for (int i = 0; i < length; i++) { |
| 6983 descriptors->SetRepresentation(i, Representation::Tagged()); | 6965 descriptors->SetRepresentation(i, Representation::Tagged()); |
| 6984 if (descriptors->GetDetails(i).type() == FIELD) { | 6966 if (descriptors->GetDetails(i).type() == FIELD) { |
| 6985 descriptors->SetValue(i, HeapType::Any()); | 6967 descriptors->SetValue(i, HeapType::Any()); |
| 6986 } | 6968 } |
| 6987 } | 6969 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7102 new_map->SetBackPointer(*map); | 7084 new_map->SetBackPointer(*map); |
| 7103 return new_map; | 7085 return new_map; |
| 7104 } | 7086 } |
| 7105 | 7087 |
| 7106 | 7088 |
| 7107 Handle<Map> Map::Copy(Handle<Map> map) { | 7089 Handle<Map> Map::Copy(Handle<Map> map) { |
| 7108 Handle<DescriptorArray> descriptors(map->instance_descriptors()); | 7090 Handle<DescriptorArray> descriptors(map->instance_descriptors()); |
| 7109 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); | 7091 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); |
| 7110 Handle<DescriptorArray> new_descriptors = | 7092 Handle<DescriptorArray> new_descriptors = |
| 7111 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); | 7093 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); |
| 7112 return CopyReplaceDescriptors(map, new_descriptors, OMIT_TRANSITION); | 7094 return CopyReplaceDescriptors( |
| 7095 map, new_descriptors, OMIT_TRANSITION, Handle<Name>()); | |
| 7113 } | 7096 } |
| 7114 | 7097 |
| 7115 | 7098 |
| 7116 Handle<Map> Map::Create(Handle<JSFunction> constructor, | 7099 Handle<Map> Map::Create(Handle<JSFunction> constructor, |
| 7117 int extra_inobject_properties) { | 7100 int extra_inobject_properties) { |
| 7118 Handle<Map> copy = Copy(handle(constructor->initial_map())); | 7101 Handle<Map> copy = Copy(handle(constructor->initial_map())); |
| 7119 | 7102 |
| 7120 // Check that we do not overflow the instance size when adding the | 7103 // Check that we do not overflow the instance size when adding the |
| 7121 // extra inobject properties. | 7104 // extra inobject properties. |
| 7122 int instance_size_delta = extra_inobject_properties * kPointerSize; | 7105 int instance_size_delta = extra_inobject_properties * kPointerSize; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 7135 int inobject_properties = | 7118 int inobject_properties = |
| 7136 copy->inobject_properties() + extra_inobject_properties; | 7119 copy->inobject_properties() + extra_inobject_properties; |
| 7137 copy->set_inobject_properties(inobject_properties); | 7120 copy->set_inobject_properties(inobject_properties); |
| 7138 copy->set_unused_property_fields(inobject_properties); | 7121 copy->set_unused_property_fields(inobject_properties); |
| 7139 copy->set_instance_size(copy->instance_size() + instance_size_delta); | 7122 copy->set_instance_size(copy->instance_size() + instance_size_delta); |
| 7140 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); | 7123 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
| 7141 return copy; | 7124 return copy; |
| 7142 } | 7125 } |
| 7143 | 7126 |
| 7144 | 7127 |
| 7128 Handle<Map> Map::CopyForFreeze(Handle<Map> map) { | |
| 7129 int num_descriptors = map->NumberOfOwnDescriptors(); | |
| 7130 Isolate* isolate = map->GetIsolate(); | |
| 7131 Handle<DescriptorArray> new_desc = DescriptorArray::CopyUpToAddAttributes( | |
| 7132 handle(map->instance_descriptors(), isolate), num_descriptors, FROZEN); | |
| 7133 Handle<Map> new_map = Map::CopyReplaceDescriptors( | |
| 7134 map, new_desc, INSERT_TRANSITION, isolate->factory()->frozen_symbol()); | |
| 7135 new_map->freeze(); | |
| 7136 new_map->set_is_extensible(false); | |
| 7137 new_map->set_elements_kind(DICTIONARY_ELEMENTS); | |
| 7138 return new_map; | |
| 7139 } | |
| 7140 | |
| 7141 | |
| 7145 Handle<Map> Map::CopyAddDescriptor(Handle<Map> map, | 7142 Handle<Map> Map::CopyAddDescriptor(Handle<Map> map, |
| 7146 Descriptor* descriptor, | 7143 Descriptor* descriptor, |
| 7147 TransitionFlag flag) { | 7144 TransitionFlag flag) { |
| 7148 Handle<DescriptorArray> descriptors(map->instance_descriptors()); | 7145 Handle<DescriptorArray> descriptors(map->instance_descriptors()); |
| 7149 | 7146 |
| 7150 // Ensure the key is unique. | 7147 // Ensure the key is unique. |
| 7151 descriptor->KeyToUniqueName(); | 7148 descriptor->KeyToUniqueName(); |
| 7152 | 7149 |
| 7153 if (flag == INSERT_TRANSITION && | 7150 if (flag == INSERT_TRANSITION && |
| 7154 map->owns_descriptors() && | 7151 map->owns_descriptors() && |
| (...skipping 9423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16578 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16575 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16579 static const char* error_messages_[] = { | 16576 static const char* error_messages_[] = { |
| 16580 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16577 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16581 }; | 16578 }; |
| 16582 #undef ERROR_MESSAGES_TEXTS | 16579 #undef ERROR_MESSAGES_TEXTS |
| 16583 return error_messages_[reason]; | 16580 return error_messages_[reason]; |
| 16584 } | 16581 } |
| 16585 | 16582 |
| 16586 | 16583 |
| 16587 } } // namespace v8::internal | 16584 } } // namespace v8::internal |
| OLD | NEW |