| 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 2983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2994 DescriptorArray::WhitenessWitness witness(*new_descriptors); | 2994 DescriptorArray::WhitenessWitness witness(*new_descriptors); |
| 2995 | 2995 |
| 2996 for (int i = 0; i < number_of_descriptors; ++i) { | 2996 for (int i = 0; i < number_of_descriptors; ++i) { |
| 2997 new_descriptors->CopyFrom(i, *descriptors, i, witness); | 2997 new_descriptors->CopyFrom(i, *descriptors, i, witness); |
| 2998 } | 2998 } |
| 2999 | 2999 |
| 3000 map->set_instance_descriptors(*new_descriptors); | 3000 map->set_instance_descriptors(*new_descriptors); |
| 3001 } | 3001 } |
| 3002 | 3002 |
| 3003 | 3003 |
| 3004 void Map::AppendCallbackDescriptors(Handle<Map> map, | 3004 template<class T> |
| 3005 Handle<Object> descriptors) { | 3005 static int AppendUniqueCallbacks(NeanderArray* callbacks, |
| 3006 Isolate* isolate = map->GetIsolate(); | 3006 Handle<typename T::Array> array, |
| 3007 Handle<DescriptorArray> array(map->instance_descriptors()); | 3007 int valid_descriptors) { |
| 3008 NeanderArray callbacks(descriptors); | 3008 int nof_callbacks = callbacks->length(); |
| 3009 int nof_callbacks = callbacks.length(); | |
| 3010 | 3009 |
| 3011 ASSERT(array->NumberOfSlackDescriptors() >= nof_callbacks); | 3010 Isolate* isolate = array->GetIsolate(); |
| 3012 | |
| 3013 // Ensure the keys are unique names before writing them into the | 3011 // Ensure the keys are unique names before writing them into the |
| 3014 // instance descriptor. Since it may cause a GC, it has to be done before we | 3012 // instance descriptor. Since it may cause a GC, it has to be done before we |
| 3015 // temporarily put the heap in an invalid state while appending descriptors. | 3013 // temporarily put the heap in an invalid state while appending descriptors. |
| 3016 for (int i = 0; i < nof_callbacks; ++i) { | 3014 for (int i = 0; i < nof_callbacks; ++i) { |
| 3017 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks.get(i))); | 3015 Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks->get(i))); |
| 3018 if (!entry->name()->IsUniqueName()) { | 3016 if (entry->name()->IsUniqueName()) continue; |
| 3019 Handle<String> key = | 3017 Handle<String> key = |
| 3020 isolate->factory()->InternalizedStringFromString( | 3018 isolate->factory()->InternalizedStringFromString( |
| 3021 Handle<String>(String::cast(entry->name()))); | 3019 Handle<String>(String::cast(entry->name()))); |
| 3022 entry->set_name(*key); | 3020 entry->set_name(*key); |
| 3023 } | |
| 3024 } | 3021 } |
| 3025 | 3022 |
| 3026 int nof = map->NumberOfOwnDescriptors(); | |
| 3027 | |
| 3028 // Fill in new callback descriptors. Process the callbacks from | 3023 // Fill in new callback descriptors. Process the callbacks from |
| 3029 // back to front so that the last callback with a given name takes | 3024 // back to front so that the last callback with a given name takes |
| 3030 // precedence over previously added callbacks with that name. | 3025 // precedence over previously added callbacks with that name. |
| 3031 for (int i = nof_callbacks - 1; i >= 0; i--) { | 3026 for (int i = nof_callbacks - 1; i >= 0; i--) { |
| 3032 AccessorInfo* entry = AccessorInfo::cast(callbacks.get(i)); | 3027 AccessorInfo* entry = AccessorInfo::cast(callbacks->get(i)); |
| 3033 Name* key = Name::cast(entry->name()); | 3028 Name* key = Name::cast(entry->name()); |
| 3034 // Check if a descriptor with this name already exists before writing. | 3029 // Check if a descriptor with this name already exists before writing. |
| 3035 if (array->Search(key, nof) == DescriptorArray::kNotFound) { | 3030 if (!T::Contains(key, entry, valid_descriptors, array)) { |
| 3036 CallbacksDescriptor desc(key, entry, entry->property_attributes()); | 3031 T::Insert(key, entry, valid_descriptors, array); |
| 3037 array->Append(&desc); | 3032 valid_descriptors++; |
| 3038 nof += 1; | |
| 3039 } | 3033 } |
| 3040 } | 3034 } |
| 3041 | 3035 |
| 3036 return valid_descriptors; |
| 3037 } |
| 3038 |
| 3039 struct DescriptorArrayAppender { |
| 3040 typedef DescriptorArray Array; |
| 3041 static bool Contains(Name* key, |
| 3042 AccessorInfo* entry, |
| 3043 int valid_descriptors, |
| 3044 Handle<DescriptorArray> array) { |
| 3045 return array->Search(key, valid_descriptors) != DescriptorArray::kNotFound; |
| 3046 } |
| 3047 static void Insert(Name* key, |
| 3048 AccessorInfo* entry, |
| 3049 int valid_descriptors, |
| 3050 Handle<DescriptorArray> array) { |
| 3051 CallbacksDescriptor desc(key, entry, entry->property_attributes()); |
| 3052 array->Append(&desc); |
| 3053 } |
| 3054 }; |
| 3055 |
| 3056 |
| 3057 struct FixedArrayAppender { |
| 3058 typedef FixedArray Array; |
| 3059 static bool Contains(Name* key, |
| 3060 AccessorInfo* entry, |
| 3061 int valid_descriptors, |
| 3062 Handle<FixedArray> array) { |
| 3063 for (int i = 0; i < valid_descriptors; i++) { |
| 3064 if (key == AccessorInfo::cast(array->get(i))->name()) return true; |
| 3065 } |
| 3066 return false; |
| 3067 } |
| 3068 static void Insert(Name* key, |
| 3069 AccessorInfo* entry, |
| 3070 int valid_descriptors, |
| 3071 Handle<FixedArray> array) { |
| 3072 array->set(valid_descriptors, entry); |
| 3073 } |
| 3074 }; |
| 3075 |
| 3076 |
| 3077 void Map::AppendCallbackDescriptors(Handle<Map> map, |
| 3078 Handle<Object> descriptors) { |
| 3079 int nof = map->NumberOfOwnDescriptors(); |
| 3080 Handle<DescriptorArray> array(map->instance_descriptors()); |
| 3081 NeanderArray callbacks(descriptors); |
| 3082 ASSERT(array->NumberOfSlackDescriptors() >= callbacks.length()); |
| 3083 nof = AppendUniqueCallbacks<DescriptorArrayAppender>(&callbacks, array, nof); |
| 3042 map->SetNumberOfOwnDescriptors(nof); | 3084 map->SetNumberOfOwnDescriptors(nof); |
| 3043 } | 3085 } |
| 3044 | 3086 |
| 3045 | 3087 |
| 3088 int AccessorInfo::AppendUnique(Handle<Object> descriptors, |
| 3089 Handle<FixedArray> array, |
| 3090 int valid_descriptors) { |
| 3091 NeanderArray callbacks(descriptors); |
| 3092 ASSERT(array->length() >= callbacks.length() + valid_descriptors); |
| 3093 return AppendUniqueCallbacks<FixedArrayAppender>(&callbacks, |
| 3094 array, |
| 3095 valid_descriptors); |
| 3096 } |
| 3097 |
| 3098 |
| 3046 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { | 3099 static bool ContainsMap(MapHandleList* maps, Handle<Map> map) { |
| 3047 ASSERT(!map.is_null()); | 3100 ASSERT(!map.is_null()); |
| 3048 for (int i = 0; i < maps->length(); ++i) { | 3101 for (int i = 0; i < maps->length(); ++i) { |
| 3049 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; | 3102 if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true; |
| 3050 } | 3103 } |
| 3051 return false; | 3104 return false; |
| 3052 } | 3105 } |
| 3053 | 3106 |
| 3054 | 3107 |
| 3055 template <class T> | 3108 template <class T> |
| (...skipping 12907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15963 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16016 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 15964 static const char* error_messages_[] = { | 16017 static const char* error_messages_[] = { |
| 15965 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16018 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 15966 }; | 16019 }; |
| 15967 #undef ERROR_MESSAGES_TEXTS | 16020 #undef ERROR_MESSAGES_TEXTS |
| 15968 return error_messages_[reason]; | 16021 return error_messages_[reason]; |
| 15969 } | 16022 } |
| 15970 | 16023 |
| 15971 | 16024 |
| 15972 } } // namespace v8::internal | 16025 } } // namespace v8::internal |
| OLD | NEW |