OLD | NEW |
1 // Copyright 2011 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 // This seems a bit hackish, but we need to make sure Array.length | 887 // This seems a bit hackish, but we need to make sure Array.length |
888 // is 1. | 888 // is 1. |
889 array_function->shared()->set_length(1); | 889 array_function->shared()->set_length(1); |
890 Handle<DescriptorArray> array_descriptors = | 890 Handle<DescriptorArray> array_descriptors = |
891 factory->CopyAppendForeignDescriptor( | 891 factory->CopyAppendForeignDescriptor( |
892 factory->empty_descriptor_array(), | 892 factory->empty_descriptor_array(), |
893 factory->length_symbol(), | 893 factory->length_symbol(), |
894 factory->NewForeign(&Accessors::ArrayLength), | 894 factory->NewForeign(&Accessors::ArrayLength), |
895 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); | 895 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); |
896 | 896 |
897 // Cache the fast JavaScript array map | |
898 global_context()->set_js_array_map(array_function->initial_map()); | |
899 global_context()->js_array_map()->set_instance_descriptors( | |
900 *array_descriptors); | |
901 // array_function is used internally. JS code creating array object should | 897 // array_function is used internally. JS code creating array object should |
902 // search for the 'Array' property on the global object and use that one | 898 // search for the 'Array' property on the global object and use that one |
903 // as the constructor. 'Array' property on a global object can be | 899 // as the constructor. 'Array' property on a global object can be |
904 // overwritten by JS code. | 900 // overwritten by JS code. |
905 global_context()->set_array_function(*array_function); | 901 global_context()->set_array_function(*array_function); |
| 902 array_function->initial_map()->set_instance_descriptors(*array_descriptors); |
906 } | 903 } |
907 | 904 |
908 { // --- N u m b e r --- | 905 { // --- N u m b e r --- |
909 Handle<JSFunction> number_fun = | 906 Handle<JSFunction> number_fun = |
910 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 907 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
911 isolate->initial_object_prototype(), | 908 isolate->initial_object_prototype(), |
912 Builtins::kIllegal, true); | 909 Builtins::kIllegal, true); |
913 global_context()->set_number_function(*number_fun); | 910 global_context()->set_number_function(*number_fun); |
914 } | 911 } |
915 | 912 |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 array_function->shared()->DontAdaptArguments(); | 1636 array_function->shared()->DontAdaptArguments(); |
1640 | 1637 |
1641 // InternalArrays should not use Smi-Only array optimizations. There are too | 1638 // InternalArrays should not use Smi-Only array optimizations. There are too |
1642 // many places in the C++ runtime code (e.g. RegEx) that assume that | 1639 // many places in the C++ runtime code (e.g. RegEx) that assume that |
1643 // elements in InternalArrays can be set to non-Smi values without going | 1640 // elements in InternalArrays can be set to non-Smi values without going |
1644 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT | 1641 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT |
1645 // transition easy to trap. Moreover, they rarely are smi-only. | 1642 // transition easy to trap. Moreover, they rarely are smi-only. |
1646 MaybeObject* maybe_map = | 1643 MaybeObject* maybe_map = |
1647 array_function->initial_map()->CopyDropTransitions(); | 1644 array_function->initial_map()->CopyDropTransitions(); |
1648 Map* new_map; | 1645 Map* new_map; |
1649 if (!maybe_map->To<Map>(&new_map)) return maybe_map; | 1646 if (!maybe_map->To<Map>(&new_map)) return false; |
1650 new_map->set_elements_kind(FAST_ELEMENTS); | 1647 new_map->set_elements_kind(FAST_ELEMENTS); |
1651 array_function->set_initial_map(new_map); | 1648 array_function->set_initial_map(new_map); |
1652 | 1649 |
1653 // Make "length" magic on instances. | 1650 // Make "length" magic on instances. |
1654 Handle<DescriptorArray> array_descriptors = | 1651 Handle<DescriptorArray> array_descriptors = |
1655 factory()->CopyAppendForeignDescriptor( | 1652 factory()->CopyAppendForeignDescriptor( |
1656 factory()->empty_descriptor_array(), | 1653 factory()->empty_descriptor_array(), |
1657 factory()->length_symbol(), | 1654 factory()->length_symbol(), |
1658 factory()->NewForeign(&Accessors::ArrayLength), | 1655 factory()->NewForeign(&Accessors::ArrayLength), |
1659 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); | 1656 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 // Add initial map. | 1735 // Add initial map. |
1739 Handle<Map> initial_map = | 1736 Handle<Map> initial_map = |
1740 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); | 1737 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); |
1741 initial_map->set_constructor(*array_constructor); | 1738 initial_map->set_constructor(*array_constructor); |
1742 | 1739 |
1743 // Set prototype on map. | 1740 // Set prototype on map. |
1744 initial_map->set_non_instance_prototype(false); | 1741 initial_map->set_non_instance_prototype(false); |
1745 initial_map->set_prototype(*array_prototype); | 1742 initial_map->set_prototype(*array_prototype); |
1746 | 1743 |
1747 // Update map with length accessor from Array and add "index" and "input". | 1744 // Update map with length accessor from Array and add "index" and "input". |
1748 Handle<Map> array_map(global_context()->js_array_map()); | |
1749 Handle<DescriptorArray> array_descriptors( | |
1750 array_map->instance_descriptors()); | |
1751 ASSERT_EQ(1, array_descriptors->number_of_descriptors()); | |
1752 | |
1753 Handle<DescriptorArray> reresult_descriptors = | 1745 Handle<DescriptorArray> reresult_descriptors = |
1754 factory()->NewDescriptorArray(3); | 1746 factory()->NewDescriptorArray(3); |
1755 | |
1756 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); | 1747 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); |
1757 | 1748 |
1758 reresult_descriptors->CopyFrom(0, *array_descriptors, 0, witness); | 1749 JSFunction* array_function = global_context()->array_function(); |
| 1750 Handle<DescriptorArray> array_descriptors( |
| 1751 array_function->initial_map()->instance_descriptors()); |
| 1752 int index = array_descriptors->SearchWithCache(heap()->length_symbol()); |
| 1753 reresult_descriptors->CopyFrom(0, *array_descriptors, index, witness); |
1759 | 1754 |
1760 int enum_index = 0; | 1755 int enum_index = 0; |
1761 { | 1756 { |
1762 FieldDescriptor index_field(heap()->index_symbol(), | 1757 FieldDescriptor index_field(heap()->index_symbol(), |
1763 JSRegExpResult::kIndexIndex, | 1758 JSRegExpResult::kIndexIndex, |
1764 NONE, | 1759 NONE, |
1765 enum_index++); | 1760 enum_index++); |
1766 reresult_descriptors->Set(1, &index_field, witness); | 1761 reresult_descriptors->Set(1, &index_field, witness); |
1767 } | 1762 } |
1768 | 1763 |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 return from + sizeof(NestingCounterType); | 2369 return from + sizeof(NestingCounterType); |
2375 } | 2370 } |
2376 | 2371 |
2377 | 2372 |
2378 // Called when the top-level V8 mutex is destroyed. | 2373 // Called when the top-level V8 mutex is destroyed. |
2379 void Bootstrapper::FreeThreadResources() { | 2374 void Bootstrapper::FreeThreadResources() { |
2380 ASSERT(!IsActive()); | 2375 ASSERT(!IsActive()); |
2381 } | 2376 } |
2382 | 2377 |
2383 } } // namespace v8::internal | 2378 } } // namespace v8::internal |
OLD | NEW |