| 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/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/base/utils/random-number-generator.h" | 9 #include "src/base/utils/random-number-generator.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Hooks the given global proxy into the context. If the context was created | 190 // Hooks the given global proxy into the context. If the context was created |
| 191 // by deserialization then this will unhook the global proxy that was | 191 // by deserialization then this will unhook the global proxy that was |
| 192 // deserialized, leaving the GC to pick it up. | 192 // deserialized, leaving the GC to pick it up. |
| 193 void HookUpGlobalProxy(Handle<GlobalObject> global_object, | 193 void HookUpGlobalProxy(Handle<GlobalObject> global_object, |
| 194 Handle<JSGlobalProxy> global_proxy); | 194 Handle<JSGlobalProxy> global_proxy); |
| 195 // Similarly, we want to use the global that has been created by the templates | 195 // Similarly, we want to use the global that has been created by the templates |
| 196 // passed through the API. The global from the snapshot is detached from the | 196 // passed through the API. The global from the snapshot is detached from the |
| 197 // other objects in the snapshot. | 197 // other objects in the snapshot. |
| 198 void HookUpGlobalObject(Handle<GlobalObject> global_object, | 198 void HookUpGlobalObject(Handle<GlobalObject> global_object, |
| 199 Handle<FixedArray> outdated_contexts); | 199 Handle<FixedArray> outdated_contexts); |
| 200 // The native context has a ScriptContextTable that store declarative bindings |
| 201 // made in script scopes. Add a "this" binding to that table pointing to the |
| 202 // global proxy. |
| 203 void InstallGlobalThisBinding(); |
| 204 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts); |
| 200 // New context initialization. Used for creating a context from scratch. | 205 // New context initialization. Used for creating a context from scratch. |
| 201 void InitializeGlobal(Handle<GlobalObject> global_object, | 206 void InitializeGlobal(Handle<GlobalObject> global_object, |
| 202 Handle<JSFunction> empty_function); | 207 Handle<JSFunction> empty_function); |
| 203 void InitializeExperimentalGlobal(); | 208 void InitializeExperimentalGlobal(); |
| 204 // 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. |
| 205 // Used for creating a context from scratch. | 210 // Used for creating a context from scratch. |
| 206 void InstallNativeFunctions(); | 211 void InstallNativeFunctions(); |
| 207 void InstallExperimentalNativeFunctions(); | 212 void InstallExperimentalNativeFunctions(); |
| 208 // Typed arrays are not serializable and have to initialized afterwards. | 213 // Typed arrays are not serializable and have to initialized afterwards. |
| 209 void InitializeBuiltinTypedArrays(); | 214 void InitializeBuiltinTypedArrays(); |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 isolate()->set_context(*native_context()); | 812 isolate()->set_context(*native_context()); |
| 808 | 813 |
| 809 // Allocate the message listeners object. | 814 // Allocate the message listeners object. |
| 810 { | 815 { |
| 811 v8::NeanderArray listeners(isolate()); | 816 v8::NeanderArray listeners(isolate()); |
| 812 native_context()->set_message_listeners(*listeners.value()); | 817 native_context()->set_message_listeners(*listeners.value()); |
| 813 } | 818 } |
| 814 } | 819 } |
| 815 | 820 |
| 816 | 821 |
| 822 void Genesis::InstallGlobalThisBinding() { |
| 823 Handle<ScriptContextTable> script_contexts( |
| 824 native_context()->script_context_table()); |
| 825 Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate()); |
| 826 Handle<JSFunction> closure(native_context()->closure()); |
| 827 Handle<Context> context = factory()->NewScriptContext(closure, scope_info); |
| 828 |
| 829 // Go ahead and hook it up while we're at it. |
| 830 int slot = scope_info->ReceiverContextSlotIndex(); |
| 831 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); |
| 832 context->set(slot, native_context()->global_proxy()); |
| 833 |
| 834 Handle<ScriptContextTable> new_script_contexts = |
| 835 ScriptContextTable::Extend(script_contexts, context); |
| 836 native_context()->set_script_context_table(*new_script_contexts); |
| 837 } |
| 838 |
| 839 |
| 840 void Genesis::HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts) { |
| 841 // One of these contexts should be the one that declares the global "this" |
| 842 // binding. |
| 843 for (int i = 0; i < outdated_contexts->length(); ++i) { |
| 844 Context* context = Context::cast(outdated_contexts->get(i)); |
| 845 if (context->IsScriptContext()) { |
| 846 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); |
| 847 int slot = scope_info->ReceiverContextSlotIndex(); |
| 848 if (slot >= 0) { |
| 849 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); |
| 850 context->set(slot, native_context()->global_proxy()); |
| 851 } |
| 852 } |
| 853 } |
| 854 } |
| 855 |
| 856 |
| 817 Handle<GlobalObject> Genesis::CreateNewGlobals( | 857 Handle<GlobalObject> Genesis::CreateNewGlobals( |
| 818 v8::Handle<v8::ObjectTemplate> global_proxy_template, | 858 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 819 Handle<JSGlobalProxy> global_proxy) { | 859 Handle<JSGlobalProxy> global_proxy) { |
| 820 // The argument global_proxy_template aka data is an ObjectTemplateInfo. | 860 // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
| 821 // It has a constructor pointer that points at global_constructor which is a | 861 // It has a constructor pointer that points at global_constructor which is a |
| 822 // FunctionTemplateInfo. | 862 // FunctionTemplateInfo. |
| 823 // The global_proxy_constructor is used to (re)initialize the | 863 // The global_proxy_constructor is used to (re)initialize the |
| 824 // global_proxy. The global_proxy_constructor also has a prototype_template | 864 // global_proxy. The global_proxy_constructor also has a prototype_template |
| 825 // pointer that points at js_global_object_template which is an | 865 // pointer that points at js_global_object_template which is an |
| 826 // ObjectTemplateInfo. | 866 // ObjectTemplateInfo. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 // by default even in case of global object reinitialization. | 1005 // by default even in case of global object reinitialization. |
| 966 native_context()->set_security_token(*global_object); | 1006 native_context()->set_security_token(*global_object); |
| 967 | 1007 |
| 968 Isolate* isolate = global_object->GetIsolate(); | 1008 Isolate* isolate = global_object->GetIsolate(); |
| 969 Factory* factory = isolate->factory(); | 1009 Factory* factory = isolate->factory(); |
| 970 Heap* heap = isolate->heap(); | 1010 Heap* heap = isolate->heap(); |
| 971 | 1011 |
| 972 Handle<ScriptContextTable> script_context_table = | 1012 Handle<ScriptContextTable> script_context_table = |
| 973 factory->NewScriptContextTable(); | 1013 factory->NewScriptContextTable(); |
| 974 native_context()->set_script_context_table(*script_context_table); | 1014 native_context()->set_script_context_table(*script_context_table); |
| 1015 InstallGlobalThisBinding(); |
| 975 | 1016 |
| 976 Handle<String> object_name = factory->Object_string(); | 1017 Handle<String> object_name = factory->Object_string(); |
| 977 JSObject::AddProperty( | 1018 JSObject::AddProperty( |
| 978 global_object, object_name, isolate->object_function(), DONT_ENUM); | 1019 global_object, object_name, isolate->object_function(), DONT_ENUM); |
| 979 | 1020 |
| 980 Handle<JSObject> global(native_context()->global_object()); | 1021 Handle<JSObject> global(native_context()->global_object()); |
| 981 | 1022 |
| 982 // Install global Function object | 1023 // Install global Function object |
| 983 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 1024 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 984 empty_function, Builtins::kIllegal); | 1025 empty_function, Builtins::kIllegal); |
| (...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3079 Map::TraceAllTransitions(object_fun->initial_map()); | 3120 Map::TraceAllTransitions(object_fun->initial_map()); |
| 3080 } | 3121 } |
| 3081 #endif | 3122 #endif |
| 3082 Handle<GlobalObject> global_object = | 3123 Handle<GlobalObject> global_object = |
| 3083 CreateNewGlobals(global_proxy_template, global_proxy); | 3124 CreateNewGlobals(global_proxy_template, global_proxy); |
| 3084 | 3125 |
| 3085 HookUpGlobalProxy(global_object, global_proxy); | 3126 HookUpGlobalProxy(global_object, global_proxy); |
| 3086 HookUpGlobalObject(global_object, outdated_contexts); | 3127 HookUpGlobalObject(global_object, outdated_contexts); |
| 3087 native_context()->builtins()->set_global_proxy( | 3128 native_context()->builtins()->set_global_proxy( |
| 3088 native_context()->global_proxy()); | 3129 native_context()->global_proxy()); |
| 3130 HookUpGlobalThisBinding(outdated_contexts); |
| 3089 | 3131 |
| 3090 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3132 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
| 3091 } else { | 3133 } else { |
| 3092 // We get here if there was no context snapshot. | 3134 // We get here if there was no context snapshot. |
| 3093 CreateRoots(); | 3135 CreateRoots(); |
| 3094 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3136 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
| 3095 CreateStrictModeFunctionMaps(empty_function); | 3137 CreateStrictModeFunctionMaps(empty_function); |
| 3096 CreateStrongModeFunctionMaps(empty_function); | 3138 CreateStrongModeFunctionMaps(empty_function); |
| 3097 Handle<GlobalObject> global_object = | 3139 Handle<GlobalObject> global_object = |
| 3098 CreateNewGlobals(global_proxy_template, global_proxy); | 3140 CreateNewGlobals(global_proxy_template, global_proxy); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3148 } | 3190 } |
| 3149 | 3191 |
| 3150 | 3192 |
| 3151 // Called when the top-level V8 mutex is destroyed. | 3193 // Called when the top-level V8 mutex is destroyed. |
| 3152 void Bootstrapper::FreeThreadResources() { | 3194 void Bootstrapper::FreeThreadResources() { |
| 3153 DCHECK(!IsActive()); | 3195 DCHECK(!IsActive()); |
| 3154 } | 3196 } |
| 3155 | 3197 |
| 3156 } // namespace internal | 3198 } // namespace internal |
| 3157 } // namespace v8 | 3199 } // namespace v8 |
| OLD | NEW |