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 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 | 816 |
857 Handle<GlobalObject> Genesis::CreateNewGlobals( | 817 Handle<GlobalObject> Genesis::CreateNewGlobals( |
858 v8::Handle<v8::ObjectTemplate> global_proxy_template, | 818 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
859 Handle<JSGlobalProxy> global_proxy) { | 819 Handle<JSGlobalProxy> global_proxy) { |
860 // The argument global_proxy_template aka data is an ObjectTemplateInfo. | 820 // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
861 // 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 |
862 // FunctionTemplateInfo. | 822 // FunctionTemplateInfo. |
863 // The global_proxy_constructor is used to (re)initialize the | 823 // The global_proxy_constructor is used to (re)initialize the |
864 // global_proxy. The global_proxy_constructor also has a prototype_template | 824 // global_proxy. The global_proxy_constructor also has a prototype_template |
865 // 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... |
1005 // by default even in case of global object reinitialization. | 965 // by default even in case of global object reinitialization. |
1006 native_context()->set_security_token(*global_object); | 966 native_context()->set_security_token(*global_object); |
1007 | 967 |
1008 Isolate* isolate = global_object->GetIsolate(); | 968 Isolate* isolate = global_object->GetIsolate(); |
1009 Factory* factory = isolate->factory(); | 969 Factory* factory = isolate->factory(); |
1010 Heap* heap = isolate->heap(); | 970 Heap* heap = isolate->heap(); |
1011 | 971 |
1012 Handle<ScriptContextTable> script_context_table = | 972 Handle<ScriptContextTable> script_context_table = |
1013 factory->NewScriptContextTable(); | 973 factory->NewScriptContextTable(); |
1014 native_context()->set_script_context_table(*script_context_table); | 974 native_context()->set_script_context_table(*script_context_table); |
1015 InstallGlobalThisBinding(); | |
1016 | 975 |
1017 Handle<String> object_name = factory->Object_string(); | 976 Handle<String> object_name = factory->Object_string(); |
1018 JSObject::AddProperty( | 977 JSObject::AddProperty( |
1019 global_object, object_name, isolate->object_function(), DONT_ENUM); | 978 global_object, object_name, isolate->object_function(), DONT_ENUM); |
1020 | 979 |
1021 Handle<JSObject> global(native_context()->global_object()); | 980 Handle<JSObject> global(native_context()->global_object()); |
1022 | 981 |
1023 // Install global Function object | 982 // Install global Function object |
1024 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 983 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
1025 empty_function, Builtins::kIllegal); | 984 empty_function, Builtins::kIllegal); |
(...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3120 Map::TraceAllTransitions(object_fun->initial_map()); | 3079 Map::TraceAllTransitions(object_fun->initial_map()); |
3121 } | 3080 } |
3122 #endif | 3081 #endif |
3123 Handle<GlobalObject> global_object = | 3082 Handle<GlobalObject> global_object = |
3124 CreateNewGlobals(global_proxy_template, global_proxy); | 3083 CreateNewGlobals(global_proxy_template, global_proxy); |
3125 | 3084 |
3126 HookUpGlobalProxy(global_object, global_proxy); | 3085 HookUpGlobalProxy(global_object, global_proxy); |
3127 HookUpGlobalObject(global_object, outdated_contexts); | 3086 HookUpGlobalObject(global_object, outdated_contexts); |
3128 native_context()->builtins()->set_global_proxy( | 3087 native_context()->builtins()->set_global_proxy( |
3129 native_context()->global_proxy()); | 3088 native_context()->global_proxy()); |
3130 HookUpGlobalThisBinding(outdated_contexts); | |
3131 | 3089 |
3132 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3090 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3133 } else { | 3091 } else { |
3134 // We get here if there was no context snapshot. | 3092 // We get here if there was no context snapshot. |
3135 CreateRoots(); | 3093 CreateRoots(); |
3136 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3094 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
3137 CreateStrictModeFunctionMaps(empty_function); | 3095 CreateStrictModeFunctionMaps(empty_function); |
3138 CreateStrongModeFunctionMaps(empty_function); | 3096 CreateStrongModeFunctionMaps(empty_function); |
3139 Handle<GlobalObject> global_object = | 3097 Handle<GlobalObject> global_object = |
3140 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... |
3190 } | 3148 } |
3191 | 3149 |
3192 | 3150 |
3193 // Called when the top-level V8 mutex is destroyed. | 3151 // Called when the top-level V8 mutex is destroyed. |
3194 void Bootstrapper::FreeThreadResources() { | 3152 void Bootstrapper::FreeThreadResources() { |
3195 DCHECK(!IsActive()); | 3153 DCHECK(!IsActive()); |
3196 } | 3154 } |
3197 | 3155 |
3198 } // namespace internal | 3156 } // namespace internal |
3199 } // namespace v8 | 3157 } // namespace v8 |
OLD | NEW |