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 <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 4687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4698 Map* current = *map; | 4698 Map* current = *map; |
4699 while (current->instance_descriptors() == *descriptors) { | 4699 while (current->instance_descriptors() == *descriptors) { |
4700 Object* next = current->GetBackPointer(); | 4700 Object* next = current->GetBackPointer(); |
4701 if (next->IsUndefined(isolate)) break; // Stop overwriting at initial map. | 4701 if (next->IsUndefined(isolate)) break; // Stop overwriting at initial map. |
4702 current->UpdateDescriptors(*new_descriptors, layout_descriptor); | 4702 current->UpdateDescriptors(*new_descriptors, layout_descriptor); |
4703 current = Map::cast(next); | 4703 current = Map::cast(next); |
4704 } | 4704 } |
4705 map->UpdateDescriptors(*new_descriptors, layout_descriptor); | 4705 map->UpdateDescriptors(*new_descriptors, layout_descriptor); |
4706 } | 4706 } |
4707 | 4707 |
4708 // static | |
4709 Handle<Map> Map::GetObjectCreateMap(Handle<HeapObject> prototype) { | |
4710 Isolate* isolate = prototype->GetIsolate(); | |
4711 Handle<Map> map(isolate->native_context()->object_function()->initial_map(), | |
4712 isolate); | |
4713 if (map->prototype() == *prototype) return map; | |
4714 if (prototype->IsNull(isolate)) { | |
4715 return isolate->slow_object_with_null_prototype_map(); | |
4716 } | |
4717 if (prototype->IsJSObject()) { | |
4718 Handle<JSObject> js_prototype = Handle<JSObject>::cast(prototype); | |
4719 if (!js_prototype->map()->is_prototype_map()) { | |
4720 JSObject::OptimizeAsPrototype(js_prototype, FAST_PROTOTYPE); | |
4721 } | |
4722 Handle<PrototypeInfo> info = | |
4723 Map::GetOrCreatePrototypeInfo(js_prototype, isolate); | |
4724 // TODO(verwaest): Use inobject slack tracking for this map. | |
4725 if (info->HasObjectCreateMap()) { | |
4726 map = handle(info->ObjectCreateMap(), isolate); | |
4727 } else { | |
4728 map = Map::CopyInitialMap(map); | |
4729 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); | |
4730 PrototypeInfo::SetObjectCreateMap(info, map); | |
4731 } | |
4732 return map; | |
4733 } | |
4734 | |
4735 return Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE); | |
4736 } | |
4737 | |
4738 template <class T> | 4708 template <class T> |
4739 static int AppendUniqueCallbacks(Handle<TemplateList> callbacks, | 4709 static int AppendUniqueCallbacks(Handle<TemplateList> callbacks, |
4740 Handle<typename T::Array> array, | 4710 Handle<typename T::Array> array, |
4741 int valid_descriptors) { | 4711 int valid_descriptors) { |
4742 int nof_callbacks = callbacks->length(); | 4712 int nof_callbacks = callbacks->length(); |
4743 | 4713 |
4744 Isolate* isolate = array->GetIsolate(); | 4714 Isolate* isolate = array->GetIsolate(); |
4745 // Ensure the keys are unique names before writing them into the | 4715 // Ensure the keys are unique names before writing them into the |
4746 // instance descriptor. Since it may cause a GC, it has to be done before we | 4716 // instance descriptor. Since it may cause a GC, it has to be done before we |
4747 // temporarily put the heap in an invalid state while appending descriptors. | 4717 // temporarily put the heap in an invalid state while appending descriptors. |
(...skipping 3477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8225 } | 8195 } |
8226 } | 8196 } |
8227 return free_index; | 8197 return free_index; |
8228 } | 8198 } |
8229 | 8199 |
8230 | 8200 |
8231 bool Map::OnlyHasSimpleProperties() { | 8201 bool Map::OnlyHasSimpleProperties() { |
8232 // Wrapped string elements aren't explicitly stored in the elements backing | 8202 // Wrapped string elements aren't explicitly stored in the elements backing |
8233 // store, but are loaded indirectly from the underlying string. | 8203 // store, but are loaded indirectly from the underlying string. |
8234 return !IsStringWrapperElementsKind(elements_kind()) && | 8204 return !IsStringWrapperElementsKind(elements_kind()) && |
8235 !IsSpecialReceiverMap() && !has_hidden_prototype() && | 8205 instance_type() > LAST_SPECIAL_RECEIVER_TYPE && |
8236 !is_dictionary_map(); | 8206 !has_hidden_prototype() && !is_dictionary_map(); |
8237 } | 8207 } |
8238 | 8208 |
8239 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( | 8209 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( |
8240 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, | 8210 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, |
8241 Handle<FixedArray>* result) { | 8211 Handle<FixedArray>* result) { |
8242 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate); | 8212 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate); |
8243 | 8213 |
8244 if (!map->IsJSObjectMap()) return Just(false); | 8214 if (!map->IsJSObjectMap()) return Just(false); |
8245 if (!map->OnlyHasSimpleProperties()) return Just(false); | 8215 if (!map->OnlyHasSimpleProperties()) return Just(false); |
8246 | 8216 |
(...skipping 11721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19968 // depend on this. | 19938 // depend on this. |
19969 return DICTIONARY_ELEMENTS; | 19939 return DICTIONARY_ELEMENTS; |
19970 } | 19940 } |
19971 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 19941 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
19972 return kind; | 19942 return kind; |
19973 } | 19943 } |
19974 } | 19944 } |
19975 | 19945 |
19976 } // namespace internal | 19946 } // namespace internal |
19977 } // namespace v8 | 19947 } // namespace v8 |
OLD | NEW |