OLD | NEW |
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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 isolate()->heap()->CopyCode(*code, reloc_info), | 885 isolate()->heap()->CopyCode(*code, reloc_info), |
886 Code); | 886 Code); |
887 } | 887 } |
888 | 888 |
889 | 889 |
890 MUST_USE_RESULT static inline MaybeObject* DoCopyInsert( | 890 MUST_USE_RESULT static inline MaybeObject* DoCopyInsert( |
891 DescriptorArray* array, | 891 DescriptorArray* array, |
892 String* key, | 892 String* key, |
893 Object* value, | 893 Object* value, |
894 PropertyAttributes attributes) { | 894 PropertyAttributes attributes) { |
895 CallbacksDescriptor desc(key, value, attributes); | 895 CallbacksDescriptor desc(key, value, attributes, 0); |
896 MaybeObject* obj = array->CopyInsert(&desc); | 896 MaybeObject* obj = array->CopyInsert(&desc); |
897 return obj; | 897 return obj; |
898 } | 898 } |
899 | 899 |
900 | 900 |
901 // Allocate the new array. | 901 // Allocate the new array. |
902 Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor( | 902 Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor( |
903 Handle<DescriptorArray> array, | 903 Handle<DescriptorArray> array, |
904 Handle<String> key, | 904 Handle<String> key, |
905 Handle<Object> value, | 905 Handle<Object> value, |
(...skipping 23 matching lines...) Expand all Loading... |
929 DescriptorArray::WhitenessWitness witness(*result); | 929 DescriptorArray::WhitenessWitness witness(*result); |
930 | 930 |
931 // Copy the descriptors from the array. | 931 // Copy the descriptors from the array. |
932 for (int i = 0; i < descriptor_count; i++) { | 932 for (int i = 0; i < descriptor_count; i++) { |
933 DescriptorArray::CopyFrom(result, i, array, i, witness); | 933 DescriptorArray::CopyFrom(result, i, array, i, witness); |
934 } | 934 } |
935 | 935 |
936 // Fill in new callback descriptors. Process the callbacks from | 936 // Fill in new callback descriptors. Process the callbacks from |
937 // back to front so that the last callback with a given name takes | 937 // back to front so that the last callback with a given name takes |
938 // precedence over previously added callbacks with that name. | 938 // precedence over previously added callbacks with that name. |
| 939 int added_descriptor_count = descriptor_count; |
| 940 int next_enum = array->NextEnumerationIndex(); |
939 for (int i = nof_callbacks - 1; i >= 0; i--) { | 941 for (int i = nof_callbacks - 1; i >= 0; i--) { |
940 Handle<AccessorInfo> entry = | 942 Handle<AccessorInfo> entry = |
941 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); | 943 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); |
942 // 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. |
943 Handle<String> key = | 945 Handle<String> key = |
944 SymbolFromString(Handle<String>(String::cast(entry->name()))); | 946 SymbolFromString(Handle<String>(String::cast(entry->name()))); |
945 // Check if a descriptor with this name already exists before writing. | 947 // Check if a descriptor with this name already exists before writing. |
946 if (LinearSearch(*result, EXPECT_UNSORTED, *key, descriptor_count) == | 948 if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) == |
947 DescriptorArray::kNotFound) { | 949 DescriptorArray::kNotFound) { |
948 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); | 950 CallbacksDescriptor desc(*key, |
949 result->Set(descriptor_count, &desc, witness); | 951 *entry, |
950 descriptor_count++; | 952 entry->property_attributes(), |
| 953 next_enum++); |
| 954 result->Set(added_descriptor_count, &desc, witness); |
| 955 added_descriptor_count++; |
951 } | 956 } |
952 } | 957 } |
953 | 958 |
| 959 // Return the old descriptor array if there were no new elements. |
| 960 if (added_descriptor_count == descriptor_count) return array; |
| 961 |
954 // If duplicates were detected, allocate a result of the right size | 962 // If duplicates were detected, allocate a result of the right size |
955 // and transfer the elements. | 963 // and transfer the elements. |
956 if (descriptor_count < result->length()) { | 964 if (added_descriptor_count < result->length()) { |
957 Handle<DescriptorArray> new_result = NewDescriptorArray(descriptor_count); | 965 Handle<DescriptorArray> new_result = |
958 for (int i = 0; i < descriptor_count; i++) { | 966 NewDescriptorArray(added_descriptor_count); |
| 967 for (int i = 0; i < added_descriptor_count; i++) { |
959 DescriptorArray::CopyFrom(new_result, i, result, i, witness); | 968 DescriptorArray::CopyFrom(new_result, i, result, i, witness); |
960 } | 969 } |
961 result = new_result; | 970 result = new_result; |
962 } | 971 } |
963 | 972 |
964 // Sort the result before returning. | 973 // Sort the result before returning. |
965 result->Sort(witness); | 974 result->Sort(witness); |
| 975 ASSERT(result->NextEnumerationIndex() == next_enum); |
966 return result; | 976 return result; |
967 } | 977 } |
968 | 978 |
969 | 979 |
970 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, | 980 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
971 PretenureFlag pretenure) { | 981 PretenureFlag pretenure) { |
972 CALL_HEAP_FUNCTION( | 982 CALL_HEAP_FUNCTION( |
973 isolate(), | 983 isolate(), |
974 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); | 984 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
975 } | 985 } |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 | 1491 |
1482 | 1492 |
1483 Handle<Object> Factory::ToBoolean(bool value) { | 1493 Handle<Object> Factory::ToBoolean(bool value) { |
1484 return Handle<Object>(value | 1494 return Handle<Object>(value |
1485 ? isolate()->heap()->true_value() | 1495 ? isolate()->heap()->true_value() |
1486 : isolate()->heap()->false_value()); | 1496 : isolate()->heap()->false_value()); |
1487 } | 1497 } |
1488 | 1498 |
1489 | 1499 |
1490 } } // namespace v8::internal | 1500 } } // namespace v8::internal |
OLD | NEW |