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); | |
205 // New context initialization. Used for creating a context from scratch. | 200 // New context initialization. Used for creating a context from scratch. |
206 void InitializeGlobal(Handle<GlobalObject> global_object, | 201 void InitializeGlobal(Handle<GlobalObject> global_object, |
207 Handle<JSFunction> empty_function); | 202 Handle<JSFunction> empty_function); |
208 void InitializeExperimentalGlobal(); | 203 void InitializeExperimentalGlobal(); |
209 // Installs the contents of the native .js files on the global objects. | 204 // Installs the contents of the native .js files on the global objects. |
210 // Used for creating a context from scratch. | 205 // Used for creating a context from scratch. |
211 void InstallNativeFunctions(); | 206 void InstallNativeFunctions(); |
212 void InstallExperimentalNativeFunctions(); | 207 void InstallExperimentalNativeFunctions(); |
213 // Typed arrays are not serializable and have to initialized afterwards. | 208 // Typed arrays are not serializable and have to initialized afterwards. |
214 void InitializeBuiltinTypedArrays(); | 209 void InitializeBuiltinTypedArrays(); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 AddToWeakNativeContextList(*native_context()); | 806 AddToWeakNativeContextList(*native_context()); |
812 isolate()->set_context(*native_context()); | 807 isolate()->set_context(*native_context()); |
813 | 808 |
814 // Allocate the message listeners object. | 809 // Allocate the message listeners object. |
815 { | 810 { |
816 v8::NeanderArray listeners(isolate()); | 811 v8::NeanderArray listeners(isolate()); |
817 native_context()->set_message_listeners(*listeners.value()); | 812 native_context()->set_message_listeners(*listeners.value()); |
818 } | 813 } |
819 } | 814 } |
820 | 815 |
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 native_context()->set_script_context_table( | |
835 *ScriptContextTable::Extend(script_contexts, context)); | |
836 } | |
837 | |
838 | |
839 void Genesis::HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts) { | |
840 // One of these contexts should be the one that declares the global "this" | |
841 // binding. | |
842 for (int i = 0; i < outdated_contexts->length(); ++i) { | |
843 Context* context = Context::cast(outdated_contexts->get(i)); | |
844 if (context->IsScriptContext()) { | |
845 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); | |
846 int slot = scope_info->ReceiverContextSlotIndex(); | |
847 if (slot >= 0) { | |
848 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); | |
849 context->set(slot, native_context()->global_proxy()); | |
850 } | |
851 } | |
852 } | |
853 } | |
854 | |
855 | 816 |
856 Handle<GlobalObject> Genesis::CreateNewGlobals( | 817 Handle<GlobalObject> Genesis::CreateNewGlobals( |
857 v8::Handle<v8::ObjectTemplate> global_proxy_template, | 818 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
858 Handle<JSGlobalProxy> global_proxy) { | 819 Handle<JSGlobalProxy> global_proxy) { |
859 // The argument global_proxy_template aka data is an ObjectTemplateInfo. | 820 // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
860 // It has a constructor pointer that points at global_constructor which is a | 821 // It has a constructor pointer that points at global_constructor which is a |
861 // FunctionTemplateInfo. | 822 // FunctionTemplateInfo. |
862 // The global_proxy_constructor is used to (re)initialize the | 823 // The global_proxy_constructor is used to (re)initialize the |
863 // global_proxy. The global_proxy_constructor also has a prototype_template | 824 // global_proxy. The global_proxy_constructor also has a prototype_template |
864 // pointer that points at js_global_object_template which is an | 825 // pointer that points at js_global_object_template which is an |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 // by default even in case of global object reinitialization. | 965 // by default even in case of global object reinitialization. |
1005 native_context()->set_security_token(*global_object); | 966 native_context()->set_security_token(*global_object); |
1006 | 967 |
1007 Isolate* isolate = global_object->GetIsolate(); | 968 Isolate* isolate = global_object->GetIsolate(); |
1008 Factory* factory = isolate->factory(); | 969 Factory* factory = isolate->factory(); |
1009 Heap* heap = isolate->heap(); | 970 Heap* heap = isolate->heap(); |
1010 | 971 |
1011 Handle<ScriptContextTable> script_context_table = | 972 Handle<ScriptContextTable> script_context_table = |
1012 factory->NewScriptContextTable(); | 973 factory->NewScriptContextTable(); |
1013 native_context()->set_script_context_table(*script_context_table); | 974 native_context()->set_script_context_table(*script_context_table); |
1014 InstallGlobalThisBinding(); | |
1015 | 975 |
1016 Handle<String> object_name = factory->Object_string(); | 976 Handle<String> object_name = factory->Object_string(); |
1017 JSObject::AddProperty( | 977 JSObject::AddProperty( |
1018 global_object, object_name, isolate->object_function(), DONT_ENUM); | 978 global_object, object_name, isolate->object_function(), DONT_ENUM); |
1019 | 979 |
1020 Handle<JSObject> global(native_context()->global_object()); | 980 Handle<JSObject> global(native_context()->global_object()); |
1021 | 981 |
1022 // Install global Function object | 982 // Install global Function object |
1023 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 983 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
1024 empty_function, Builtins::kIllegal); | 984 empty_function, Builtins::kIllegal); |
(...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3119 Map::TraceAllTransitions(object_fun->initial_map()); | 3079 Map::TraceAllTransitions(object_fun->initial_map()); |
3120 } | 3080 } |
3121 #endif | 3081 #endif |
3122 Handle<GlobalObject> global_object = | 3082 Handle<GlobalObject> global_object = |
3123 CreateNewGlobals(global_proxy_template, global_proxy); | 3083 CreateNewGlobals(global_proxy_template, global_proxy); |
3124 | 3084 |
3125 HookUpGlobalProxy(global_object, global_proxy); | 3085 HookUpGlobalProxy(global_object, global_proxy); |
3126 HookUpGlobalObject(global_object, outdated_contexts); | 3086 HookUpGlobalObject(global_object, outdated_contexts); |
3127 native_context()->builtins()->set_global_proxy( | 3087 native_context()->builtins()->set_global_proxy( |
3128 native_context()->global_proxy()); | 3088 native_context()->global_proxy()); |
3129 HookUpGlobalThisBinding(outdated_contexts); | |
3130 | 3089 |
3131 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3090 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3132 } else { | 3091 } else { |
3133 // We get here if there was no context snapshot. | 3092 // We get here if there was no context snapshot. |
3134 CreateRoots(); | 3093 CreateRoots(); |
3135 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3094 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
3136 CreateStrictModeFunctionMaps(empty_function); | 3095 CreateStrictModeFunctionMaps(empty_function); |
3137 CreateStrongModeFunctionMaps(empty_function); | 3096 CreateStrongModeFunctionMaps(empty_function); |
3138 Handle<GlobalObject> global_object = | 3097 Handle<GlobalObject> global_object = |
3139 CreateNewGlobals(global_proxy_template, global_proxy); | 3098 CreateNewGlobals(global_proxy_template, global_proxy); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3189 } | 3148 } |
3190 | 3149 |
3191 | 3150 |
3192 // Called when the top-level V8 mutex is destroyed. | 3151 // Called when the top-level V8 mutex is destroyed. |
3193 void Bootstrapper::FreeThreadResources() { | 3152 void Bootstrapper::FreeThreadResources() { |
3194 DCHECK(!IsActive()); | 3153 DCHECK(!IsActive()); |
3195 } | 3154 } |
3196 | 3155 |
3197 } // namespace internal | 3156 } // namespace internal |
3198 } // namespace v8 | 3157 } // namespace v8 |
OLD | NEW |