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

Unified Diff: src/factory.cc

Issue 10695120: Ensure that all descriptors have a valid enumeration index, and replace NextEnumIndex with LastAdde… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | src/heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index e7c612b92a4819d9c0fd161ad8950d548ddea22f..a4dfa907d044e6cf8aabb6cb998102f555ee1b0e 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -892,7 +892,7 @@ MUST_USE_RESULT static inline MaybeObject* DoCopyInsert(
String* key,
Object* value,
PropertyAttributes attributes) {
- CallbacksDescriptor desc(key, value, attributes);
+ CallbacksDescriptor desc(key, value, attributes, 0);
MaybeObject* obj = array->CopyInsert(&desc);
return obj;
}
@@ -936,6 +936,8 @@ Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
// 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.
+ int added_descriptor_count = descriptor_count;
+ int next_enum = array->NextEnumerationIndex();
for (int i = nof_callbacks - 1; i >= 0; i--) {
Handle<AccessorInfo> entry =
Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
@@ -943,19 +945,26 @@ Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
Handle<String> key =
SymbolFromString(Handle<String>(String::cast(entry->name())));
// Check if a descriptor with this name already exists before writing.
- if (LinearSearch(*result, EXPECT_UNSORTED, *key, descriptor_count) ==
+ if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) ==
DescriptorArray::kNotFound) {
- CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
- result->Set(descriptor_count, &desc, witness);
- descriptor_count++;
+ CallbacksDescriptor desc(*key,
+ *entry,
+ entry->property_attributes(),
+ next_enum++);
+ result->Set(added_descriptor_count, &desc, witness);
+ added_descriptor_count++;
}
}
+ // Return the old descriptor array if there were no new elements.
+ if (added_descriptor_count == descriptor_count) return array;
+
// If duplicates were detected, allocate a result of the right size
// and transfer the elements.
- if (descriptor_count < result->length()) {
- Handle<DescriptorArray> new_result = NewDescriptorArray(descriptor_count);
- for (int i = 0; i < descriptor_count; i++) {
+ if (added_descriptor_count < result->length()) {
+ Handle<DescriptorArray> new_result =
+ NewDescriptorArray(added_descriptor_count);
+ for (int i = 0; i < added_descriptor_count; i++) {
DescriptorArray::CopyFrom(new_result, i, result, i, witness);
}
result = new_result;
@@ -963,6 +972,7 @@ Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
// Sort the result before returning.
result->Sort(witness);
+ ASSERT(result->NextEnumerationIndex() == next_enum);
return result;
}
« no previous file with comments | « src/bootstrapper.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698