| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // templates passed through the API. The inner global from the snapshot is | 224 // templates passed through the API. The inner global from the snapshot is |
| 225 // detached from the other objects in the snapshot. | 225 // detached from the other objects in the snapshot. |
| 226 void HookUpInnerGlobal(Handle<GlobalObject> inner_global); | 226 void HookUpInnerGlobal(Handle<GlobalObject> inner_global); |
| 227 // New context initialization. Used for creating a context from scratch. | 227 // New context initialization. Used for creating a context from scratch. |
| 228 void InitializeGlobal(Handle<GlobalObject> inner_global, | 228 void InitializeGlobal(Handle<GlobalObject> inner_global, |
| 229 Handle<JSFunction> empty_function); | 229 Handle<JSFunction> empty_function); |
| 230 void InitializeExperimentalGlobal(); | 230 void InitializeExperimentalGlobal(); |
| 231 // Installs the contents of the native .js files on the global objects. | 231 // Installs the contents of the native .js files on the global objects. |
| 232 // Used for creating a context from scratch. | 232 // Used for creating a context from scratch. |
| 233 void InstallNativeFunctions(); | 233 void InstallNativeFunctions(); |
| 234 void InstallExperimentalBuiltinFunctionIds(); |
| 234 void InstallExperimentalNativeFunctions(); | 235 void InstallExperimentalNativeFunctions(); |
| 235 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, | 236 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, |
| 236 const char* name, | 237 const char* name, |
| 237 ElementsKind elements_kind); | 238 ElementsKind elements_kind); |
| 238 bool InstallNatives(); | 239 bool InstallNatives(); |
| 239 | 240 |
| 240 Handle<JSFunction> InstallTypedArray(const char* name, | 241 Handle<JSFunction> InstallTypedArray(const char* name, |
| 241 ElementsKind elementsKind); | 242 ElementsKind elementsKind); |
| 242 bool InstallExperimentalNatives(); | 243 bool InstallExperimentalNatives(); |
| 243 void InstallBuiltinFunctionIds(); | 244 void InstallBuiltinFunctionIds(); |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 Handle<JSFunction> array_buffer_fun = | 1088 Handle<JSFunction> array_buffer_fun = |
| 1088 InstallFunction( | 1089 InstallFunction( |
| 1089 global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, | 1090 global, "ArrayBuffer", JS_ARRAY_BUFFER_TYPE, |
| 1090 JSArrayBuffer::kSizeWithInternalFields, | 1091 JSArrayBuffer::kSizeWithInternalFields, |
| 1091 isolate->initial_object_prototype(), | 1092 isolate->initial_object_prototype(), |
| 1092 Builtins::kIllegal, true, true); | 1093 Builtins::kIllegal, true, true); |
| 1093 native_context()->set_array_buffer_fun(*array_buffer_fun); | 1094 native_context()->set_array_buffer_fun(*array_buffer_fun); |
| 1094 } | 1095 } |
| 1095 | 1096 |
| 1096 { // -- T y p e d A r r a y s | 1097 { // -- T y p e d A r r a y s |
| 1097 Handle<JSFunction> int8_fun = InstallTypedArray("Int8Array", | 1098 #define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 1098 EXTERNAL_BYTE_ELEMENTS); | 1099 { \ |
| 1099 native_context()->set_int8_array_fun(*int8_fun); | 1100 Handle<JSFunction> fun = InstallTypedArray(#Type "Array", \ |
| 1100 Handle<JSFunction> uint8_fun = InstallTypedArray("Uint8Array", | 1101 EXTERNAL_##TYPE##_ELEMENTS); \ |
| 1101 EXTERNAL_UNSIGNED_BYTE_ELEMENTS); | 1102 native_context()->set_##type##_array_fun(*fun); \ |
| 1102 native_context()->set_uint8_array_fun(*uint8_fun); | 1103 } |
| 1103 Handle<JSFunction> int16_fun = InstallTypedArray("Int16Array", | 1104 TYPED_ARRAYS(INSTALL_TYPED_ARRAY) |
| 1104 EXTERNAL_SHORT_ELEMENTS); | 1105 #undef INSTALL_TYPED_ARRAY |
| 1105 native_context()->set_int16_array_fun(*int16_fun); | |
| 1106 Handle<JSFunction> uint16_fun = InstallTypedArray("Uint16Array", | |
| 1107 EXTERNAL_UNSIGNED_SHORT_ELEMENTS); | |
| 1108 native_context()->set_uint16_array_fun(*uint16_fun); | |
| 1109 Handle<JSFunction> int32_fun = InstallTypedArray("Int32Array", | |
| 1110 EXTERNAL_INT_ELEMENTS); | |
| 1111 native_context()->set_int32_array_fun(*int32_fun); | |
| 1112 Handle<JSFunction> uint32_fun = InstallTypedArray("Uint32Array", | |
| 1113 EXTERNAL_UNSIGNED_INT_ELEMENTS); | |
| 1114 native_context()->set_uint32_array_fun(*uint32_fun); | |
| 1115 Handle<JSFunction> float_fun = InstallTypedArray("Float32Array", | |
| 1116 EXTERNAL_FLOAT_ELEMENTS); | |
| 1117 native_context()->set_float_array_fun(*float_fun); | |
| 1118 Handle<JSFunction> double_fun = InstallTypedArray("Float64Array", | |
| 1119 EXTERNAL_DOUBLE_ELEMENTS); | |
| 1120 native_context()->set_double_array_fun(*double_fun); | |
| 1121 Handle<JSFunction> uint8c_fun = InstallTypedArray("Uint8ClampedArray", | |
| 1122 EXTERNAL_PIXEL_ELEMENTS); | |
| 1123 native_context()->set_uint8c_array_fun(*uint8c_fun); | |
| 1124 | 1106 |
| 1125 Handle<JSFunction> data_view_fun = | 1107 Handle<JSFunction> data_view_fun = |
| 1126 InstallFunction( | 1108 InstallFunction( |
| 1127 global, "DataView", JS_DATA_VIEW_TYPE, | 1109 global, "DataView", JS_DATA_VIEW_TYPE, |
| 1128 JSDataView::kSizeWithInternalFields, | 1110 JSDataView::kSizeWithInternalFields, |
| 1129 isolate->initial_object_prototype(), | 1111 isolate->initial_object_prototype(), |
| 1130 Builtins::kIllegal, true, true); | 1112 Builtins::kIllegal, true, true); |
| 1131 native_context()->set_data_view_fun(*data_view_fun); | 1113 native_context()->set_data_view_fun(*data_view_fun); |
| 1132 } | 1114 } |
| 1133 | 1115 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 configure_instance_fun); | 1576 configure_instance_fun); |
| 1595 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); | 1577 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); |
| 1596 INSTALL_NATIVE(JSObject, "functionCache", function_cache); | 1578 INSTALL_NATIVE(JSObject, "functionCache", function_cache); |
| 1597 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", | 1579 INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", |
| 1598 to_complete_property_descriptor); | 1580 to_complete_property_descriptor); |
| 1599 } | 1581 } |
| 1600 | 1582 |
| 1601 | 1583 |
| 1602 void Genesis::InstallExperimentalNativeFunctions() { | 1584 void Genesis::InstallExperimentalNativeFunctions() { |
| 1603 INSTALL_NATIVE(JSFunction, "RunMicrotasks", run_microtasks); | 1585 INSTALL_NATIVE(JSFunction, "RunMicrotasks", run_microtasks); |
| 1586 INSTALL_NATIVE(JSFunction, "EnqueueExternalMicrotask", |
| 1587 enqueue_external_microtask); |
| 1588 |
| 1604 if (FLAG_harmony_proxies) { | 1589 if (FLAG_harmony_proxies) { |
| 1605 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); | 1590 INSTALL_NATIVE(JSFunction, "DerivedHasTrap", derived_has_trap); |
| 1606 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); | 1591 INSTALL_NATIVE(JSFunction, "DerivedGetTrap", derived_get_trap); |
| 1607 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); | 1592 INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap); |
| 1608 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); | 1593 INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate); |
| 1609 } | 1594 } |
| 1610 if (FLAG_harmony_observation) { | 1595 if (FLAG_harmony_observation) { |
| 1611 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); | 1596 INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change); |
| 1612 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); | 1597 INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice); |
| 1613 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", | 1598 INSTALL_NATIVE(JSFunction, "BeginPerformSplice", |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2069 INSTALL_EXPERIMENTAL_NATIVE(i, observation, "object-observe.js") | 2054 INSTALL_EXPERIMENTAL_NATIVE(i, observation, "object-observe.js") |
| 2070 INSTALL_EXPERIMENTAL_NATIVE(i, promises, "promise.js") | 2055 INSTALL_EXPERIMENTAL_NATIVE(i, promises, "promise.js") |
| 2071 INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") | 2056 INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js") |
| 2072 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") | 2057 INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js") |
| 2073 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") | 2058 INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js") |
| 2074 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") | 2059 INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js") |
| 2075 INSTALL_EXPERIMENTAL_NATIVE(i, maths, "harmony-math.js") | 2060 INSTALL_EXPERIMENTAL_NATIVE(i, maths, "harmony-math.js") |
| 2076 } | 2061 } |
| 2077 | 2062 |
| 2078 InstallExperimentalNativeFunctions(); | 2063 InstallExperimentalNativeFunctions(); |
| 2079 | 2064 InstallExperimentalBuiltinFunctionIds(); |
| 2080 return true; | 2065 return true; |
| 2081 } | 2066 } |
| 2082 | 2067 |
| 2083 | 2068 |
| 2084 static Handle<JSObject> ResolveBuiltinIdHolder( | 2069 static Handle<JSObject> ResolveBuiltinIdHolder( |
| 2085 Handle<Context> native_context, | 2070 Handle<Context> native_context, |
| 2086 const char* holder_expr) { | 2071 const char* holder_expr) { |
| 2087 Isolate* isolate = native_context->GetIsolate(); | 2072 Isolate* isolate = native_context->GetIsolate(); |
| 2088 Factory* factory = isolate->factory(); | 2073 Factory* factory = isolate->factory(); |
| 2089 Handle<GlobalObject> global(native_context->global_object()); | 2074 Handle<GlobalObject> global(native_context->global_object()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2119 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ | 2104 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ |
| 2120 native_context(), #holder_expr); \ | 2105 native_context(), #holder_expr); \ |
| 2121 BuiltinFunctionId id = k##name; \ | 2106 BuiltinFunctionId id = k##name; \ |
| 2122 InstallBuiltinFunctionId(holder, #fun_name, id); \ | 2107 InstallBuiltinFunctionId(holder, #fun_name, id); \ |
| 2123 } | 2108 } |
| 2124 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) | 2109 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) |
| 2125 #undef INSTALL_BUILTIN_ID | 2110 #undef INSTALL_BUILTIN_ID |
| 2126 } | 2111 } |
| 2127 | 2112 |
| 2128 | 2113 |
| 2114 void Genesis::InstallExperimentalBuiltinFunctionIds() { |
| 2115 HandleScope scope(isolate()); |
| 2116 if (FLAG_harmony_maths) { |
| 2117 Handle<JSObject> holder = ResolveBuiltinIdHolder(native_context(), "Math"); |
| 2118 InstallBuiltinFunctionId(holder, "clz32", kMathClz32); |
| 2119 } |
| 2120 } |
| 2121 |
| 2122 |
| 2129 // Do not forget to update macros.py with named constant | 2123 // Do not forget to update macros.py with named constant |
| 2130 // of cache id. | 2124 // of cache id. |
| 2131 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ | 2125 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ |
| 2132 F(16, native_context()->regexp_function()) | 2126 F(16, native_context()->regexp_function()) |
| 2133 | 2127 |
| 2134 | 2128 |
| 2135 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { | 2129 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { |
| 2136 Factory* factory = factory_function->GetIsolate()->factory(); | 2130 Factory* factory = factory_function->GetIsolate()->factory(); |
| 2137 // Caches are supposed to live for a long time, allocate in old space. | 2131 // Caches are supposed to live for a long time, allocate in old space. |
| 2138 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; | 2132 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 ASSERT(!function_map_writable_prototype_.is_null()); | 2562 ASSERT(!function_map_writable_prototype_.is_null()); |
| 2569 ASSERT(!strict_mode_function_map_writable_prototype_.is_null()); | 2563 ASSERT(!strict_mode_function_map_writable_prototype_.is_null()); |
| 2570 | 2564 |
| 2571 // Replace function instance maps to make prototype writable. | 2565 // Replace function instance maps to make prototype writable. |
| 2572 native_context()->set_function_map(*function_map_writable_prototype_); | 2566 native_context()->set_function_map(*function_map_writable_prototype_); |
| 2573 native_context()->set_strict_mode_function_map( | 2567 native_context()->set_strict_mode_function_map( |
| 2574 *strict_mode_function_map_writable_prototype_); | 2568 *strict_mode_function_map_writable_prototype_); |
| 2575 } | 2569 } |
| 2576 | 2570 |
| 2577 | 2571 |
| 2572 class NoTrackDoubleFieldsForSerializerScope { |
| 2573 public: |
| 2574 NoTrackDoubleFieldsForSerializerScope() : flag_(FLAG_track_double_fields) { |
| 2575 if (Serializer::enabled()) { |
| 2576 // Disable tracking double fields because heap numbers treated as |
| 2577 // immutable by the serializer. |
| 2578 FLAG_track_double_fields = false; |
| 2579 } |
| 2580 } |
| 2581 ~NoTrackDoubleFieldsForSerializerScope() { |
| 2582 if (Serializer::enabled()) { |
| 2583 FLAG_track_double_fields = flag_; |
| 2584 } |
| 2585 } |
| 2586 |
| 2587 private: |
| 2588 bool flag_; |
| 2589 }; |
| 2590 |
| 2591 |
| 2578 Genesis::Genesis(Isolate* isolate, | 2592 Genesis::Genesis(Isolate* isolate, |
| 2579 Handle<Object> global_object, | 2593 Handle<Object> global_object, |
| 2580 v8::Handle<v8::ObjectTemplate> global_template, | 2594 v8::Handle<v8::ObjectTemplate> global_template, |
| 2581 v8::ExtensionConfiguration* extensions) | 2595 v8::ExtensionConfiguration* extensions) |
| 2582 : isolate_(isolate), | 2596 : isolate_(isolate), |
| 2583 active_(isolate->bootstrapper()) { | 2597 active_(isolate->bootstrapper()) { |
| 2598 NoTrackDoubleFieldsForSerializerScope disable_double_tracking_for_serializer; |
| 2584 result_ = Handle<Context>::null(); | 2599 result_ = Handle<Context>::null(); |
| 2585 // If V8 cannot be initialized, just return. | 2600 // If V8 cannot be initialized, just return. |
| 2586 if (!V8::Initialize(NULL)) return; | 2601 if (!V8::Initialize(NULL)) return; |
| 2587 | 2602 |
| 2588 // Before creating the roots we must save the context and restore it | 2603 // Before creating the roots we must save the context and restore it |
| 2589 // on all function exits. | 2604 // on all function exits. |
| 2590 SaveContext saved_context(isolate); | 2605 SaveContext saved_context(isolate); |
| 2591 | 2606 |
| 2592 // During genesis, the boilerplate for stack overflow won't work until the | 2607 // During genesis, the boilerplate for stack overflow won't work until the |
| 2593 // environment has been at least partially initialized. Add a stack check | 2608 // environment has been at least partially initialized. Add a stack check |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2731 return from + sizeof(NestingCounterType); | 2746 return from + sizeof(NestingCounterType); |
| 2732 } | 2747 } |
| 2733 | 2748 |
| 2734 | 2749 |
| 2735 // Called when the top-level V8 mutex is destroyed. | 2750 // Called when the top-level V8 mutex is destroyed. |
| 2736 void Bootstrapper::FreeThreadResources() { | 2751 void Bootstrapper::FreeThreadResources() { |
| 2737 ASSERT(!IsActive()); | 2752 ASSERT(!IsActive()); |
| 2738 } | 2753 } |
| 2739 | 2754 |
| 2740 } } // namespace v8::internal | 2755 } } // namespace v8::internal |
| OLD | NEW |