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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 return isolate->factory()->NewJSArrayWithElements(elements); | 698 return isolate->factory()->NewJSArrayWithElements(elements); |
699 } | 699 } |
700 | 700 |
701 | 701 |
702 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, | 702 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, |
703 bool cache_result) { | 703 bool cache_result) { |
704 int index = 0; | 704 int index = 0; |
705 Isolate* isolate = object->GetIsolate(); | 705 Isolate* isolate = object->GetIsolate(); |
706 if (object->HasFastProperties()) { | 706 if (object->HasFastProperties()) { |
707 if (object->map()->instance_descriptors()->HasEnumCache()) { | 707 if (object->map()->instance_descriptors()->HasEnumCache()) { |
708 int own_property_count = object->map()->EnumLength(); | |
709 | |
710 // Mark that we have an enum cache if we are allowed to cache it. | |
711 if (cache_result && own_property_count == Map::kInvalidEnumCache) { | |
712 int num_enum = object->map()->NumberOfDescribedProperties(DONT_ENUM); | |
713 object->map()->SetEnumLength(num_enum); | |
714 } | |
715 | |
716 DescriptorArray* desc = object->map()->instance_descriptors(); | |
717 Handle<FixedArray> keys(FixedArray::cast(desc->GetEnumCache()), isolate); | |
718 | |
708 isolate->counters()->enum_cache_hits()->Increment(); | 719 isolate->counters()->enum_cache_hits()->Increment(); |
709 DescriptorArray* desc = object->map()->instance_descriptors(); | 720 return keys; |
710 return Handle<FixedArray>(FixedArray::cast(desc->GetEnumCache()), | |
711 isolate); | |
712 } | 721 } |
722 | |
723 Handle<Map> map(object->map()); | |
724 | |
725 if (map->instance_descriptors()->IsEmpty()) { | |
726 // Count encountering the empty descriptor array as a cache hit. | |
Michael Starzinger
2012/08/06 15:06:22
Hmm, "encountering" is an adjective, I would just
Toon Verwaest
2012/08/07 10:49:47
Done.
| |
727 isolate->counters()->enum_cache_hits()->Increment(); | |
728 if (cache_result) map->SetEnumLength(0); | |
729 return Handle<FixedArray>(isolate->factory()->empty_fixed_array()); | |
Michael Starzinger
2012/08/06 15:06:22
No need for a copy constructor of the handle here!
Toon Verwaest
2012/08/07 10:49:47
Done.
| |
730 } | |
731 | |
713 isolate->counters()->enum_cache_misses()->Increment(); | 732 isolate->counters()->enum_cache_misses()->Increment(); |
714 Handle<Map> map(object->map()); | |
715 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); | |
716 | 733 |
717 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 734 int num_enum = map->NumberOfDescribedProperties(DONT_ENUM); |
718 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); | 735 |
736 Handle<FixedArray> storage; | |
737 Handle<FixedArray> sort_array; | |
719 | 738 |
720 Handle<FixedArray> indices; | 739 Handle<FixedArray> indices; |
721 Handle<FixedArray> sort_array2; | 740 Handle<FixedArray> sort_array2; |
722 | 741 |
723 if (cache_result) { | 742 storage = isolate->factory()->NewFixedArray(num_enum); |
Michael Starzinger
2012/08/06 15:06:22
Can we just merge the handle declarations and the
Toon Verwaest
2012/08/07 10:49:47
Done.
| |
724 indices = isolate->factory()->NewFixedArray(num_enum); | 743 sort_array = isolate->factory()->NewFixedArray(num_enum); |
725 sort_array2 = isolate->factory()->NewFixedArray(num_enum); | 744 indices = isolate->factory()->NewFixedArray(num_enum); |
726 } | 745 sort_array2 = isolate->factory()->NewFixedArray(num_enum); |
727 | 746 |
728 Handle<DescriptorArray> descs = | 747 Handle<DescriptorArray> descs = |
729 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); | 748 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); |
730 | 749 |
731 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 750 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
732 if (!descs->GetDetails(i).IsDontEnum()) { | 751 PropertyDetails details = descs->GetDetails(i); |
752 if (!details.IsDontEnum()) { | |
733 storage->set(index, descs->GetKey(i)); | 753 storage->set(index, descs->GetKey(i)); |
734 PropertyDetails details = descs->GetDetails(i); | |
735 sort_array->set(index, Smi::FromInt(details.index())); | 754 sort_array->set(index, Smi::FromInt(details.index())); |
736 if (!indices.is_null()) { | 755 if (!indices.is_null()) { |
737 if (details.type() != FIELD) { | 756 if (details.type() != FIELD) { |
738 indices = Handle<FixedArray>(); | 757 indices = Handle<FixedArray>(); |
739 sort_array2 = Handle<FixedArray>(); | 758 sort_array2 = Handle<FixedArray>(); |
740 } else { | 759 } else { |
741 int field_index = Descriptor::IndexFromValue(descs->GetValue(i)); | 760 int field_index = Descriptor::IndexFromValue(descs->GetValue(i)); |
742 if (field_index >= map->inobject_properties()) { | 761 if (field_index >= map->inobject_properties()) { |
743 field_index = -(field_index - map->inobject_properties() + 1); | 762 field_index = -(field_index - map->inobject_properties() + 1); |
744 } | 763 } |
745 indices->set(index, Smi::FromInt(field_index)); | 764 indices->set(index, Smi::FromInt(field_index)); |
746 sort_array2->set(index, Smi::FromInt(details.index())); | 765 sort_array2->set(index, Smi::FromInt(details.index())); |
747 } | 766 } |
748 } | 767 } |
749 index++; | 768 index++; |
750 } | 769 } |
751 } | 770 } |
771 ASSERT(index == storage->length()); | |
772 | |
752 storage->SortPairs(*sort_array, sort_array->length()); | 773 storage->SortPairs(*sort_array, sort_array->length()); |
753 if (!indices.is_null()) { | 774 if (!indices.is_null()) { |
754 indices->SortPairs(*sort_array2, sort_array2->length()); | 775 indices->SortPairs(*sort_array2, sort_array2->length()); |
755 } | 776 } |
777 | |
778 Handle<FixedArray> bridge_storage = | |
779 isolate->factory()->NewFixedArray( | |
780 DescriptorArray::kEnumCacheBridgeLength); | |
781 DescriptorArray* desc = object->map()->instance_descriptors(); | |
782 desc->SetEnumCache(*bridge_storage, | |
783 *storage, | |
784 indices.is_null() ? Object::cast(Smi::FromInt(0)) | |
785 : Object::cast(*indices)); | |
756 if (cache_result) { | 786 if (cache_result) { |
757 Handle<FixedArray> bridge_storage = | 787 object->map()->SetEnumLength(index); |
758 isolate->factory()->NewFixedArray( | |
759 DescriptorArray::kEnumCacheBridgeLength); | |
760 DescriptorArray* desc = object->map()->instance_descriptors(); | |
761 desc->SetEnumCache(*bridge_storage, | |
762 *storage, | |
763 indices.is_null() ? Object::cast(Smi::FromInt(0)) | |
764 : Object::cast(*indices)); | |
765 } | 788 } |
766 ASSERT(storage->length() == index); | |
767 return storage; | 789 return storage; |
768 } else { | 790 } else { |
769 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); | 791 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); |
770 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 792 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); |
771 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); | 793 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); |
772 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); | 794 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); |
773 return storage; | 795 return storage; |
774 } | 796 } |
775 } | 797 } |
776 | 798 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 data->next = prev_next_; | 1017 data->next = prev_next_; |
996 data->limit = prev_limit_; | 1018 data->limit = prev_limit_; |
997 #ifdef DEBUG | 1019 #ifdef DEBUG |
998 handles_detached_ = true; | 1020 handles_detached_ = true; |
999 #endif | 1021 #endif |
1000 return deferred; | 1022 return deferred; |
1001 } | 1023 } |
1002 | 1024 |
1003 | 1025 |
1004 } } // namespace v8::internal | 1026 } } // namespace v8::internal |
OLD | NEW |