| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 delete_these_arrays_on_tear_down_->Add(memory); | 122 delete_these_arrays_on_tear_down_->Add(memory); |
| 123 } | 123 } |
| 124 return memory; | 124 return memory; |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 void Bootstrapper::TearDown() { | 128 void Bootstrapper::TearDown() { |
| 129 if (delete_these_non_arrays_on_tear_down_ != NULL) { | 129 if (delete_these_non_arrays_on_tear_down_ != NULL) { |
| 130 int len = delete_these_non_arrays_on_tear_down_->length(); | 130 int len = delete_these_non_arrays_on_tear_down_->length(); |
| 131 DCHECK(len < 28); // Don't use this mechanism for unbounded allocations. | 131 DCHECK(len < 1000); // Don't use this mechanism for unbounded allocations. |
| 132 for (int i = 0; i < len; i++) { | 132 for (int i = 0; i < len; i++) { |
| 133 delete delete_these_non_arrays_on_tear_down_->at(i); | 133 delete delete_these_non_arrays_on_tear_down_->at(i); |
| 134 delete_these_non_arrays_on_tear_down_->at(i) = NULL; | 134 delete_these_non_arrays_on_tear_down_->at(i) = NULL; |
| 135 } | 135 } |
| 136 delete delete_these_non_arrays_on_tear_down_; | 136 delete delete_these_non_arrays_on_tear_down_; |
| 137 delete_these_non_arrays_on_tear_down_ = NULL; | 137 delete_these_non_arrays_on_tear_down_ = NULL; |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (delete_these_arrays_on_tear_down_ != NULL) { | 140 if (delete_these_arrays_on_tear_down_ != NULL) { |
| 141 int len = delete_these_arrays_on_tear_down_->length(); | 141 int len = delete_these_arrays_on_tear_down_->length(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // other objects in the snapshot. | 203 // other objects in the snapshot. |
| 204 void HookUpGlobalObject(Handle<GlobalObject> global_object); | 204 void HookUpGlobalObject(Handle<GlobalObject> global_object); |
| 205 // New context initialization. Used for creating a context from scratch. | 205 // New context initialization. Used for creating a context from scratch. |
| 206 void InitializeGlobal(Handle<GlobalObject> global_object, | 206 void InitializeGlobal(Handle<GlobalObject> global_object, |
| 207 Handle<JSFunction> empty_function); | 207 Handle<JSFunction> empty_function); |
| 208 void InitializeExperimentalGlobal(); | 208 void InitializeExperimentalGlobal(); |
| 209 // Installs the contents of the native .js files on the global objects. | 209 // Installs the contents of the native .js files on the global objects. |
| 210 // Used for creating a context from scratch. | 210 // Used for creating a context from scratch. |
| 211 void InstallNativeFunctions(); | 211 void InstallNativeFunctions(); |
| 212 void InstallExperimentalNativeFunctions(); | 212 void InstallExperimentalNativeFunctions(); |
| 213 |
| 214 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
| 215 void InstallNativeFunctions_##id(); \ |
| 216 void InitializeGlobal_##id(); |
| 217 |
| 218 SHIPPING_FEATURES(DECLARE_FEATURE_INITIALIZATION) |
| 219 HARMONY_FEATURES(DECLARE_FEATURE_INITIALIZATION) |
| 220 STAGED_FEATURES(DECLARE_FEATURE_INITIALIZATION) |
| 221 |
| 222 DECLARE_FEATURE_INITIALIZATION(proxies, "") |
| 223 #undef DECLARE_FEATURE_INITIALIZATION |
| 224 |
| 213 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, | 225 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, |
| 214 const char* name, | 226 const char* name, |
| 215 ElementsKind elements_kind); | 227 ElementsKind elements_kind); |
| 216 bool InstallNatives(); | 228 bool InstallNatives(); |
| 217 | 229 |
| 218 void InstallTypedArray( | 230 void InstallTypedArray( |
| 219 const char* name, | 231 const char* name, |
| 220 ElementsKind elements_kind, | 232 ElementsKind elements_kind, |
| 221 Handle<JSFunction>* fun, | 233 Handle<JSFunction>* fun, |
| 222 Handle<Map>* external_map); | 234 Handle<Map>* external_map); |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 // Set up the call-as-constructor delegate. | 1335 // Set up the call-as-constructor delegate. |
| 1324 Handle<Code> code = | 1336 Handle<Code> code = |
| 1325 Handle<Code>(isolate->builtins()->builtin( | 1337 Handle<Code>(isolate->builtins()->builtin( |
| 1326 Builtins::kHandleApiCallAsConstructor)); | 1338 Builtins::kHandleApiCallAsConstructor)); |
| 1327 Handle<JSFunction> delegate = factory->NewFunction( | 1339 Handle<JSFunction> delegate = factory->NewFunction( |
| 1328 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); | 1340 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 1329 native_context()->set_call_as_constructor_delegate(*delegate); | 1341 native_context()->set_call_as_constructor_delegate(*delegate); |
| 1330 delegate->shared()->DontAdaptArguments(); | 1342 delegate->shared()->DontAdaptArguments(); |
| 1331 } | 1343 } |
| 1332 | 1344 |
| 1345 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); |
| 1346 |
| 1347 SHIPPING_FEATURES(FEATURE_INITIALIZE_GLOBAL) |
| 1348 #undef FEATURE_INITIALIZE_GLOBAL |
| 1349 |
| 1333 // Initialize the embedder data slot. | 1350 // Initialize the embedder data slot. |
| 1334 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1351 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
| 1335 native_context()->set_embedder_data(*embedder_data); | 1352 native_context()->set_embedder_data(*embedder_data); |
| 1336 } | 1353 } |
| 1337 | 1354 |
| 1338 | 1355 |
| 1339 void Genesis::InstallTypedArray( | 1356 void Genesis::InstallTypedArray( |
| 1340 const char* name, | 1357 const char* name, |
| 1341 ElementsKind elements_kind, | 1358 ElementsKind elements_kind, |
| 1342 Handle<JSFunction>* fun, | 1359 Handle<JSFunction>* fun, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1353 JSFunction::SetInitialMap(result, initial_map, | 1370 JSFunction::SetInitialMap(result, initial_map, |
| 1354 handle(initial_map->prototype(), isolate())); | 1371 handle(initial_map->prototype(), isolate())); |
| 1355 *fun = result; | 1372 *fun = result; |
| 1356 | 1373 |
| 1357 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind); | 1374 ElementsKind external_kind = GetNextTransitionElementsKind(elements_kind); |
| 1358 *external_map = Map::AsElementsKind(initial_map, external_kind); | 1375 *external_map = Map::AsElementsKind(initial_map, external_kind); |
| 1359 } | 1376 } |
| 1360 | 1377 |
| 1361 | 1378 |
| 1362 void Genesis::InitializeExperimentalGlobal() { | 1379 void Genesis::InitializeExperimentalGlobal() { |
| 1363 // TODO(erikcorry): Move this into Genesis::InitializeGlobal once we no | 1380 #define FEATURE_INITIALIZE_GLOBAL(id, descr) InitializeGlobal_##id(); |
| 1364 // longer need to live behind a flag. | |
| 1365 Handle<JSObject> builtins(native_context()->builtins()); | |
| 1366 | 1381 |
| 1367 Handle<HeapObject> flag( | 1382 HARMONY_FEATURES(FEATURE_INITIALIZE_GLOBAL) |
| 1368 FLAG_harmony_regexps ? heap()->true_value() : heap()->false_value()); | 1383 STAGED_FEATURES(FEATURE_INITIALIZE_GLOBAL) |
| 1369 PropertyAttributes attributes = | 1384 #undef FEATURE_INITIALIZE_GLOBAL |
| 1370 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | |
| 1371 Runtime::DefineObjectProperty(builtins, factory()->harmony_regexps_string(), | |
| 1372 flag, attributes).Assert(); | |
| 1373 } | 1385 } |
| 1374 | 1386 |
| 1375 | 1387 |
| 1376 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { | 1388 bool Genesis::CompileBuiltin(Isolate* isolate, int index) { |
| 1377 Vector<const char> name = Natives::GetScriptName(index); | 1389 Vector<const char> name = Natives::GetScriptName(index); |
| 1378 Handle<String> source_code = | 1390 Handle<String> source_code = |
| 1379 isolate->bootstrapper()->NativesSourceLookup(index); | 1391 isolate->bootstrapper()->NativesSourceLookup(index); |
| 1380 return CompileNative(isolate, name, source_code); | 1392 return CompileNative(isolate, name, source_code); |
| 1381 } | 1393 } |
| 1382 | 1394 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 INSTALL_NATIVE(JSFunction, "NativeObjectObserve", | 1556 INSTALL_NATIVE(JSFunction, "NativeObjectObserve", |
| 1545 native_object_observe); | 1557 native_object_observe); |
| 1546 INSTALL_NATIVE(JSFunction, "NativeObjectGetNotifier", | 1558 INSTALL_NATIVE(JSFunction, "NativeObjectGetNotifier", |
| 1547 native_object_get_notifier); | 1559 native_object_get_notifier); |
| 1548 INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange", | 1560 INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange", |
| 1549 native_object_notifier_perform_change); | 1561 native_object_notifier_perform_change); |
| 1550 | 1562 |
| 1551 INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol); | 1563 INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol); |
| 1552 INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol); | 1564 INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol); |
| 1553 INSTALL_NATIVE(JSFunction, "ArrayValues", array_values_iterator); | 1565 INSTALL_NATIVE(JSFunction, "ArrayValues", array_values_iterator); |
| 1566 |
| 1567 #define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id(); |
| 1568 |
| 1569 SHIPPING_FEATURES(INSTALL_NATIVE_FUNCTIONS_FOR) |
| 1570 #undef INSTALL_NATIVE_FUNCTIONS_FOR |
| 1554 } | 1571 } |
| 1555 | 1572 |
| 1556 | 1573 |
| 1557 void Genesis::InstallExperimentalNativeFunctions() { | 1574 void Genesis::InstallExperimentalNativeFunctions() { |
| 1558 if (FLAG_harmony_proxies) { | 1575 if (FLAG_harmony_proxies) { |
| 1559 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); | 1576 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
| 1560 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1577 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
| 1561 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); | 1578 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
| 1562 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); | 1579 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
| 1563 } | 1580 } |
| 1581 |
| 1582 #define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id(); |
| 1583 |
| 1584 HARMONY_FEATURES(INSTALL_NATIVE_FUNCTIONS_FOR) |
| 1585 STAGED_FEATURES(INSTALL_NATIVE_FUNCTIONS_FOR) |
| 1586 INSTALL_NATIVE_FUNCTIONS_FOR(proxies, "") |
| 1587 #undef INSTALL_NATIVE_FUNCTIONS_FOR |
| 1588 } |
| 1589 |
| 1590 |
| 1591 #define EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(id) \ |
| 1592 void Genesis::InstallNativeFunctions_##id() {} |
| 1593 |
| 1594 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(scoping) |
| 1595 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(modules) |
| 1596 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(strings) |
| 1597 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(arrays) |
| 1598 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(classes) |
| 1599 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(object_literals) |
| 1600 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(regexps) |
| 1601 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(arrow_functions) |
| 1602 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(numeric_literals) |
| 1603 |
| 1604 |
| 1605 void Genesis::InstallNativeFunctions_proxies() { |
| 1606 if (FLAG_harmony_proxies) { |
| 1607 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
| 1608 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
| 1609 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
| 1610 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
| 1611 } |
| 1564 } | 1612 } |
| 1565 | 1613 |
| 1566 #undef INSTALL_NATIVE | 1614 #undef INSTALL_NATIVE |
| 1567 | 1615 |
| 1616 #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ |
| 1617 void Genesis::InitializeGlobal_##id() {} |
| 1618 |
| 1619 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(scoping) |
| 1620 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(modules) |
| 1621 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(strings) |
| 1622 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(arrays) |
| 1623 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(classes) |
| 1624 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(object_literals) |
| 1625 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(arrow_functions) |
| 1626 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(numeric_literals) |
| 1627 |
| 1628 void Genesis::InitializeGlobal_regexps() { |
| 1629 Handle<JSObject> builtins(native_context()->builtins()); |
| 1630 |
| 1631 Handle<HeapObject> flag(FLAG_harmony_regexps ? heap()->true_value() |
| 1632 : heap()->false_value()); |
| 1633 PropertyAttributes attributes = |
| 1634 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
| 1635 Runtime::DefineObjectProperty(builtins, factory()->harmony_regexps_string(), |
| 1636 flag, attributes).Assert(); |
| 1637 } |
| 1638 |
| 1568 | 1639 |
| 1569 Handle<JSFunction> Genesis::InstallInternalArray( | 1640 Handle<JSFunction> Genesis::InstallInternalArray( |
| 1570 Handle<JSBuiltinsObject> builtins, | 1641 Handle<JSBuiltinsObject> builtins, |
| 1571 const char* name, | 1642 const char* name, |
| 1572 ElementsKind elements_kind) { | 1643 ElementsKind elements_kind) { |
| 1573 // --- I n t e r n a l A r r a y --- | 1644 // --- I n t e r n a l A r r a y --- |
| 1574 // An array constructor on the builtins object that works like | 1645 // An array constructor on the builtins object that works like |
| 1575 // the public Array constructor, except that its prototype | 1646 // the public Array constructor, except that its prototype |
| 1576 // doesn't inherit from Object.prototype. | 1647 // doesn't inherit from Object.prototype. |
| 1577 // To be used only for internal work by builtins. Instances | 1648 // To be used only for internal work by builtins. Instances |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 | 2144 |
| 2074 #define INSTALL_EXPERIMENTAL_NATIVE(i, flag, file) \ | 2145 #define INSTALL_EXPERIMENTAL_NATIVE(i, flag, file) \ |
| 2075 if (FLAG_harmony_##flag && \ | 2146 if (FLAG_harmony_##flag && \ |
| 2076 strcmp(ExperimentalNatives::GetScriptName(i).start(), \ | 2147 strcmp(ExperimentalNatives::GetScriptName(i).start(), \ |
| 2077 "native " file) == 0) { \ | 2148 "native " file) == 0) { \ |
| 2078 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ | 2149 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ |
| 2079 } | 2150 } |
| 2080 | 2151 |
| 2081 | 2152 |
| 2082 bool Genesis::InstallExperimentalNatives() { | 2153 bool Genesis::InstallExperimentalNatives() { |
| 2154 static const char* arrays_natives[] = {"native harmony-array.js", |
| 2155 "native harmony-typedarray.js", NULL}; |
| 2156 static const char* proxies_natives[] = {"native proxy.js", NULL}; |
| 2157 static const char* strings_natives[] = {"native harmony-string.js", NULL}; |
| 2158 static const char* classes_natives[] = {"native harmony-classes.js", NULL}; |
| 2159 static const char* modules_natives[] = {NULL}; |
| 2160 static const char* scoping_natives[] = {NULL}; |
| 2161 static const char* object_literals_natives[] = {NULL}; |
| 2162 static const char* regexps_natives[] = {NULL}; |
| 2163 static const char* arrow_functions_natives[] = {NULL}; |
| 2164 static const char* numeric_literals_natives[] = {NULL}; |
| 2165 |
| 2083 for (int i = ExperimentalNatives::GetDebuggerCount(); | 2166 for (int i = ExperimentalNatives::GetDebuggerCount(); |
| 2084 i < ExperimentalNatives::GetBuiltinsCount(); | 2167 i < ExperimentalNatives::GetBuiltinsCount(); i++) { |
| 2085 i++) { | 2168 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ |
| 2086 INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js") | 2169 if (FLAG_harmony_##id) { \ |
| 2087 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") | 2170 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ |
| 2088 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") | 2171 if (strcmp(ExperimentalNatives::GetScriptName(i).start(), \ |
| 2089 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-typedarray.js") | 2172 id##_natives[j]) == 0) { \ |
| 2090 INSTALL_EXPERIMENTAL_NATIVE(i, classes, "harmony-classes.js") | 2173 if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ |
| 2174 } \ |
| 2175 } \ |
| 2091 } | 2176 } |
| 2177 INSTALL_EXPERIMENTAL_NATIVES(proxies, ""); |
| 2178 // Iterate over flags that are not enabled by default. |
| 2179 HARMONY_FEATURES(INSTALL_EXPERIMENTAL_NATIVES); |
| 2180 STAGED_FEATURES(INSTALL_EXPERIMENTAL_NATIVES); |
| 2181 #undef INSTALL_EXPERIMENTAL_NATIVES |
| 2182 } |
| 2183 |
| 2184 #define USE_NATIVES_FOR_FEATURE(id, descr) USE(id##_natives); |
| 2185 |
| 2186 SHIPPING_FEATURES(USE_NATIVES_FOR_FEATURE) |
| 2187 #undef USE_NATIVES_FOR_FEATURE |
| 2092 | 2188 |
| 2093 InstallExperimentalNativeFunctions(); | 2189 InstallExperimentalNativeFunctions(); |
| 2094 return true; | 2190 return true; |
| 2095 } | 2191 } |
| 2096 | 2192 |
| 2097 | 2193 |
| 2098 static void InstallBuiltinFunctionId(Handle<JSObject> holder, | 2194 static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
| 2099 const char* function_name, | 2195 const char* function_name, |
| 2100 BuiltinFunctionId id) { | 2196 BuiltinFunctionId id) { |
| 2101 Isolate* isolate = holder->GetIsolate(); | 2197 Isolate* isolate = holder->GetIsolate(); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 return from + sizeof(NestingCounterType); | 2810 return from + sizeof(NestingCounterType); |
| 2715 } | 2811 } |
| 2716 | 2812 |
| 2717 | 2813 |
| 2718 // Called when the top-level V8 mutex is destroyed. | 2814 // Called when the top-level V8 mutex is destroyed. |
| 2719 void Bootstrapper::FreeThreadResources() { | 2815 void Bootstrapper::FreeThreadResources() { |
| 2720 DCHECK(!IsActive()); | 2816 DCHECK(!IsActive()); |
| 2721 } | 2817 } |
| 2722 | 2818 |
| 2723 } } // namespace v8::internal | 2819 } } // namespace v8::internal |
| OLD | NEW |