Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: src/objects.cc

Issue 2196533003: [api] Cleaning up: Replace NeanderArray with FixedArray implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mind the pointers Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 type->IsFunctionTemplateInfo(); 1024 type->IsFunctionTemplateInfo();
1025 type = FunctionTemplateInfo::cast(type)->parent_template()) { 1025 type = FunctionTemplateInfo::cast(type)->parent_template()) {
1026 if (type == this) return true; 1026 if (type == this) return true;
1027 } 1027 }
1028 // Didn't find the required type in the inheritance chain. 1028 // Didn't find the required type in the inheritance chain.
1029 return false; 1029 return false;
1030 } 1030 }
1031 1031
1032 1032
1033 // static 1033 // static
1034 Handle<TemplateList> TemplateList::New(Isolate* isolate, int size) {
1035 Handle<FixedArray> list =
1036 isolate->factory()->NewFixedArray(kLengthIndex + size);
1037 list->set(kLengthIndex, Smi::FromInt(0));
1038 return Handle<TemplateList>::cast(list);
1039 }
1040
1041 // static
1042 Handle<TemplateList> TemplateList::Add(Isolate* isolate,
1043 Handle<TemplateList> list,
1044 Handle<i::Object> value) {
1045 STATIC_ASSERT(kFirstElementIndex == 1);
1046 int index = list->length() + 1;
1047 Handle<i::FixedArray> fixed_array = Handle<FixedArray>::cast(list);
1048 fixed_array = FixedArray::SetAndGrow(fixed_array, index, value);
1049 fixed_array->set(kLengthIndex, Smi::FromInt(index));
1050 return Handle<TemplateList>::cast(fixed_array);
1051 }
1052
1053 // static
1034 MaybeHandle<JSObject> JSObject::New(Handle<JSFunction> constructor, 1054 MaybeHandle<JSObject> JSObject::New(Handle<JSFunction> constructor,
1035 Handle<JSReceiver> new_target, 1055 Handle<JSReceiver> new_target,
1036 Handle<AllocationSite> site) { 1056 Handle<AllocationSite> site) {
1037 // If called through new, new.target can be: 1057 // If called through new, new.target can be:
1038 // - a subclass of constructor, 1058 // - a subclass of constructor,
1039 // - a proxy wrapper around constructor, or 1059 // - a proxy wrapper around constructor, or
1040 // - the constructor itself. 1060 // - the constructor itself.
1041 // If called through Reflect.construct, it's guaranteed to be a constructor. 1061 // If called through Reflect.construct, it's guaranteed to be a constructor.
1042 Isolate* const isolate = constructor->GetIsolate(); 1062 Isolate* const isolate = constructor->GetIsolate();
1043 DCHECK(constructor->IsConstructor()); 1063 DCHECK(constructor->IsConstructor());
(...skipping 3720 matching lines...) Expand 10 before | Expand all | Expand 10 after
4764 Map* current = *map; 4784 Map* current = *map;
4765 while (current->instance_descriptors() == *descriptors) { 4785 while (current->instance_descriptors() == *descriptors) {
4766 Object* next = current->GetBackPointer(); 4786 Object* next = current->GetBackPointer();
4767 if (next->IsUndefined(isolate)) break; // Stop overwriting at initial map. 4787 if (next->IsUndefined(isolate)) break; // Stop overwriting at initial map.
4768 current->UpdateDescriptors(*new_descriptors, layout_descriptor); 4788 current->UpdateDescriptors(*new_descriptors, layout_descriptor);
4769 current = Map::cast(next); 4789 current = Map::cast(next);
4770 } 4790 }
4771 map->UpdateDescriptors(*new_descriptors, layout_descriptor); 4791 map->UpdateDescriptors(*new_descriptors, layout_descriptor);
4772 } 4792 }
4773 4793
4774 4794 template <class T>
4775 template<class T> 4795 static int AppendUniqueCallbacks(Handle<TemplateList> callbacks,
4776 static int AppendUniqueCallbacks(NeanderArray* callbacks,
4777 Handle<typename T::Array> array, 4796 Handle<typename T::Array> array,
4778 int valid_descriptors) { 4797 int valid_descriptors) {
4779 int nof_callbacks = callbacks->length(); 4798 int nof_callbacks = callbacks->length();
4780 4799
4781 Isolate* isolate = array->GetIsolate(); 4800 Isolate* isolate = array->GetIsolate();
4782 // Ensure the keys are unique names before writing them into the 4801 // Ensure the keys are unique names before writing them into the
4783 // instance descriptor. Since it may cause a GC, it has to be done before we 4802 // instance descriptor. Since it may cause a GC, it has to be done before we
4784 // temporarily put the heap in an invalid state while appending descriptors. 4803 // temporarily put the heap in an invalid state while appending descriptors.
4785 for (int i = 0; i < nof_callbacks; ++i) { 4804 for (int i = 0; i < nof_callbacks; ++i) {
4786 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks->get(i))); 4805 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks->get(i)));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4845 DisallowHeapAllocation no_gc; 4864 DisallowHeapAllocation no_gc;
4846 array->set(valid_descriptors, *entry); 4865 array->set(valid_descriptors, *entry);
4847 } 4866 }
4848 }; 4867 };
4849 4868
4850 4869
4851 void Map::AppendCallbackDescriptors(Handle<Map> map, 4870 void Map::AppendCallbackDescriptors(Handle<Map> map,
4852 Handle<Object> descriptors) { 4871 Handle<Object> descriptors) {
4853 int nof = map->NumberOfOwnDescriptors(); 4872 int nof = map->NumberOfOwnDescriptors();
4854 Handle<DescriptorArray> array(map->instance_descriptors()); 4873 Handle<DescriptorArray> array(map->instance_descriptors());
4855 NeanderArray callbacks(descriptors); 4874 Handle<TemplateList> callbacks = Handle<TemplateList>::cast(descriptors);
4856 DCHECK(array->NumberOfSlackDescriptors() >= callbacks.length()); 4875 DCHECK_GE(array->NumberOfSlackDescriptors(), callbacks->length());
4857 nof = AppendUniqueCallbacks<DescriptorArrayAppender>(&callbacks, array, nof); 4876 nof = AppendUniqueCallbacks<DescriptorArrayAppender>(callbacks, array, nof);
4858 map->SetNumberOfOwnDescriptors(nof); 4877 map->SetNumberOfOwnDescriptors(nof);
4859 } 4878 }
4860 4879
4861 4880
4862 int AccessorInfo::AppendUnique(Handle<Object> descriptors, 4881 int AccessorInfo::AppendUnique(Handle<Object> descriptors,
4863 Handle<FixedArray> array, 4882 Handle<FixedArray> array,
4864 int valid_descriptors) { 4883 int valid_descriptors) {
4865 NeanderArray callbacks(descriptors); 4884 Handle<TemplateList> callbacks = Handle<TemplateList>::cast(descriptors);
4866 DCHECK(array->length() >= callbacks.length() + valid_descriptors); 4885 DCHECK_GE(array->length(), callbacks->length() + valid_descriptors);
4867 return AppendUniqueCallbacks<FixedArrayAppender>(&callbacks, 4886 return AppendUniqueCallbacks<FixedArrayAppender>(callbacks, array,
4868 array,
4869 valid_descriptors); 4887 valid_descriptors);
4870 } 4888 }
4871 4889
4872 4890
4873 static bool ContainsMap(MapHandleList* maps, Map* map) { 4891 static bool ContainsMap(MapHandleList* maps, Map* map) {
4874 DCHECK_NOT_NULL(map); 4892 DCHECK_NOT_NULL(map);
4875 for (int i = 0; i < maps->length(); ++i) { 4893 for (int i = 0; i < maps->length(); ++i) {
4876 if (!maps->at(i).is_null() && *maps->at(i) == map) return true; 4894 if (!maps->at(i).is_null() && *maps->at(i) == map) return true;
4877 } 4895 }
4878 return false; 4896 return false;
(...skipping 14130 matching lines...) Expand 10 before | Expand all | Expand 10 after
19009 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, 19027 for (PrototypeIterator iter(isolate, this, kStartAtReceiver,
19010 PrototypeIterator::END_AT_NULL); 19028 PrototypeIterator::END_AT_NULL);
19011 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { 19029 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) {
19012 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; 19030 if (iter.GetCurrent<Object>()->IsJSProxy()) return true;
19013 } 19031 }
19014 return false; 19032 return false;
19015 } 19033 }
19016 19034
19017 } // namespace internal 19035 } // namespace internal
19018 } // namespace v8 19036 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698