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 3078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3089 DescriptorArray::WhitenessWitness witness(*new_descriptors); | 3089 DescriptorArray::WhitenessWitness witness(*new_descriptors); |
| 3090 | 3090 |
| 3091 for (int i = 0; i < number_of_descriptors; ++i) { | 3091 for (int i = 0; i < number_of_descriptors; ++i) { |
| 3092 new_descriptors->CopyFrom(i, *descriptors, i, witness); | 3092 new_descriptors->CopyFrom(i, *descriptors, i, witness); |
| 3093 } | 3093 } |
| 3094 | 3094 |
| 3095 map->set_instance_descriptors(*new_descriptors); | 3095 map->set_instance_descriptors(*new_descriptors); |
| 3096 } | 3096 } |
| 3097 | 3097 |
| 3098 | 3098 |
| 3099 void Map::AppendCallbackDescriptors(Handle<Map> map, | 3099 template<class T> |
| 3100 Handle<Object> descriptors) { | 3100 static int AppendUniqueCallbacks(NeanderArray* callbacks, |
| 3101 Isolate* isolate = map->GetIsolate(); | 3101 Handle<typename T::Array> array, |
| 3102 Handle<DescriptorArray> array(map->instance_descriptors()); | 3102 int valid_descriptors) { |
| 3103 NeanderArray callbacks(descriptors); | 3103 int nof_callbacks = callbacks->length(); |
| 3104 int nof_callbacks = callbacks.length(); | |
| 3105 | 3104 |
| 3106 ASSERT(array->NumberOfSlackDescriptors() >= nof_callbacks); | 3105 Isolate* isolate = array->GetIsolate(); |
| 3107 | |
| 3108 // Ensure the keys are unique names before writing them into the | 3106 // Ensure the keys are unique names before writing them into the |
| 3109 // instance descriptor. Since it may cause a GC, it has to be done before we | 3107 // instance descriptor. Since it may cause a GC, it has to be done before we |
| 3110 // temporarily put the heap in an invalid state while appending descriptors. | 3108 // temporarily put the heap in an invalid state while appending descriptors. |
| 3111 for (int i = 0; i < nof_callbacks; ++i) { | 3109 for (int i = 0; i < nof_callbacks; ++i) { |
| 3112 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks.get(i))); | 3110 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks->get(i))); |
| 3113 if (!entry->name()->IsUniqueName()) { | 3111 if (entry->name()->IsUniqueName()) continue; |
| 3114 Handle<String> key = | 3112 Handle<String> key = |
| 3115 isolate->factory()->InternalizedStringFromString( | 3113 isolate->factory()->InternalizedStringFromString( |
| 3116 Handle<String>(String::cast(entry->name()))); | 3114 Handle<String>(String::cast(entry->name()))); |
| 3117 entry->set_name(*key); | 3115 entry->set_name(*key); |
| 3118 } | |
| 3119 } | 3116 } |
| 3120 | 3117 |
| 3121 int nof = map->NumberOfOwnDescriptors(); | |
| 3122 | |
| 3123 // Fill in new callback descriptors. Process the callbacks from | 3118 // Fill in new callback descriptors. Process the callbacks from |
| 3124 // back to front so that the last callback with a given name takes | 3119 // back to front so that the last callback with a given name takes |
| 3125 // precedence over previously added callbacks with that name. | 3120 // precedence over previously added callbacks with that name. |
| 3126 for (int i = nof_callbacks - 1; i >= 0; i--) { | 3121 for (int i = nof_callbacks - 1; i >= 0; i--) { |
| 3127 AccessorInfo* entry = AccessorInfo::cast(callbacks.get(i)); | 3122 AccessorInfo* entry = AccessorInfo::cast(callbacks->get(i)); |
| 3128 Name* key = Name::cast(entry->name()); | 3123 Name* key = Name::cast(entry->name()); |
| 3129 // Check if a descriptor with this name already exists before writing. | 3124 // Check if a descriptor with this name already exists before writing. |
| 3130 if (array->Search(key, nof) == DescriptorArray::kNotFound) { | 3125 if (T::InsertUnique(key, entry, valid_descriptors, array)) { |
| 3131 CallbacksDescriptor desc(key, entry, entry->property_attributes()); | 3126 valid_descriptors++; |
| 3132 array->Append(&desc); | |
| 3133 nof += 1; | |
| 3134 } | 3127 } |
| 3135 } | 3128 } |
| 3136 | 3129 |
| 3130 return valid_descriptors; | |
| 3131 } | |
| 3132 | |
| 3133 struct DescriptorArrayAppender { | |
| 3134 typedef DescriptorArray Array; | |
| 3135 static bool InsertUnique(Name* key, | |
|
Sven Panne
2013/08/26 07:20:24
Splitting InsertUnique into 2 methods
Contains
dcarney
2013/08/26 07:32:23
okay
| |
| 3136 AccessorInfo* entry, | |
| 3137 int valid_descriptors, | |
| 3138 Handle<DescriptorArray> array) { | |
| 3139 if (array->Search(key, valid_descriptors) != DescriptorArray::kNotFound) { | |
| 3140 return false; | |
| 3141 } | |
| 3142 CallbacksDescriptor desc(key, entry, entry->property_attributes()); | |
| 3143 array->Append(&desc); | |
| 3144 return true; | |
| 3145 } | |
| 3146 }; | |
| 3147 | |
| 3148 | |
| 3149 struct FixedArrayAppender { | |
| 3150 typedef FixedArray Array; | |
| 3151 static bool InsertUnique(Name* key, | |
| 3152 AccessorInfo* entry, | |
| 3153 int valid_descriptors, | |
| 3154 Handle<FixedArray> array) { | |
| 3155 for (int i = 0; i < valid_descriptors; i++) { | |
| 3156 if (key == AccessorInfo::cast(array->get(i))->name()) return false; | |
| 3157 } | |
| 3158 array->set(valid_descriptors, entry); | |
|
Sven Panne
2013/08/26 07:20:24
Why is there always room for the new entry?
dcarney
2013/08/26 07:32:23
I'll add an assert, like appendcallbackdescriptors
| |
| 3159 return true; | |
| 3160 } | |
| 3161 }; | |
| 3162 | |
| 3163 | |
| 3164 void Map::AppendCallbackDescriptors(Handle<Map> map, | |
| 3165 Handle<Object> descriptors) { | |
| 3166 int nof = map->NumberOfOwnDescriptors(); | |
| 3167 Handle<DescriptorArray> array(map->instance_descriptors()); | |
| 3168 NeanderArray callbacks(descriptors); | |
| 3169 ASSERT(array->NumberOfSlackDescriptors() >= callbacks.length()); | |
| 3170 nof = AppendUniqueCallbacks<DescriptorArrayAppender>(&callbacks, array, nof); | |
| 3137 map->SetNumberOfOwnDescriptors(nof); | 3171 map->SetNumberOfOwnDescriptors(nof); |
| 3138 } | 3172 } |
| 3139 | 3173 |
| 3140 | 3174 |
| 3175 int AccessorInfo::AppendUnique(Handle<Object> descriptors, | |
| 3176 Handle<FixedArray> array, | |
| 3177 int valid_descriptors) { | |
| 3178 NeanderArray callbacks(descriptors); | |
| 3179 return AppendUniqueCallbacks<FixedArrayAppender>(&callbacks, | |
| 3180 array, | |
| 3181 valid_descriptors); | |
| 3182 } | |
| 3183 | |
| 3184 | |
| 3141 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { | 3185 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { |
| 3142 ASSERT(!map.is_null()); | 3186 ASSERT(!map.is_null()); |
| 3143 for (int i = 0; i < maps->length(); ++i) { | 3187 for (int i = 0; i < maps->length(); ++i) { |
| 3144 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; | 3188 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; |
| 3145 } | 3189 } |
| 3146 return false; | 3190 return false; |
| 3147 } | 3191 } |
| 3148 | 3192 |
| 3149 | 3193 |
| 3150 template <class T> | 3194 template <class T> |
| (...skipping 12856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16007 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16051 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16008 static const char* error_messages_[] = { | 16052 static const char* error_messages_[] = { |
| 16009 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16053 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16010 }; | 16054 }; |
| 16011 #undef ERROR_MESSAGES_TEXTS | 16055 #undef ERROR_MESSAGES_TEXTS |
| 16012 return error_messages_[reason]; | 16056 return error_messages_[reason]; |
| 16013 } | 16057 } |
| 16014 | 16058 |
| 16015 | 16059 |
| 16016 } } // namespace v8::internal | 16060 } } // namespace v8::internal |
| OLD | NEW |