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

Side by Side Diff: src/factory.cc

Issue 10692185: Couple the enumeration index of a property to the size of the descriptor array where it first appea… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Adding assert in Set 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.cc ('k') | src/objects.h » ('j') | src/objects.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 931
932 // Copy the descriptors from the array. 932 // Copy the descriptors from the array.
933 for (int i = 0; i < descriptor_count; i++) { 933 for (int i = 0; i < descriptor_count; i++) {
934 DescriptorArray::CopyFrom(result, i, array, i, witness); 934 DescriptorArray::CopyFrom(result, i, array, i, witness);
935 } 935 }
936 936
937 // Fill in new callback descriptors. Process the callbacks from 937 // Fill in new callback descriptors. Process the callbacks from
938 // back to front so that the last callback with a given name takes 938 // back to front so that the last callback with a given name takes
939 // precedence over previously added callbacks with that name. 939 // precedence over previously added callbacks with that name.
940 int added_descriptor_count = descriptor_count; 940 int added_descriptor_count = descriptor_count;
941 int next_enum = array->NextEnumerationIndex();
942 for (int i = nof_callbacks - 1; i >= 0; i--) { 941 for (int i = nof_callbacks - 1; i >= 0; i--) {
943 Handle<AccessorInfo> entry = 942 Handle<AccessorInfo> entry =
944 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); 943 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
945 // Ensure the key is a symbol before writing into the instance descriptor. 944 // Ensure the key is a symbol before writing into the instance descriptor.
946 Handle<String> key = 945 Handle<String> key =
947 SymbolFromString(Handle<String>(String::cast(entry->name()))); 946 SymbolFromString(Handle<String>(String::cast(entry->name())));
948 // Check if a descriptor with this name already exists before writing. 947 // Check if a descriptor with this name already exists before writing.
949 if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) == 948 if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) ==
950 DescriptorArray::kNotFound) { 949 DescriptorArray::kNotFound) {
951 CallbacksDescriptor desc(*key, 950 CallbacksDescriptor desc(*key, *entry, entry->property_attributes(), 0);
952 *entry, 951 result->Append(added_descriptor_count, &desc, witness);
953 entry->property_attributes(),
954 next_enum++);
955 result->Set(added_descriptor_count, &desc, witness);
956 added_descriptor_count++; 952 added_descriptor_count++;
957 } 953 }
958 } 954 }
959 955
960 // Return the old descriptor array if there were no new elements. 956 // Return the old descriptor array if there were no new elements.
961 if (added_descriptor_count == descriptor_count) return array; 957 if (added_descriptor_count == descriptor_count) return array;
962 958
963 // If duplicates were detected, allocate a result of the right size 959 // If duplicates were detected, allocate a result of the right size
964 // and transfer the elements. 960 // and transfer the elements.
965 if (added_descriptor_count < result->length()) { 961 if (added_descriptor_count < result->length()) {
966 Handle<DescriptorArray> new_result = 962 Handle<DescriptorArray> new_result =
967 NewDescriptorArray(added_descriptor_count); 963 NewDescriptorArray(added_descriptor_count);
968 for (int i = 0; i < added_descriptor_count; i++) { 964 for (int i = 0; i < added_descriptor_count; i++) {
969 DescriptorArray::CopyFrom(new_result, i, result, i, witness); 965 DescriptorArray::CopyFrom(new_result, i, result, i, witness);
970 } 966 }
971 result = new_result; 967 result = new_result;
972 } 968 }
973 969
974 // Sort the result before returning. 970 // Sort the result before returning.
975 result->Sort(witness); 971 result->Sort(witness);
976 ASSERT(result->NextEnumerationIndex() == next_enum);
977 return result; 972 return result;
978 } 973 }
979 974
980 975
981 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, 976 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
982 PretenureFlag pretenure) { 977 PretenureFlag pretenure) {
983 CALL_HEAP_FUNCTION( 978 CALL_HEAP_FUNCTION(
984 isolate(), 979 isolate(),
985 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); 980 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
986 } 981 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 1487
1493 1488
1494 Handle<Object> Factory::ToBoolean(bool value) { 1489 Handle<Object> Factory::ToBoolean(bool value) {
1495 return Handle<Object>(value 1490 return Handle<Object>(value
1496 ? isolate()->heap()->true_value() 1491 ? isolate()->heap()->true_value()
1497 : isolate()->heap()->false_value()); 1492 : isolate()->heap()->false_value());
1498 } 1493 }
1499 1494
1500 1495
1501 } } // namespace v8::internal 1496 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/objects.h » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698