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 6989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7000 if (map->owns_descriptors()) { | 7000 if (map->owns_descriptors()) { |
7001 new_map->InitializeDescriptors(map->instance_descriptors()); | 7001 new_map->InitializeDescriptors(map->instance_descriptors()); |
7002 map->set_owns_descriptors(false); | 7002 map->set_owns_descriptors(false); |
7003 } | 7003 } |
7004 | 7004 |
7005 new_map->SetBackPointer(*map); | 7005 new_map->SetBackPointer(*map); |
7006 return new_map; | 7006 return new_map; |
7007 } | 7007 } |
7008 | 7008 |
7009 | 7009 |
7010 MaybeObject* Map::CopyWithPreallocatedFieldDescriptors() { | |
7011 if (pre_allocated_property_fields() == 0) return CopyDropDescriptors(); | |
7012 | |
7013 // If the map has pre-allocated properties always start out with a descriptor | |
7014 // array describing these properties. | |
7015 ASSERT(constructor()->IsJSFunction()); | |
7016 JSFunction* ctor = JSFunction::cast(constructor()); | |
7017 Map* map = ctor->initial_map(); | |
7018 DescriptorArray* descriptors = map->instance_descriptors(); | |
7019 | |
7020 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); | |
7021 DescriptorArray* new_descriptors; | |
7022 MaybeObject* maybe_descriptors = | |
7023 descriptors->CopyUpTo(number_of_own_descriptors); | |
7024 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors; | |
7025 | |
7026 return CopyReplaceDescriptors(new_descriptors, OMIT_TRANSITION); | |
7027 } | |
7028 | |
7029 | |
7030 Handle<Map> Map::Copy(Handle<Map> map) { | 7010 Handle<Map> Map::Copy(Handle<Map> map) { |
7031 CALL_HEAP_FUNCTION(map->GetIsolate(), map->Copy(), Map); | 7011 CALL_HEAP_FUNCTION(map->GetIsolate(), map->Copy(), Map); |
7032 } | 7012 } |
7033 | 7013 |
7034 | 7014 |
7035 MaybeObject* Map::Copy() { | 7015 MaybeObject* Map::Copy() { |
7036 DescriptorArray* descriptors = instance_descriptors(); | 7016 DescriptorArray* descriptors = instance_descriptors(); |
7037 DescriptorArray* new_descriptors; | 7017 DescriptorArray* new_descriptors; |
7038 int number_of_own_descriptors = NumberOfOwnDescriptors(); | 7018 int number_of_own_descriptors = NumberOfOwnDescriptors(); |
7039 MaybeObject* maybe_descriptors = | 7019 MaybeObject* maybe_descriptors = |
7040 descriptors->CopyUpTo(number_of_own_descriptors); | 7020 descriptors->CopyUpTo(number_of_own_descriptors); |
7041 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors; | 7021 if (!maybe_descriptors->To(&new_descriptors)) return maybe_descriptors; |
7042 | 7022 |
7043 return CopyReplaceDescriptors(new_descriptors, OMIT_TRANSITION); | 7023 return CopyReplaceDescriptors(new_descriptors, OMIT_TRANSITION); |
7044 } | 7024 } |
7045 | 7025 |
7046 | 7026 |
| 7027 Handle<Map> Map::Create(Handle<JSFunction> constructor, |
| 7028 int extra_inobject_properties) { |
| 7029 Handle<Map> copy = Copy(handle(constructor->initial_map())); |
| 7030 |
| 7031 // Check that we do not overflow the instance size when adding the |
| 7032 // extra inobject properties. |
| 7033 int instance_size_delta = extra_inobject_properties * kPointerSize; |
| 7034 int max_instance_size_delta = |
| 7035 JSObject::kMaxInstanceSize - copy->instance_size(); |
| 7036 int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2; |
| 7037 |
| 7038 // If the instance size overflows, we allocate as many properties as we can as |
| 7039 // inobject properties. |
| 7040 if (extra_inobject_properties > max_extra_properties) { |
| 7041 instance_size_delta = max_instance_size_delta; |
| 7042 extra_inobject_properties = max_extra_properties; |
| 7043 } |
| 7044 |
| 7045 // Adjust the map with the extra inobject properties. |
| 7046 int inobject_properties = |
| 7047 copy->inobject_properties() + extra_inobject_properties; |
| 7048 copy->set_inobject_properties(inobject_properties); |
| 7049 copy->set_unused_property_fields(inobject_properties); |
| 7050 copy->set_instance_size(copy->instance_size() + instance_size_delta); |
| 7051 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
| 7052 return copy; |
| 7053 } |
| 7054 |
| 7055 |
7047 MaybeObject* Map::CopyAddDescriptor(Descriptor* descriptor, | 7056 MaybeObject* Map::CopyAddDescriptor(Descriptor* descriptor, |
7048 TransitionFlag flag) { | 7057 TransitionFlag flag) { |
7049 DescriptorArray* descriptors = instance_descriptors(); | 7058 DescriptorArray* descriptors = instance_descriptors(); |
7050 | 7059 |
7051 // Ensure the key is unique. | 7060 // Ensure the key is unique. |
7052 MaybeObject* maybe_failure = descriptor->KeyToUniqueName(); | 7061 MaybeObject* maybe_failure = descriptor->KeyToUniqueName(); |
7053 if (maybe_failure->IsFailure()) return maybe_failure; | 7062 if (maybe_failure->IsFailure()) return maybe_failure; |
7054 | 7063 |
7055 int old_size = NumberOfOwnDescriptors(); | 7064 int old_size = NumberOfOwnDescriptors(); |
7056 int new_size = old_size + 1; | 7065 int new_size = old_size + 1; |
(...skipping 9419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16476 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16485 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16477 static const char* error_messages_[] = { | 16486 static const char* error_messages_[] = { |
16478 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16487 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16479 }; | 16488 }; |
16480 #undef ERROR_MESSAGES_TEXTS | 16489 #undef ERROR_MESSAGES_TEXTS |
16481 return error_messages_[reason]; | 16490 return error_messages_[reason]; |
16482 } | 16491 } |
16483 | 16492 |
16484 | 16493 |
16485 } } // namespace v8::internal | 16494 } } // namespace v8::internal |
OLD | NEW |