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 5784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5795 } | 5795 } |
5796 | 5796 |
5797 // Allocate an array with storage for all the property names. | 5797 // Allocate an array with storage for all the property names. |
5798 Handle<FixedArray> names = | 5798 Handle<FixedArray> names = |
5799 isolate->factory()->NewFixedArray(total_property_count); | 5799 isolate->factory()->NewFixedArray(total_property_count); |
5800 | 5800 |
5801 // Get the property names. | 5801 // Get the property names. |
5802 jsproto = obj; | 5802 jsproto = obj; |
5803 int proto_with_hidden_properties = 0; | 5803 int proto_with_hidden_properties = 0; |
5804 int next_copy_index = 0; | 5804 int next_copy_index = 0; |
5805 int duplicates = 0; | |
5805 for (int i = 0; i < length; i++) { | 5806 for (int i = 0; i < length; i++) { |
5806 jsproto->GetLocalPropertyNames(*names, next_copy_index, filter); | 5807 jsproto->GetLocalPropertyNames(*names, next_copy_index, filter); |
5808 if (i > 0 && jsproto->map()->is_hidden_prototype()) { | |
dcarney
2013/12/26 13:26:58
this should just be i > 0
sof
2013/12/26 21:48:45
Done.
| |
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 RUNTIME_ASSERT(names->get(j)->IsString()); | |
dcarney
2013/12/24 08:48:08
I don't think these asserts are necessary, but the
sof
2013/12/26 21:48:45
Gone; I kept the use of String (rather than Name.)
| |
5816 String* name_from_hidden_proto = String::cast(names->get(j)); | |
5817 for (int k = 0; k < next_copy_index; k++) { | |
5818 if (!names->get(k)->IsTheHole() && | |
dcarney
2013/12/24 08:48:08
no need for a hole check here, see last comment
| |
5819 names->get(k) != isolate->heap()->hidden_string()) { | |
5820 RUNTIME_ASSERT(names->get(k)->IsString()); | |
5821 String* name = String::cast(names->get(k)); | |
5822 if (name_from_hidden_proto->Equals(name)) { | |
dcarney
2013/12/24 08:48:08
all Name keys for properties are either symbols or
| |
5823 names->set_the_hole(j); | |
5824 duplicates++; | |
5825 break; | |
5826 } | |
5827 } | |
5828 } | |
5829 } | |
5830 } | |
5807 next_copy_index += local_property_count[i]; | 5831 next_copy_index += local_property_count[i]; |
5808 if (jsproto->HasHiddenProperties()) { | 5832 if (jsproto->HasHiddenProperties()) { |
5809 proto_with_hidden_properties++; | 5833 proto_with_hidden_properties++; |
5810 } | 5834 } |
5811 if (i < length - 1) { | 5835 if (i < length - 1) { |
5812 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); | 5836 jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype())); |
5813 } | 5837 } |
5814 } | 5838 } |
5815 | 5839 |
5816 // Filter out name of hidden properties object. | 5840 // Filter out name of hidden properties object and |
5817 if (proto_with_hidden_properties > 0) { | 5841 // hidden prototype duplicates. |
5842 if (proto_with_hidden_properties > 0 || duplicates > 0) { | |
dcarney
2013/12/24 08:48:08
maybe merge these 2 variables into a single duplic
dcarney
2013/12/26 13:26:58
actually, a better solution might be to call this
sof
2013/12/26 21:48:45
Nice redux; done.
| |
5818 Handle<FixedArray> old_names = names; | 5843 Handle<FixedArray> old_names = names; |
5819 names = isolate->factory()->NewFixedArray( | 5844 names = isolate->factory()->NewFixedArray( |
5820 names->length() - proto_with_hidden_properties); | 5845 names->length() - proto_with_hidden_properties - duplicates); |
5821 int dest_pos = 0; | 5846 int dest_pos = 0; |
5822 for (int i = 0; i < total_property_count; i++) { | 5847 for (int i = 0; i < total_property_count; i++) { |
5823 Object* name = old_names->get(i); | 5848 Object* name = old_names->get(i); |
5824 if (name == isolate->heap()->hidden_string()) { | 5849 if (name->IsTheHole()) continue; |
5825 continue; | 5850 if (name == isolate->heap()->hidden_string()) continue; |
5826 } | |
5827 names->set(dest_pos++, name); | 5851 names->set(dest_pos++, name); |
5828 } | 5852 } |
5829 } | 5853 } |
5830 | 5854 |
5831 return *isolate->factory()->NewJSArrayWithElements(names); | 5855 return *isolate->factory()->NewJSArrayWithElements(names); |
5832 } | 5856 } |
5833 | 5857 |
5834 | 5858 |
5835 // Return the names of the local indexed properties. | 5859 // Return the names of the local indexed properties. |
5836 // args[0]: object | 5860 // args[0]: object |
(...skipping 9066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14903 // Handle last resort GC and make sure to allow future allocations | 14927 // Handle last resort GC and make sure to allow future allocations |
14904 // to grow the heap without causing GCs (if possible). | 14928 // to grow the heap without causing GCs (if possible). |
14905 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14929 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14906 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14930 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14907 "Runtime::PerformGC"); | 14931 "Runtime::PerformGC"); |
14908 } | 14932 } |
14909 } | 14933 } |
14910 | 14934 |
14911 | 14935 |
14912 } } // namespace v8::internal | 14936 } } // namespace v8::internal |
OLD | NEW |