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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 GetKeysInFixedArrayFor(object, INCLUDE_PROTOS, threw); | 697 GetKeysInFixedArrayFor(object, INCLUDE_PROTOS, threw); |
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 Isolate* isolate = object->GetIsolate(); | 704 Isolate* isolate = object->GetIsolate(); |
705 if (object->HasFastProperties()) { | 705 if (object->HasFastProperties()) { |
706 if (object->map()->instance_descriptors()->HasEnumCache()) { | 706 if (object->map()->instance_descriptors()->HasEnumCache()) { |
| 707 int own_property_count = object->map()->EnumLength(); |
| 708 |
| 709 // Mark that we have an enum cache if we are allowed to cache it. |
| 710 if (cache_result && own_property_count == Map::kInvalidEnumCache) { |
| 711 int num_enum = object->map()->NumberOfDescribedProperties(DONT_ENUM); |
| 712 object->map()->SetEnumLength(num_enum); |
| 713 } |
| 714 |
| 715 DescriptorArray* desc = object->map()->instance_descriptors(); |
| 716 Handle<FixedArray> keys(FixedArray::cast(desc->GetEnumCache()), isolate); |
| 717 |
707 isolate->counters()->enum_cache_hits()->Increment(); | 718 isolate->counters()->enum_cache_hits()->Increment(); |
708 DescriptorArray* desc = object->map()->instance_descriptors(); | 719 return keys; |
709 return Handle<FixedArray>(FixedArray::cast(desc->GetEnumCache()), | |
710 isolate); | |
711 } | 720 } |
| 721 |
| 722 Handle<Map> map(object->map()); |
| 723 |
| 724 if (map->instance_descriptors()->IsEmpty()) { |
| 725 isolate->counters()->enum_cache_hits()->Increment(); |
| 726 if (cache_result) map->SetEnumLength(0); |
| 727 return isolate->factory()->empty_fixed_array(); |
| 728 } |
| 729 |
712 isolate->counters()->enum_cache_misses()->Increment(); | 730 isolate->counters()->enum_cache_misses()->Increment(); |
713 Handle<Map> map(object->map()); | 731 |
714 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); | 732 int num_enum = map->NumberOfDescribedProperties(DONT_ENUM); |
715 | 733 |
716 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 734 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); |
717 Handle<FixedArray> indices; | 735 Handle<FixedArray> indices = isolate->factory()->NewFixedArray(num_enum); |
718 | |
719 if (cache_result) { | |
720 indices = isolate->factory()->NewFixedArray(num_enum); | |
721 } | |
722 | 736 |
723 Handle<DescriptorArray> descs = | 737 Handle<DescriptorArray> descs = |
724 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); | 738 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); |
725 | 739 |
726 int index = 0; | 740 int index = 0; |
727 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 741 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
728 if (!descs->GetDetails(i).IsDontEnum()) { | 742 PropertyDetails details = descs->GetDetails(i); |
| 743 if (!details.IsDontEnum()) { |
729 storage->set(index, descs->GetKey(i)); | 744 storage->set(index, descs->GetKey(i)); |
730 PropertyDetails details = descs->GetDetails(i); | |
731 if (!indices.is_null()) { | 745 if (!indices.is_null()) { |
732 if (details.type() != FIELD) { | 746 if (details.type() != FIELD) { |
733 indices = Handle<FixedArray>(); | 747 indices = Handle<FixedArray>(); |
734 } else { | 748 } else { |
735 int field_index = Descriptor::IndexFromValue(descs->GetValue(i)); | 749 int field_index = Descriptor::IndexFromValue(descs->GetValue(i)); |
736 if (field_index >= map->inobject_properties()) { | 750 if (field_index >= map->inobject_properties()) { |
737 field_index = -(field_index - map->inobject_properties() + 1); | 751 field_index = -(field_index - map->inobject_properties() + 1); |
738 } | 752 } |
739 indices->set(index, Smi::FromInt(field_index)); | 753 indices->set(index, Smi::FromInt(field_index)); |
740 } | 754 } |
741 } | 755 } |
742 index++; | 756 index++; |
743 } | 757 } |
744 } | 758 } |
| 759 ASSERT(index == storage->length()); |
| 760 |
| 761 Handle<FixedArray> bridge_storage = |
| 762 isolate->factory()->NewFixedArray( |
| 763 DescriptorArray::kEnumCacheBridgeLength); |
| 764 DescriptorArray* desc = object->map()->instance_descriptors(); |
| 765 desc->SetEnumCache(*bridge_storage, |
| 766 *storage, |
| 767 indices.is_null() ? Object::cast(Smi::FromInt(0)) |
| 768 : Object::cast(*indices)); |
745 if (cache_result) { | 769 if (cache_result) { |
746 Handle<FixedArray> bridge_storage = | 770 object->map()->SetEnumLength(index); |
747 isolate->factory()->NewFixedArray( | |
748 DescriptorArray::kEnumCacheBridgeLength); | |
749 DescriptorArray* desc = object->map()->instance_descriptors(); | |
750 desc->SetEnumCache(*bridge_storage, | |
751 *storage, | |
752 indices.is_null() ? Object::cast(Smi::FromInt(0)) | |
753 : Object::cast(*indices)); | |
754 } | 771 } |
755 ASSERT(storage->length() == index); | |
756 return storage; | 772 return storage; |
757 } else { | 773 } else { |
758 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); | 774 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); |
759 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 775 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); |
760 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); | 776 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); |
761 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); | 777 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); |
762 return storage; | 778 return storage; |
763 } | 779 } |
764 } | 780 } |
765 | 781 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 data->next = prev_next_; | 1000 data->next = prev_next_; |
985 data->limit = prev_limit_; | 1001 data->limit = prev_limit_; |
986 #ifdef DEBUG | 1002 #ifdef DEBUG |
987 handles_detached_ = true; | 1003 handles_detached_ = true; |
988 #endif | 1004 #endif |
989 return deferred; | 1005 return deferred; |
990 } | 1006 } |
991 | 1007 |
992 | 1008 |
993 } } // namespace v8::internal | 1009 } } // namespace v8::internal |
OLD | NEW |