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 27 matching lines...) Expand all Loading... |
38 #include "macro-assembler.h" | 38 #include "macro-assembler.h" |
39 #include "natives.h" | 39 #include "natives.h" |
40 #include "objects-visiting.h" | 40 #include "objects-visiting.h" |
41 #include "platform.h" | 41 #include "platform.h" |
42 #include "snapshot.h" | 42 #include "snapshot.h" |
43 #include "extensions/externalize-string-extension.h" | 43 #include "extensions/externalize-string-extension.h" |
44 #include "extensions/gc-extension.h" | 44 #include "extensions/gc-extension.h" |
45 #include "extensions/statistics-extension.h" | 45 #include "extensions/statistics-extension.h" |
46 #include "code-stubs.h" | 46 #include "code-stubs.h" |
47 | 47 |
| 48 #if defined(V8_I18N_SUPPORT) |
| 49 #include "extensions/i18n/i18n-extension.h" |
| 50 #endif |
| 51 |
48 namespace v8 { | 52 namespace v8 { |
49 namespace internal { | 53 namespace internal { |
50 | 54 |
51 | 55 |
52 NativesExternalStringResource::NativesExternalStringResource( | 56 NativesExternalStringResource::NativesExternalStringResource( |
53 Bootstrapper* bootstrapper, | 57 Bootstrapper* bootstrapper, |
54 const char* source, | 58 const char* source, |
55 size_t length) | 59 size_t length) |
56 : data_(source), length_(length) { | 60 : data_(source), length_(length) { |
57 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { | 61 if (bootstrapper->delete_these_non_arrays_on_tear_down_ == NULL) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 99 |
96 void Bootstrapper::Initialize(bool create_heap_objects) { | 100 void Bootstrapper::Initialize(bool create_heap_objects) { |
97 extensions_cache_.Initialize(create_heap_objects); | 101 extensions_cache_.Initialize(create_heap_objects); |
98 } | 102 } |
99 | 103 |
100 | 104 |
101 void Bootstrapper::InitializeOncePerProcess() { | 105 void Bootstrapper::InitializeOncePerProcess() { |
102 GCExtension::Register(); | 106 GCExtension::Register(); |
103 ExternalizeStringExtension::Register(); | 107 ExternalizeStringExtension::Register(); |
104 StatisticsExtension::Register(); | 108 StatisticsExtension::Register(); |
| 109 #if defined(V8_I18N_SUPPORT) |
| 110 v8_i18n::Extension::Register(); |
| 111 #endif |
105 } | 112 } |
106 | 113 |
107 | 114 |
108 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { | 115 char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
109 char* memory = new char[bytes]; | 116 char* memory = new char[bytes]; |
110 if (memory != NULL) { | 117 if (memory != NULL) { |
111 if (delete_these_arrays_on_tear_down_ == NULL) { | 118 if (delete_these_arrays_on_tear_down_ == NULL) { |
112 delete_these_arrays_on_tear_down_ = new List<char*>(2); | 119 delete_these_arrays_on_tear_down_ = new List<char*>(2); |
113 } | 120 } |
114 delete_these_arrays_on_tear_down_->Add(memory); | 121 delete_these_arrays_on_tear_down_->Add(memory); |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 isolate->initial_object_prototype(), | 866 isolate->initial_object_prototype(), |
860 Builtins::kArrayCode, true, true); | 867 Builtins::kArrayCode, true, true); |
861 array_function->shared()->DontAdaptArguments(); | 868 array_function->shared()->DontAdaptArguments(); |
862 array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); | 869 array_function->shared()->set_function_data(Smi::FromInt(kArrayCode)); |
863 | 870 |
864 // This seems a bit hackish, but we need to make sure Array.length | 871 // This seems a bit hackish, but we need to make sure Array.length |
865 // is 1. | 872 // is 1. |
866 array_function->shared()->set_length(1); | 873 array_function->shared()->set_length(1); |
867 | 874 |
868 Handle<Map> initial_map(array_function->initial_map()); | 875 Handle<Map> initial_map(array_function->initial_map()); |
| 876 |
| 877 // This assert protects an optimization in |
| 878 // HGraphBuilder::JSArrayBuilder::EmitMapCode() |
| 879 ASSERT(initial_map->elements_kind() == GetInitialFastElementsKind()); |
| 880 |
869 Handle<DescriptorArray> array_descriptors( | 881 Handle<DescriptorArray> array_descriptors( |
870 factory->NewDescriptorArray(0, 1)); | 882 factory->NewDescriptorArray(0, 1)); |
871 DescriptorArray::WhitenessWitness witness(*array_descriptors); | 883 DescriptorArray::WhitenessWitness witness(*array_descriptors); |
872 | 884 |
873 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); | 885 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength)); |
874 PropertyAttributes attribs = static_cast<PropertyAttributes>( | 886 PropertyAttributes attribs = static_cast<PropertyAttributes>( |
875 DONT_ENUM | DONT_DELETE); | 887 DONT_ENUM | DONT_DELETE); |
876 initial_map->set_instance_descriptors(*array_descriptors); | 888 initial_map->set_instance_descriptors(*array_descriptors); |
877 | 889 |
878 { // Add length. | 890 { // Add length. |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 | 1282 |
1271 | 1283 |
1272 Handle<JSFunction> Genesis::InstallTypedArray( | 1284 Handle<JSFunction> Genesis::InstallTypedArray( |
1273 const char* name, ElementsKind elementsKind) { | 1285 const char* name, ElementsKind elementsKind) { |
1274 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | 1286 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
1275 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, | 1287 Handle<JSFunction> result = InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, |
1276 JSTypedArray::kSize, isolate()->initial_object_prototype(), | 1288 JSTypedArray::kSize, isolate()->initial_object_prototype(), |
1277 Builtins::kIllegal, false, true); | 1289 Builtins::kIllegal, false, true); |
1278 | 1290 |
1279 Handle<Map> initial_map = isolate()->factory()->NewMap( | 1291 Handle<Map> initial_map = isolate()->factory()->NewMap( |
1280 JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, elementsKind); | 1292 JS_TYPED_ARRAY_TYPE, JSTypedArray::kSizeWithInternalFields, elementsKind); |
1281 result->set_initial_map(*initial_map); | 1293 result->set_initial_map(*initial_map); |
1282 initial_map->set_constructor(*result); | 1294 initial_map->set_constructor(*result); |
1283 return result; | 1295 return result; |
1284 } | 1296 } |
1285 | 1297 |
1286 | 1298 |
1287 void Genesis::InitializeExperimentalGlobal() { | 1299 void Genesis::InitializeExperimentalGlobal() { |
1288 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); | 1300 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object()); |
1289 | 1301 |
1290 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no | 1302 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 Handle<JSFunction> double_fun = InstallTypedArray("Float64Array", | 1366 Handle<JSFunction> double_fun = InstallTypedArray("Float64Array", |
1355 EXTERNAL_DOUBLE_ELEMENTS); | 1367 EXTERNAL_DOUBLE_ELEMENTS); |
1356 native_context()->set_double_array_fun(*double_fun); | 1368 native_context()->set_double_array_fun(*double_fun); |
1357 Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray", | 1369 Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray", |
1358 EXTERNAL_PIXEL_ELEMENTS); | 1370 EXTERNAL_PIXEL_ELEMENTS); |
1359 native_context()->set_uint8c_array_fun(*uint8c_fun); | 1371 native_context()->set_uint8c_array_fun(*uint8c_fun); |
1360 | 1372 |
1361 Handle<JSFunction> data_view_fun = | 1373 Handle<JSFunction> data_view_fun = |
1362 InstallFunction( | 1374 InstallFunction( |
1363 global, "DataView", JS_DATA_VIEW_TYPE, | 1375 global, "DataView", JS_DATA_VIEW_TYPE, |
1364 JSDataView::kSize, | 1376 JSDataView::kSizeWithInternalFields, |
1365 isolate()->initial_object_prototype(), | 1377 isolate()->initial_object_prototype(), |
1366 Builtins::kIllegal, true, true); | 1378 Builtins::kIllegal, true, true); |
1367 native_context()->set_data_view_fun(*data_view_fun); | 1379 native_context()->set_data_view_fun(*data_view_fun); |
1368 } | 1380 } |
1369 | 1381 |
1370 if (FLAG_harmony_generators) { | 1382 if (FLAG_harmony_generators) { |
1371 // Create generator meta-objects and install them on the builtins object. | 1383 // Create generator meta-objects and install them on the builtins object. |
1372 Handle<JSObject> builtins(native_context()->builtins()); | 1384 Handle<JSObject> builtins(native_context()->builtins()); |
1373 Handle<JSObject> generator_object_prototype = | 1385 Handle<JSObject> generator_object_prototype = |
1374 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1386 factory()->NewJSObject(isolate()->object_function(), TENURED); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); | 1579 INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); |
1568 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); | 1580 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); |
1569 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", | 1581 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", |
1570 configure_instance_fun); | 1582 configure_instance_fun); |
1571 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); | 1583 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
1572 INSTALL_NATIVE(JSObject, "functionCache", function_cache); | 1584 INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
1573 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", | 1585 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", |
1574 to_complete_property_descriptor); | 1586 to_complete_property_descriptor); |
1575 } | 1587 } |
1576 | 1588 |
| 1589 |
1577 void Genesis::InstallExperimentalNativeFunctions() { | 1590 void Genesis::InstallExperimentalNativeFunctions() { |
1578 if (FLAG_harmony_proxies) { | 1591 if (FLAG_harmony_proxies) { |
1579 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); | 1592 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
1580 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1593 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
1581 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); | 1594 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
1582 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); | 1595 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
1583 } | 1596 } |
1584 if (FLAG_harmony_observation) { | 1597 if (FLAG_harmony_observation) { |
1585 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); | 1598 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); |
1586 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); | 1599 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 factory->InternalizeUtf8String(FLAG_expose_debug_as); | 2233 factory->InternalizeUtf8String(FLAG_expose_debug_as); |
2221 Handle<Object> global_proxy( | 2234 Handle<Object> global_proxy( |
2222 debug->debug_context()->global_proxy(), isolate); | 2235 debug->debug_context()->global_proxy(), isolate); |
2223 CHECK_NOT_EMPTY_HANDLE(isolate, | 2236 CHECK_NOT_EMPTY_HANDLE(isolate, |
2224 JSObject::SetLocalPropertyIgnoreAttributes( | 2237 JSObject::SetLocalPropertyIgnoreAttributes( |
2225 global, debug_string, global_proxy, DONT_ENUM)); | 2238 global, debug_string, global_proxy, DONT_ENUM)); |
2226 } | 2239 } |
2227 #endif | 2240 #endif |
2228 } | 2241 } |
2229 | 2242 |
| 2243 |
2230 static uint32_t Hash(RegisteredExtension* extension) { | 2244 static uint32_t Hash(RegisteredExtension* extension) { |
2231 return v8::internal::ComputePointerHash(extension); | 2245 return v8::internal::ComputePointerHash(extension); |
2232 } | 2246 } |
2233 | 2247 |
| 2248 |
2234 static bool MatchRegisteredExtensions(void* key1, void* key2) { | 2249 static bool MatchRegisteredExtensions(void* key1, void* key2) { |
2235 return key1 == key2; | 2250 return key1 == key2; |
2236 } | 2251 } |
2237 | 2252 |
2238 Genesis::ExtensionStates::ExtensionStates() | 2253 Genesis::ExtensionStates::ExtensionStates() |
2239 : map_(MatchRegisteredExtensions, 8) { } | 2254 : map_(MatchRegisteredExtensions, 8) { } |
2240 | 2255 |
2241 Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state( | 2256 Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state( |
2242 RegisteredExtension* extension) { | 2257 RegisteredExtension* extension) { |
2243 i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension), false); | 2258 i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension), false); |
(...skipping 23 matching lines...) Expand all Loading... |
2267 } | 2282 } |
2268 | 2283 |
2269 if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); | 2284 if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); |
2270 if (FLAG_expose_externalize_string) { | 2285 if (FLAG_expose_externalize_string) { |
2271 InstallExtension(isolate, "v8/externalize", &extension_states); | 2286 InstallExtension(isolate, "v8/externalize", &extension_states); |
2272 } | 2287 } |
2273 if (FLAG_track_gc_object_stats) { | 2288 if (FLAG_track_gc_object_stats) { |
2274 InstallExtension(isolate, "v8/statistics", &extension_states); | 2289 InstallExtension(isolate, "v8/statistics", &extension_states); |
2275 } | 2290 } |
2276 | 2291 |
| 2292 #if defined(V8_I18N_SUPPORT) |
| 2293 if (FLAG_enable_i18n) { |
| 2294 InstallExtension(isolate, "v8/i18n", &extension_states); |
| 2295 } |
| 2296 #endif |
| 2297 |
2277 if (extensions == NULL) return true; | 2298 if (extensions == NULL) return true; |
2278 // Install required extensions | 2299 // Install required extensions |
2279 int count = v8::ImplementationUtilities::GetNameCount(extensions); | 2300 int count = v8::ImplementationUtilities::GetNameCount(extensions); |
2280 const char** names = v8::ImplementationUtilities::GetNames(extensions); | 2301 const char** names = v8::ImplementationUtilities::GetNames(extensions); |
2281 for (int i = 0; i < count; i++) { | 2302 for (int i = 0; i < count; i++) { |
2282 if (!InstallExtension(isolate, names[i], &extension_states)) | 2303 if (!InstallExtension(isolate, names[i], &extension_states)) |
2283 return false; | 2304 return false; |
2284 } | 2305 } |
2285 | 2306 |
2286 return true; | 2307 return true; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 // Before creating the roots we must save the context and restore it | 2589 // Before creating the roots we must save the context and restore it |
2569 // on all function exits. | 2590 // on all function exits. |
2570 SaveContext saved_context(isolate); | 2591 SaveContext saved_context(isolate); |
2571 | 2592 |
2572 // During genesis, the boilerplate for stack overflow won't work until the | 2593 // During genesis, the boilerplate for stack overflow won't work until the |
2573 // environment has been at least partially initialized. Add a stack check | 2594 // environment has been at least partially initialized. Add a stack check |
2574 // before entering JS code to catch overflow early. | 2595 // before entering JS code to catch overflow early. |
2575 StackLimitCheck check(isolate); | 2596 StackLimitCheck check(isolate); |
2576 if (check.HasOverflowed()) return; | 2597 if (check.HasOverflowed()) return; |
2577 | 2598 |
2578 native_context_ = Snapshot::NewContextFromSnapshot(); | 2599 // We can only de-serialize a context if the isolate was initialized from |
| 2600 // a snapshot. Otherwise we have to build the context from scratch. |
| 2601 if (isolate->initialized_from_snapshot()) { |
| 2602 native_context_ = Snapshot::NewContextFromSnapshot(); |
| 2603 } else { |
| 2604 native_context_ = Handle<Context>(); |
| 2605 } |
| 2606 |
2579 if (!native_context().is_null()) { | 2607 if (!native_context().is_null()) { |
2580 AddToWeakNativeContextList(*native_context()); | 2608 AddToWeakNativeContextList(*native_context()); |
2581 isolate->set_context(*native_context()); | 2609 isolate->set_context(*native_context()); |
2582 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 2610 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
2583 Handle<GlobalObject> inner_global; | 2611 Handle<GlobalObject> inner_global; |
2584 Handle<JSGlobalProxy> global_proxy = | 2612 Handle<JSGlobalProxy> global_proxy = |
2585 CreateNewGlobals(global_template, | 2613 CreateNewGlobals(global_template, |
2586 global_object, | 2614 global_object, |
2587 &inner_global); | 2615 &inner_global); |
2588 | 2616 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2642 return from + sizeof(NestingCounterType); | 2670 return from + sizeof(NestingCounterType); |
2643 } | 2671 } |
2644 | 2672 |
2645 | 2673 |
2646 // Called when the top-level V8 mutex is destroyed. | 2674 // Called when the top-level V8 mutex is destroyed. |
2647 void Bootstrapper::FreeThreadResources() { | 2675 void Bootstrapper::FreeThreadResources() { |
2648 ASSERT(!IsActive()); | 2676 ASSERT(!IsActive()); |
2649 } | 2677 } |
2650 | 2678 |
2651 } } // namespace v8::internal | 2679 } } // namespace v8::internal |
OLD | NEW |