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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 DescriptorArray::WhitenessWitness witness(*result); | 905 DescriptorArray::WhitenessWitness witness(*result); |
906 | 906 |
907 // Copy the descriptors from the array. | 907 // Copy the descriptors from the array. |
908 if (0 < descriptor_count) { | 908 if (0 < descriptor_count) { |
909 result->SetLastAdded(array->LastAdded()); | 909 result->SetLastAdded(array->LastAdded()); |
910 for (int i = 0; i < descriptor_count; i++) { | 910 for (int i = 0; i < descriptor_count; i++) { |
911 result->CopyFrom(i, *array, i, witness); | 911 result->CopyFrom(i, *array, i, witness); |
912 } | 912 } |
913 } | 913 } |
914 | 914 |
| 915 map->set_instance_descriptors(*result); |
| 916 |
915 // Fill in new callback descriptors. Process the callbacks from | 917 // Fill in new callback descriptors. Process the callbacks from |
916 // back to front so that the last callback with a given name takes | 918 // back to front so that the last callback with a given name takes |
917 // precedence over previously added callbacks with that name. | 919 // precedence over previously added callbacks with that name. |
918 for (int i = nof_callbacks - 1; i >= 0; i--) { | 920 for (int i = nof_callbacks - 1; i >= 0; i--) { |
919 Handle<AccessorInfo> entry = | 921 Handle<AccessorInfo> entry = |
920 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); | 922 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); |
921 // Ensure the key is a symbol before writing into the instance descriptor. | 923 // Ensure the key is a symbol before writing into the instance descriptor. |
922 Handle<String> key = | 924 Handle<String> key = |
923 SymbolFromString(Handle<String>(String::cast(entry->name()))); | 925 SymbolFromString(Handle<String>(String::cast(entry->name()))); |
924 // Check if a descriptor with this name already exists before writing. | 926 // Check if a descriptor with this name already exists before writing. |
925 if (LinearSearch(*result, *key, result->NumberOfSetDescriptors()) == | 927 if (LinearSearch(*result, *key, result->NumberOfSetDescriptors()) == |
926 DescriptorArray::kNotFound) { | 928 DescriptorArray::kNotFound) { |
927 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); | 929 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); |
928 result->Append(&desc, witness); | 930 map->AppendDescriptor(&desc, witness); |
929 } | 931 } |
930 } | 932 } |
931 | 933 |
932 int new_number_of_descriptors = result->NumberOfSetDescriptors(); | 934 int new_number_of_descriptors = result->NumberOfSetDescriptors(); |
933 // Don't replace the descriptor array if there were no new elements. | 935 // Reinstall the original descriptor array if no new elements were added. |
934 if (new_number_of_descriptors == descriptor_count) return; | 936 if (new_number_of_descriptors == descriptor_count) { |
| 937 map->set_instance_descriptors(*array); |
| 938 return; |
| 939 } |
935 | 940 |
936 // If duplicates were detected, allocate a result of the right size | 941 // If duplicates were detected, allocate a result of the right size |
937 // and transfer the elements. | 942 // and transfer the elements. |
938 if (new_number_of_descriptors < result->length()) { | 943 if (new_number_of_descriptors < result->length()) { |
939 Handle<DescriptorArray> new_result = | 944 Handle<DescriptorArray> new_result = |
940 NewDescriptorArray(new_number_of_descriptors); | 945 NewDescriptorArray(new_number_of_descriptors); |
941 for (int i = 0; i < new_number_of_descriptors; i++) { | 946 for (int i = 0; i < new_number_of_descriptors; i++) { |
942 new_result->CopyFrom(i, *result, i, witness); | 947 new_result->CopyFrom(i, *result, i, witness); |
943 } | 948 } |
944 new_result->SetLastAdded(result->LastAdded()); | 949 new_result->SetLastAdded(result->LastAdded()); |
945 result = new_result; | 950 map->set_instance_descriptors(*new_result); |
946 } | 951 } |
947 | |
948 map->set_instance_descriptors(*result); | |
949 } | 952 } |
950 | 953 |
951 | 954 |
952 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, | 955 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
953 PretenureFlag pretenure) { | 956 PretenureFlag pretenure) { |
954 CALL_HEAP_FUNCTION( | 957 CALL_HEAP_FUNCTION( |
955 isolate(), | 958 isolate(), |
956 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); | 959 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
957 } | 960 } |
958 | 961 |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 | 1461 |
1459 | 1462 |
1460 Handle<Object> Factory::ToBoolean(bool value) { | 1463 Handle<Object> Factory::ToBoolean(bool value) { |
1461 return Handle<Object>(value | 1464 return Handle<Object>(value |
1462 ? isolate()->heap()->true_value() | 1465 ? isolate()->heap()->true_value() |
1463 : isolate()->heap()->false_value()); | 1466 : isolate()->heap()->false_value()); |
1464 } | 1467 } |
1465 | 1468 |
1466 | 1469 |
1467 } } // namespace v8::internal | 1470 } } // namespace v8::internal |
OLD | NEW |