OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/extensions/externalize-string-extension.h" | 9 #include "src/extensions/externalize-string-extension.h" |
10 #include "src/extensions/free-buffer-extension.h" | 10 #include "src/extensions/free-buffer-extension.h" |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1120 |
1121 Handle<JSFunction> data_view_fun = | 1121 Handle<JSFunction> data_view_fun = |
1122 InstallFunction( | 1122 InstallFunction( |
1123 global, "DataView", JS_DATA_VIEW_TYPE, | 1123 global, "DataView", JS_DATA_VIEW_TYPE, |
1124 JSDataView::kSizeWithInternalFields, | 1124 JSDataView::kSizeWithInternalFields, |
1125 isolate->initial_object_prototype(), | 1125 isolate->initial_object_prototype(), |
1126 Builtins::kIllegal); | 1126 Builtins::kIllegal); |
1127 native_context()->set_data_view_fun(*data_view_fun); | 1127 native_context()->set_data_view_fun(*data_view_fun); |
1128 } | 1128 } |
1129 | 1129 |
| 1130 // -- M a p |
| 1131 InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize, |
| 1132 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1133 |
| 1134 // -- S e t |
| 1135 InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, |
| 1136 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1137 |
| 1138 { // Set up the iterator result object |
| 1139 STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2); |
| 1140 Handle<JSFunction> object_function(native_context()->object_function()); |
| 1141 ASSERT(object_function->initial_map()->inobject_properties() == 0); |
| 1142 Handle<Map> iterator_result_map = |
| 1143 Map::Create(object_function, JSGeneratorObject::kResultPropertyCount); |
| 1144 ASSERT(iterator_result_map->inobject_properties() == |
| 1145 JSGeneratorObject::kResultPropertyCount); |
| 1146 Map::EnsureDescriptorSlack(iterator_result_map, |
| 1147 JSGeneratorObject::kResultPropertyCount); |
| 1148 |
| 1149 FieldDescriptor value_descr(factory->value_string(), |
| 1150 JSGeneratorObject::kResultValuePropertyIndex, |
| 1151 NONE, Representation::Tagged()); |
| 1152 iterator_result_map->AppendDescriptor(&value_descr); |
| 1153 |
| 1154 FieldDescriptor done_descr(factory->done_string(), |
| 1155 JSGeneratorObject::kResultDonePropertyIndex, |
| 1156 NONE, Representation::Tagged()); |
| 1157 iterator_result_map->AppendDescriptor(&done_descr); |
| 1158 |
| 1159 iterator_result_map->set_unused_property_fields(0); |
| 1160 ASSERT_EQ(JSGeneratorObject::kResultSize, |
| 1161 iterator_result_map->instance_size()); |
| 1162 native_context()->set_iterator_result_map(*iterator_result_map); |
| 1163 } |
| 1164 |
1130 // -- W e a k M a p | 1165 // -- W e a k M a p |
1131 InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, | 1166 InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, |
1132 isolate->initial_object_prototype(), Builtins::kIllegal); | 1167 isolate->initial_object_prototype(), Builtins::kIllegal); |
1133 // -- W e a k S e t | 1168 // -- W e a k S e t |
1134 InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, | 1169 InstallFunction(global, "WeakSet", JS_WEAK_SET_TYPE, JSWeakSet::kSize, |
1135 isolate->initial_object_prototype(), Builtins::kIllegal); | 1170 isolate->initial_object_prototype(), Builtins::kIllegal); |
1136 | 1171 |
| 1172 { |
| 1173 // --- S y m b o l --- |
| 1174 Handle<JSFunction> symbol_fun = InstallFunction( |
| 1175 global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, |
| 1176 isolate->initial_object_prototype(), Builtins::kIllegal); |
| 1177 native_context()->set_symbol_function(*symbol_fun); |
| 1178 } |
| 1179 |
1137 { // --- sloppy arguments map | 1180 { // --- sloppy arguments map |
1138 // Make sure we can recognize argument objects at runtime. | 1181 // Make sure we can recognize argument objects at runtime. |
1139 // This is done by introducing an anonymous function with | 1182 // This is done by introducing an anonymous function with |
1140 // class_name equals 'Arguments'. | 1183 // class_name equals 'Arguments'. |
1141 Handle<String> arguments_string = factory->InternalizeOneByteString( | 1184 Handle<String> arguments_string = factory->InternalizeOneByteString( |
1142 STATIC_ASCII_VECTOR("Arguments")); | 1185 STATIC_ASCII_VECTOR("Arguments")); |
1143 Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); | 1186 Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); |
1144 Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( | 1187 Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( |
1145 arguments_string, code); | 1188 arguments_string, code); |
1146 function->shared()->set_instance_class_name(*arguments_string); | 1189 function->shared()->set_instance_class_name(*arguments_string); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 result->set_initial_map(*initial_map); | 1339 result->set_initial_map(*initial_map); |
1297 initial_map->set_constructor(*result); | 1340 initial_map->set_constructor(*result); |
1298 *fun = result; | 1341 *fun = result; |
1299 | 1342 |
1300 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind); | 1343 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind); |
1301 *external_map = Map::AsElementsKind(initial_map, external_kind); | 1344 *external_map = Map::AsElementsKind(initial_map, external_kind); |
1302 } | 1345 } |
1303 | 1346 |
1304 | 1347 |
1305 void Genesis::InitializeExperimentalGlobal() { | 1348 void Genesis::InitializeExperimentalGlobal() { |
1306 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | |
1307 | |
1308 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no | 1349 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no |
1309 // longer need to live behind flags, so functions get added to the snapshot. | 1350 // longer need to live behind flags, so functions get added to the snapshot. |
1310 | 1351 |
1311 if (FLAG_harmony_symbols) { | |
1312 // --- S y m b o l --- | |
1313 Handle<JSFunction> symbol_fun = InstallFunction( | |
1314 global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, | |
1315 isolate()->initial_object_prototype(), Builtins::kIllegal); | |
1316 native_context()->set_symbol_function(*symbol_fun); | |
1317 } | |
1318 | |
1319 if (FLAG_harmony_collections) { | |
1320 // -- M a p | |
1321 InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize, | |
1322 isolate()->initial_object_prototype(), Builtins::kIllegal); | |
1323 // -- S e t | |
1324 InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, | |
1325 isolate()->initial_object_prototype(), Builtins::kIllegal); | |
1326 { // -- S e t I t e r a t o r | |
1327 Handle<JSObject> builtins(native_context()->builtins()); | |
1328 Handle<JSFunction> set_iterator_function = | |
1329 InstallFunction(builtins, "SetIterator", JS_SET_ITERATOR_TYPE, | |
1330 JSSetIterator::kSize, | |
1331 isolate()->initial_object_prototype(), | |
1332 Builtins::kIllegal); | |
1333 native_context()->set_set_iterator_map( | |
1334 set_iterator_function->initial_map()); | |
1335 } | |
1336 { // -- M a p I t e r a t o r | |
1337 Handle<JSObject> builtins(native_context()->builtins()); | |
1338 Handle<JSFunction> map_iterator_function = | |
1339 InstallFunction(builtins, "MapIterator", JS_MAP_ITERATOR_TYPE, | |
1340 JSMapIterator::kSize, | |
1341 isolate()->initial_object_prototype(), | |
1342 Builtins::kIllegal); | |
1343 native_context()->set_map_iterator_map( | |
1344 map_iterator_function->initial_map()); | |
1345 } | |
1346 } | |
1347 | |
1348 if (FLAG_harmony_generators) { | 1352 if (FLAG_harmony_generators) { |
1349 // Create generator meta-objects and install them on the builtins object. | 1353 // Create generator meta-objects and install them on the builtins object. |
1350 Handle<JSObject> builtins(native_context()->builtins()); | 1354 Handle<JSObject> builtins(native_context()->builtins()); |
1351 Handle<JSObject> generator_object_prototype = | 1355 Handle<JSObject> generator_object_prototype = |
1352 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1356 factory()->NewJSObject(isolate()->object_function(), TENURED); |
1353 Handle<JSFunction> generator_function_prototype = InstallFunction( | 1357 Handle<JSFunction> generator_function_prototype = InstallFunction( |
1354 builtins, "GeneratorFunctionPrototype", JS_FUNCTION_TYPE, | 1358 builtins, "GeneratorFunctionPrototype", JS_FUNCTION_TYPE, |
1355 JSFunction::kHeaderSize, generator_object_prototype, | 1359 JSFunction::kHeaderSize, generator_object_prototype, |
1356 Builtins::kIllegal); | 1360 Builtins::kIllegal); |
1357 InstallFunction(builtins, "GeneratorFunction", | 1361 InstallFunction(builtins, "GeneratorFunction", |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 *strict_generator_function_map); | 1403 *strict_generator_function_map); |
1400 | 1404 |
1401 Handle<JSFunction> object_function(native_context()->object_function()); | 1405 Handle<JSFunction> object_function(native_context()->object_function()); |
1402 Handle<Map> generator_object_prototype_map = Map::Create( | 1406 Handle<Map> generator_object_prototype_map = Map::Create( |
1403 object_function, 0); | 1407 object_function, 0); |
1404 generator_object_prototype_map->set_prototype( | 1408 generator_object_prototype_map->set_prototype( |
1405 *generator_object_prototype); | 1409 *generator_object_prototype); |
1406 native_context()->set_generator_object_prototype_map( | 1410 native_context()->set_generator_object_prototype_map( |
1407 *generator_object_prototype_map); | 1411 *generator_object_prototype_map); |
1408 } | 1412 } |
1409 | |
1410 if (FLAG_harmony_collections || FLAG_harmony_generators) { | |
1411 // Collection forEach uses an iterator result object. | |
1412 // Generators return iteraror result objects. | |
1413 | |
1414 STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2); | |
1415 Handle<JSFunction> object_function(native_context()->object_function()); | |
1416 ASSERT(object_function->initial_map()->inobject_properties() == 0); | |
1417 Handle<Map> iterator_result_map = Map::Create( | |
1418 object_function, JSGeneratorObject::kResultPropertyCount); | |
1419 ASSERT(iterator_result_map->inobject_properties() == | |
1420 JSGeneratorObject::kResultPropertyCount); | |
1421 Map::EnsureDescriptorSlack( | |
1422 iterator_result_map, JSGeneratorObject::kResultPropertyCount); | |
1423 | |
1424 FieldDescriptor value_descr(isolate()->factory()->value_string(), | |
1425 JSGeneratorObject::kResultValuePropertyIndex, | |
1426 NONE, | |
1427 Representation::Tagged()); | |
1428 iterator_result_map->AppendDescriptor(&value_descr); | |
1429 | |
1430 FieldDescriptor done_descr(isolate()->factory()->done_string(), | |
1431 JSGeneratorObject::kResultDonePropertyIndex, | |
1432 NONE, | |
1433 Representation::Tagged()); | |
1434 iterator_result_map->AppendDescriptor(&done_descr); | |
1435 | |
1436 iterator_result_map->set_unused_property_fields(0); | |
1437 ASSERT_EQ(JSGeneratorObject::kResultSize, | |
1438 iterator_result_map->instance_size()); | |
1439 native_context()->set_iterator_result_map(*iterator_result_map); | |
1440 } | |
1441 } | 1413 } |
1442 | 1414 |
1443 | 1415 |
1444 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { | 1416 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { |
1445 Vector<const char> name = Natives::GetScriptName(index); | 1417 Vector<const char> name = Natives::GetScriptName(index); |
1446 Handle<String> source_code = | 1418 Handle<String> source_code = |
1447 isolate->bootstrapper()->NativesSourceLookup(index); | 1419 isolate->bootstrapper()->NativesSourceLookup(index); |
1448 return CompileNative(isolate, name, source_code); | 1420 return CompileNative(isolate, name, source_code); |
1449 } | 1421 } |
1450 | 1422 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", | 1548 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", |
1577 observers_begin_perform_splice); | 1549 observers_begin_perform_splice); |
1578 INSTALL_NATIVE(JSFunction, "EndPerformSplice", | 1550 INSTALL_NATIVE(JSFunction, "EndPerformSplice", |
1579 observers_end_perform_splice); | 1551 observers_end_perform_splice); |
1580 INSTALL_NATIVE(JSFunction, "NativeObjectObserve", | 1552 INSTALL_NATIVE(JSFunction, "NativeObjectObserve", |
1581 native_object_observe); | 1553 native_object_observe); |
1582 INSTALL_NATIVE(JSFunction, "NativeObjectGetNotifier", | 1554 INSTALL_NATIVE(JSFunction, "NativeObjectGetNotifier", |
1583 native_object_get_notifier); | 1555 native_object_get_notifier); |
1584 INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange", | 1556 INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange", |
1585 native_object_notifier_perform_change); | 1557 native_object_notifier_perform_change); |
| 1558 INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol); |
1586 } | 1559 } |
1587 | 1560 |
1588 | 1561 |
1589 void Genesis::InstallExperimentalNativeFunctions() { | 1562 void Genesis::InstallExperimentalNativeFunctions() { |
1590 if (FLAG_harmony_proxies) { | 1563 if (FLAG_harmony_proxies) { |
1591 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); | 1564 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
1592 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1565 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
1593 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); | 1566 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
1594 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); | 1567 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
1595 } | 1568 } |
1596 | |
1597 if (FLAG_harmony_symbols) { | |
1598 INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol); | |
1599 } | |
1600 } | 1569 } |
1601 | 1570 |
1602 #undef INSTALL_NATIVE | 1571 #undef INSTALL_NATIVE |
1603 | 1572 |
1604 | 1573 |
1605 Handle<JSFunction> Genesis::InstallInternalArray( | 1574 Handle<JSFunction> Genesis::InstallInternalArray( |
1606 Handle<JSBuiltinsObject> builtins, | 1575 Handle<JSBuiltinsObject> builtins, |
1607 const char* name, | 1576 const char* name, |
1608 ElementsKind elements_kind) { | 1577 ElementsKind elements_kind) { |
1609 // --- I n t e r n a l A r r a y --- | 1578 // --- I n t e r n a l A r r a y --- |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 { | 1832 { |
1864 Handle<JSFunction> array_function = | 1833 Handle<JSFunction> array_function = |
1865 InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS); | 1834 InstallInternalArray(builtins, "InternalArray", FAST_HOLEY_ELEMENTS); |
1866 native_context()->set_internal_array_function(*array_function); | 1835 native_context()->set_internal_array_function(*array_function); |
1867 } | 1836 } |
1868 | 1837 |
1869 { | 1838 { |
1870 InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS); | 1839 InstallInternalArray(builtins, "InternalPackedArray", FAST_ELEMENTS); |
1871 } | 1840 } |
1872 | 1841 |
| 1842 { // -- S e t I t e r a t o r |
| 1843 Handle<JSFunction> set_iterator_function = InstallFunction( |
| 1844 builtins, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, |
| 1845 isolate()->initial_object_prototype(), Builtins::kIllegal); |
| 1846 native_context()->set_set_iterator_map( |
| 1847 set_iterator_function->initial_map()); |
| 1848 } |
| 1849 |
| 1850 { // -- M a p I t e r a t o r |
| 1851 Handle<JSFunction> map_iterator_function = InstallFunction( |
| 1852 builtins, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, |
| 1853 isolate()->initial_object_prototype(), Builtins::kIllegal); |
| 1854 native_context()->set_map_iterator_map( |
| 1855 map_iterator_function->initial_map()); |
| 1856 } |
| 1857 |
1873 if (FLAG_disable_native_files) { | 1858 if (FLAG_disable_native_files) { |
1874 PrintF("Warning: Running without installed natives!\n"); | 1859 PrintF("Warning: Running without installed natives!\n"); |
1875 return true; | 1860 return true; |
1876 } | 1861 } |
1877 | 1862 |
1878 // Install natives. | 1863 // Install natives. |
1879 for (int i = Natives::GetDebuggerCount(); | 1864 for (int i = Natives::GetDebuggerCount(); |
1880 i < Natives::GetBuiltinsCount(); | 1865 i < Natives::GetBuiltinsCount(); |
1881 i++) { | 1866 i++) { |
1882 if (!CompileBuiltin(isolate(), i)) return false; | 1867 if (!CompileBuiltin(isolate(), i)) return false; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2006 strcmp(ExperimentalNatives::GetScriptName(i).start(), \ | 1991 strcmp(ExperimentalNatives::GetScriptName(i).start(), \ |
2007 "native " file) == 0) { \ | 1992 "native " file) == 0) { \ |
2008 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ | 1993 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ |
2009 } | 1994 } |
2010 | 1995 |
2011 | 1996 |
2012 bool Genesis::InstallExperimentalNatives() { | 1997 bool Genesis::InstallExperimentalNatives() { |
2013 for (int i = ExperimentalNatives::GetDebuggerCount(); | 1998 for (int i = ExperimentalNatives::GetDebuggerCount(); |
2014 i < ExperimentalNatives::GetBuiltinsCount(); | 1999 i < ExperimentalNatives::GetBuiltinsCount(); |
2015 i++) { | 2000 i++) { |
2016 INSTALL_EXPERIMENTAL_NATIVE(i, symbols, "symbol.js") | |
2017 INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js") | 2001 INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js") |
2018 INSTALL_EXPERIMENTAL_NATIVE(i, collections, "collection.js") | |
2019 INSTALL_EXPERIMENTAL_NATIVE(i, collections, "collection-iterator.js") | |
2020 INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") | 2002 INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") |
2021 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") | 2003 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") |
2022 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "string-iterator.js") | 2004 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "string-iterator.js") |
2023 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") | 2005 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") |
2024 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") | 2006 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") |
2025 } | 2007 } |
2026 | 2008 |
2027 InstallExperimentalNativeFunctions(); | 2009 InstallExperimentalNativeFunctions(); |
2028 return true; | 2010 return true; |
2029 } | 2011 } |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2693 return from + sizeof(NestingCounterType); | 2675 return from + sizeof(NestingCounterType); |
2694 } | 2676 } |
2695 | 2677 |
2696 | 2678 |
2697 // Called when the top-level V8 mutex is destroyed. | 2679 // Called when the top-level V8 mutex is destroyed. |
2698 void Bootstrapper::FreeThreadResources() { | 2680 void Bootstrapper::FreeThreadResources() { |
2699 ASSERT(!IsActive()); | 2681 ASSERT(!IsActive()); |
2700 } | 2682 } |
2701 | 2683 |
2702 } } // namespace v8::internal | 2684 } } // namespace v8::internal |
OLD | NEW |