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 5783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5794 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); | 5794 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); |
5795 } | 5795 } |
5796 } | 5796 } |
5797 | 5797 |
5798 // Allocate an array with storage for all the property names. | 5798 // Allocate an array with storage for all the property names. |
5799 Handle<FixedArray> names = | 5799 Handle<FixedArray> names = |
5800 isolate->factory()->NewFixedArray(total_property_count); | 5800 isolate->factory()->NewFixedArray(total_property_count); |
5801 | 5801 |
5802 // Get the property names. | 5802 // Get the property names. |
5803 jsproto = obj; | 5803 jsproto = obj; |
5804 int proto_with_hidden_properties = 0; | |
5805 int next_copy_index = 0; | 5804 int next_copy_index = 0; |
| 5805 int hidden_strings = 0; |
5806 for (int i = 0; i < length; i++) { | 5806 for (int i = 0; i < length; i++) { |
5807 jsproto->GetLocalPropertyNames(*names, next_copy_index, filter); | 5807 jsproto->GetLocalPropertyNames(*names, next_copy_index, filter); |
| 5808 if (i > 0) { |
| 5809 // Names from hidden prototypes may already have been added |
| 5810 // for inherited function template instances. Count the duplicates |
| 5811 // and stub them out; the final copy pass at the end ignores holes. |
| 5812 for (int j = next_copy_index; |
| 5813 j < next_copy_index + local_property_count[i]; |
| 5814 j++) { |
| 5815 Object* name_from_hidden_proto = names->get(j); |
| 5816 for (int k = 0; k < next_copy_index; k++) { |
| 5817 if (names->get(k) != isolate->heap()->hidden_string()) { |
| 5818 Object* name = names->get(k); |
| 5819 if (name_from_hidden_proto == name) { |
| 5820 names->set(j, isolate->heap()->hidden_string()); |
| 5821 hidden_strings++; |
| 5822 break; |
| 5823 } |
| 5824 } |
| 5825 } |
| 5826 } |
| 5827 } |
5808 next_copy_index += local_property_count[i]; | 5828 next_copy_index += local_property_count[i]; |
5809 if (jsproto->HasHiddenProperties()) { | 5829 if (jsproto->HasHiddenProperties()) { |
5810 proto_with_hidden_properties++; | 5830 hidden_strings++; |
5811 } | 5831 } |
5812 if (i < length - 1) { | 5832 if (i < length - 1) { |
5813 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); | 5833 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); |
5814 } | 5834 } |
5815 } | 5835 } |
5816 | 5836 |
5817 // Filter out name of hidden properties object. | 5837 // Filter out name of hidden properties object and |
5818 if (proto_with_hidden_properties > 0) { | 5838 // hidden prototype duplicates. |
| 5839 if (hidden_strings > 0) { |
5819 Handle<FixedArray> old_names = names; | 5840 Handle<FixedArray> old_names = names; |
5820 names = isolate->factory()->NewFixedArray( | 5841 names = isolate->factory()->NewFixedArray( |
5821 names->length() - proto_with_hidden_properties); | 5842 names->length() - hidden_strings); |
5822 int dest_pos = 0; | 5843 int dest_pos = 0; |
5823 for (int i = 0; i < total_property_count; i++) { | 5844 for (int i = 0; i < total_property_count; i++) { |
5824 Object* name = old_names->get(i); | 5845 Object* name = old_names->get(i); |
5825 if (name == isolate->heap()->hidden_string()) { | 5846 if (name == isolate->heap()->hidden_string()) { |
| 5847 hidden_strings--; |
5826 continue; | 5848 continue; |
5827 } | 5849 } |
5828 names->set(dest_pos++, name); | 5850 names->set(dest_pos++, name); |
5829 } | 5851 } |
| 5852 ASSERT_EQ(0, hidden_strings); |
5830 } | 5853 } |
5831 | 5854 |
5832 return *isolate->factory()->NewJSArrayWithElements(names); | 5855 return *isolate->factory()->NewJSArrayWithElements(names); |
5833 } | 5856 } |
5834 | 5857 |
5835 | 5858 |
5836 // Return the names of the local indexed properties. | 5859 // Return the names of the local indexed properties. |
5837 // args[0]: object | 5860 // args[0]: object |
5838 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalElementNames) { | 5861 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalElementNames) { |
5839 HandleScope scope(isolate); | 5862 HandleScope scope(isolate); |
(...skipping 9028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14868 // Handle last resort GC and make sure to allow future allocations | 14891 // Handle last resort GC and make sure to allow future allocations |
14869 // to grow the heap without causing GCs (if possible). | 14892 // to grow the heap without causing GCs (if possible). |
14870 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14893 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14871 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14894 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14872 "Runtime::PerformGC"); | 14895 "Runtime::PerformGC"); |
14873 } | 14896 } |
14874 } | 14897 } |
14875 | 14898 |
14876 | 14899 |
14877 } } // namespace v8::internal | 14900 } } // namespace v8::internal |
OLD | NEW |