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

Side by Side Diff: src/objects.cc

Issue 23182003: Push SetAccessor to Template (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: missed something Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after
3083 DescriptorArray::WhitenessWitness witness(*new_descriptors); 3083 DescriptorArray::WhitenessWitness witness(*new_descriptors);
3084 3084
3085 for (int i = 0; i < number_of_descriptors; ++i) { 3085 for (int i = 0; i < number_of_descriptors; ++i) {
3086 new_descriptors->CopyFrom(i, *descriptors, i, witness); 3086 new_descriptors->CopyFrom(i, *descriptors, i, witness);
3087 } 3087 }
3088 3088
3089 map->set_instance_descriptors(*new_descriptors); 3089 map->set_instance_descriptors(*new_descriptors);
3090 } 3090 }
3091 3091
3092 3092
3093 void Map::AppendCallbackDescriptors(Handle<Map> map, 3093 template<class T>
3094 Handle<Object> descriptors) { 3094 static int AppendUniqueCallbacks(NeanderArray* callbacks,
3095 Isolate* isolate = map->GetIsolate(); 3095 Handle<typename T::Array> array,
3096 Handle<DescriptorArray> array(map->instance_descriptors()); 3096 int valid_descriptors) {
3097 NeanderArray callbacks(descriptors); 3097 int nof_callbacks = callbacks->length();
3098 int nof_callbacks = callbacks.length();
3099 3098
3100 ASSERT(array->NumberOfSlackDescriptors() >= nof_callbacks); 3099 Isolate* isolate = array->GetIsolate();
3101
3102 // Ensure the keys are unique names before writing them into the 3100 // Ensure the keys are unique names before writing them into the
3103 // instance descriptor. Since it may cause a GC, it has to be done before we 3101 // instance descriptor. Since it may cause a GC, it has to be done before we
3104 // temporarily put the heap in an invalid state while appending descriptors. 3102 // temporarily put the heap in an invalid state while appending descriptors.
3105 for (int i = 0; i < nof_callbacks; ++i) { 3103 for (int i = 0; i < nof_callbacks; ++i) {
3106 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks.get(i))); 3104 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks->get(i)));
3107 if (!entry->name()->IsUniqueName()) { 3105 if (entry->name()->IsUniqueName()) continue;
3108 Handle<String> key = 3106 Handle<String> key =
3109 isolate->factory()->InternalizedStringFromString( 3107 isolate->factory()->InternalizedStringFromString(
3110 Handle<String>(String::cast(entry->name()))); 3108 Handle<String>(String::cast(entry->name())));
3111 entry->set_name(*key); 3109 entry->set_name(*key);
3112 }
3113 } 3110 }
3114 3111
3115 int nof = map->NumberOfOwnDescriptors();
3116
3117 // Fill in new callback descriptors. Process the callbacks from 3112 // Fill in new callback descriptors. Process the callbacks from
3118 // back to front so that the last callback with a given name takes 3113 // back to front so that the last callback with a given name takes
3119 // precedence over previously added callbacks with that name. 3114 // precedence over previously added callbacks with that name.
3120 for (int i = nof_callbacks - 1; i >= 0; i--) { 3115 for (int i = nof_callbacks - 1; i >= 0; i--) {
3121 AccessorInfo* entry = AccessorInfo::cast(callbacks.get(i)); 3116 AccessorInfo* entry = AccessorInfo::cast(callbacks->get(i));
3122 Name* key = Name::cast(entry->name()); 3117 Name* key = Name::cast(entry->name());
3123 // Check if a descriptor with this name already exists before writing. 3118 // Check if a descriptor with this name already exists before writing.
3124 if (array->Search(key, nof) == DescriptorArray::kNotFound) { 3119 if (!T::Contains(key, entry, valid_descriptors, array)) {
3125 CallbacksDescriptor desc(key, entry, entry->property_attributes()); 3120 T::Insert(key, entry, valid_descriptors, array);
3126 array->Append(&desc); 3121 valid_descriptors++;
3127 nof += 1;
3128 } 3122 }
3129 } 3123 }
3130 3124
3125 return valid_descriptors;
3126 }
3127
3128 struct DescriptorArrayAppender {
3129 typedef DescriptorArray Array;
3130 static bool Contains(Name* key,
3131 AccessorInfo* entry,
3132 int valid_descriptors,
3133 Handle<DescriptorArray> array) {
3134 return array->Search(key, valid_descriptors) != DescriptorArray::kNotFound;
3135 }
3136 static void Insert(Name* key,
3137 AccessorInfo* entry,
3138 int valid_descriptors,
3139 Handle<DescriptorArray> array) {
3140 CallbacksDescriptor desc(key, entry, entry->property_attributes());
3141 array->Append(&desc);
3142 }
3143 };
3144
3145
3146 struct FixedArrayAppender {
3147 typedef FixedArray Array;
3148 static bool Contains(Name* key,
3149 AccessorInfo* entry,
3150 int valid_descriptors,
3151 Handle<FixedArray> array) {
3152 for (int i = 0; i < valid_descriptors; i++) {
3153 if (key == AccessorInfo::cast(array->get(i))->name()) return true;
3154 }
3155 return false;
3156 }
3157 static void Insert(Name* key,
3158 AccessorInfo* entry,
3159 int valid_descriptors,
3160 Handle<FixedArray> array) {
3161 array->set(valid_descriptors, entry);
3162 }
3163 };
3164
3165
3166 void Map::AppendCallbackDescriptors(Handle<Map> map,
3167 Handle<Object> descriptors) {
3168 int nof = map->NumberOfOwnDescriptors();
3169 Handle<DescriptorArray> array(map->instance_descriptors());
3170 NeanderArray callbacks(descriptors);
3171 ASSERT(array->NumberOfSlackDescriptors() >= callbacks.length());
3172 nof = AppendUniqueCallbacks<DescriptorArrayAppender>(&callbacks, array, nof);
3131 map->SetNumberOfOwnDescriptors(nof); 3173 map->SetNumberOfOwnDescriptors(nof);
3132 } 3174 }
3133 3175
3134 3176
3177 int AccessorInfo::AppendUnique(Handle<Object> descriptors,
3178 Handle<FixedArray> array,
3179 int valid_descriptors) {
3180 NeanderArray callbacks(descriptors);
3181 ASSERT(array->length() >= callbacks.length() + valid_descriptors);
3182 return AppendUniqueCallbacks<FixedArrayAppender>(&callbacks,
3183 array,
3184 valid_descriptors);
3185 }
3186
3187
3135 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { 3188 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) {
3136 ASSERT(!map.is_null()); 3189 ASSERT(!map.is_null());
3137 for (int i = 0; i < maps->length(); ++i) { 3190 for (int i = 0; i < maps->length(); ++i) {
3138 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; 3191 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true;
3139 } 3192 }
3140 return false; 3193 return false;
3141 } 3194 }
3142 3195
3143 3196
3144 template <class T> 3197 template <class T>
(...skipping 12804 matching lines...) Expand 10 before | Expand all | Expand 10 after
15949 #define ERROR_MESSAGES_TEXTS(C, T) T, 16002 #define ERROR_MESSAGES_TEXTS(C, T) T,
15950 static const char* error_messages_[] = { 16003 static const char* error_messages_[] = {
15951 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16004 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
15952 }; 16005 };
15953 #undef ERROR_MESSAGES_TEXTS 16006 #undef ERROR_MESSAGES_TEXTS
15954 return error_messages_[reason]; 16007 return error_messages_[reason];
15955 } 16008 }
15956 16009
15957 16010
15958 } } // namespace v8::internal 16011 } } // namespace v8::internal
OLDNEW
« src/objects.h ('K') | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698