Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 995ed36f0228b9982dd08f50fc9ef0dd54406b9d..881066a3f2de9345cf0509a760b10825ad1faaca 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -3058,42 +3058,9 @@ void Map::EnsureDescriptorSlack(Handle<Map> map, int slack) { |
void Map::AppendCallbackDescriptors(Handle<Map> map, |
Handle<Object> descriptors) { |
- Isolate* isolate = map->GetIsolate(); |
- Handle<DescriptorArray> array(map->instance_descriptors()); |
- NeanderArray callbacks(descriptors); |
- int nof_callbacks = callbacks.length(); |
- |
- ASSERT(array->NumberOfSlackDescriptors() >= nof_callbacks); |
- |
- // Ensure the keys are unique names before writing them into the |
- // instance descriptor. Since it may cause a GC, it has to be done before we |
- // temporarily put the heap in an invalid state while appending descriptors. |
- for (int i = 0; i < nof_callbacks; ++i) { |
- Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks.get(i))); |
- if (!entry->name()->IsUniqueName()) { |
- Handle<String> key = |
- isolate->factory()->InternalizedStringFromString( |
- Handle<String>(String::cast(entry->name()))); |
- entry->set_name(*key); |
- } |
- } |
- |
int nof = map->NumberOfOwnDescriptors(); |
- |
- // Fill in new callback descriptors. Process the callbacks from |
- // back to front so that the last callback with a given name takes |
- // precedence over previously added callbacks with that name. |
- for (int i = nof_callbacks - 1; i >= 0; i--) { |
- AccessorInfo* entry = AccessorInfo::cast(callbacks.get(i)); |
- Name* key = Name::cast(entry->name()); |
- // Check if a descriptor with this name already exists before writing. |
- if (array->Search(key, nof) == DescriptorArray::kNotFound) { |
- CallbacksDescriptor desc(key, entry, entry->property_attributes()); |
- array->Append(&desc); |
- nof += 1; |
- } |
- } |
- |
+ Handle<DescriptorArray> array(map->instance_descriptors()); |
+ nof = DescriptorArray::AppendDescriptors(array, nof, descriptors); |
map->SetNumberOfOwnDescriptors(nof); |
} |
@@ -7750,6 +7717,45 @@ void DescriptorArray::SetEnumCache(FixedArray* bridge_storage, |
} |
+int DescriptorArray::AppendDescriptors(Handle<DescriptorArray> array, |
+ int valid_descriptors, |
+ Handle<Object> descriptors) { |
+ NeanderArray callbacks(descriptors); |
+ int nof_callbacks = callbacks.length(); |
+ ASSERT(array->NumberOfSlackDescriptors() >= nof_callbacks); |
+ |
+ Isolate* isolate = array->GetIsolate(); |
+ // Ensure the keys are unique names before writing them into the |
+ // instance descriptor. Since it may cause a GC, it has to be done before we |
+ // temporarily put the heap in an invalid state while appending descriptors. |
+ for (int i = 0; i < nof_callbacks; ++i) { |
+ Handle<AccessorInfo> entry(AccessorInfo::cast(callbacks.get(i))); |
+ if (entry->name()->IsUniqueName()) continue; |
+ Handle<String> key = |
+ isolate->factory()->InternalizedStringFromString( |
+ Handle<String>(String::cast(entry->name()))); |
+ entry->set_name(*key); |
+ } |
+ |
+ // Fill in new callback descriptors. Process the callbacks from |
+ // back to front so that the last callback with a given name takes |
+ // precedence over previously added callbacks with that name. |
+ for (int i = nof_callbacks - 1; i >= 0; i--) { |
+ AccessorInfo* entry = AccessorInfo::cast(callbacks.get(i)); |
+ Name* key = Name::cast(entry->name()); |
+ // Check if a descriptor with this name already exists before writing. |
+ if (array->Search(key, valid_descriptors) != DescriptorArray::kNotFound) { |
+ continue; |
+ } |
+ CallbacksDescriptor desc(key, entry, entry->property_attributes()); |
+ array->Append(&desc); |
+ valid_descriptors += 1; |
+ } |
+ |
+ return valid_descriptors; |
+} |
+ |
+ |
void DescriptorArray::CopyFrom(int dst_index, |
DescriptorArray* src, |
int src_index, |