| 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/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 v8::Local<v8::ObjectTemplate> global_proxy_template, | 178 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 179 Handle<JSGlobalProxy> global_proxy); | 179 Handle<JSGlobalProxy> global_proxy); |
| 180 // Hooks the given global proxy into the context. If the context was created | 180 // Hooks the given global proxy into the context. If the context was created |
| 181 // by deserialization then this will unhook the global proxy that was | 181 // by deserialization then this will unhook the global proxy that was |
| 182 // deserialized, leaving the GC to pick it up. | 182 // deserialized, leaving the GC to pick it up. |
| 183 void HookUpGlobalProxy(Handle<JSGlobalObject> global_object, | 183 void HookUpGlobalProxy(Handle<JSGlobalObject> global_object, |
| 184 Handle<JSGlobalProxy> global_proxy); | 184 Handle<JSGlobalProxy> global_proxy); |
| 185 // Similarly, we want to use the global that has been created by the templates | 185 // Similarly, we want to use the global that has been created by the templates |
| 186 // passed through the API. The global from the snapshot is detached from the | 186 // passed through the API. The global from the snapshot is detached from the |
| 187 // other objects in the snapshot. | 187 // other objects in the snapshot. |
| 188 void HookUpGlobalObject(Handle<JSGlobalObject> global_object, | 188 void HookUpGlobalObject(Handle<JSGlobalObject> global_object); |
| 189 Handle<FixedArray> outdated_contexts); | |
| 190 // The native context has a ScriptContextTable that store declarative bindings | 189 // The native context has a ScriptContextTable that store declarative bindings |
| 191 // made in script scopes. Add a "this" binding to that table pointing to the | 190 // made in script scopes. Add a "this" binding to that table pointing to the |
| 192 // global proxy. | 191 // global proxy. |
| 193 void InstallGlobalThisBinding(); | 192 void InstallGlobalThisBinding(); |
| 194 void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts); | |
| 195 // New context initialization. Used for creating a context from scratch. | 193 // New context initialization. Used for creating a context from scratch. |
| 196 void InitializeGlobal(Handle<JSGlobalObject> global_object, | 194 void InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 197 Handle<JSFunction> empty_function, | 195 Handle<JSFunction> empty_function, |
| 198 ContextType context_type); | 196 ContextType context_type); |
| 199 void InitializeExperimentalGlobal(); | 197 void InitializeExperimentalGlobal(); |
| 200 // Depending on the situation, expose and/or get rid of the utils object. | 198 // Depending on the situation, expose and/or get rid of the utils object. |
| 201 void ConfigureUtilsObject(ContextType context_type); | 199 void ConfigureUtilsObject(ContextType context_type); |
| 202 | 200 |
| 203 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ | 201 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
| 204 void InitializeGlobal_##id(); | 202 void InitializeGlobal_##id(); |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 int slot = scope_info->ReceiverContextSlotIndex(); | 914 int slot = scope_info->ReceiverContextSlotIndex(); |
| 917 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); | 915 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); |
| 918 context->set(slot, native_context()->global_proxy()); | 916 context->set(slot, native_context()->global_proxy()); |
| 919 | 917 |
| 920 Handle<ScriptContextTable> new_script_contexts = | 918 Handle<ScriptContextTable> new_script_contexts = |
| 921 ScriptContextTable::Extend(script_contexts, context); | 919 ScriptContextTable::Extend(script_contexts, context); |
| 922 native_context()->set_script_context_table(*new_script_contexts); | 920 native_context()->set_script_context_table(*new_script_contexts); |
| 923 } | 921 } |
| 924 | 922 |
| 925 | 923 |
| 926 void Genesis::HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts) { | |
| 927 // One of these contexts should be the one that declares the global "this" | |
| 928 // binding. | |
| 929 for (int i = 0; i < outdated_contexts->length(); ++i) { | |
| 930 Context* context = Context::cast(outdated_contexts->get(i)); | |
| 931 if (context->IsScriptContext()) { | |
| 932 ScopeInfo* scope_info = context->scope_info(); | |
| 933 int slot = scope_info->ReceiverContextSlotIndex(); | |
| 934 if (slot >= 0) { | |
| 935 DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS); | |
| 936 context->set(slot, native_context()->global_proxy()); | |
| 937 } | |
| 938 } | |
| 939 } | |
| 940 } | |
| 941 | |
| 942 | |
| 943 Handle<JSGlobalObject> Genesis::CreateNewGlobals( | 924 Handle<JSGlobalObject> Genesis::CreateNewGlobals( |
| 944 v8::Local<v8::ObjectTemplate> global_proxy_template, | 925 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 945 Handle<JSGlobalProxy> global_proxy) { | 926 Handle<JSGlobalProxy> global_proxy) { |
| 946 // The argument global_proxy_template aka data is an ObjectTemplateInfo. | 927 // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
| 947 // It has a constructor pointer that points at global_constructor which is a | 928 // It has a constructor pointer that points at global_constructor which is a |
| 948 // FunctionTemplateInfo. | 929 // FunctionTemplateInfo. |
| 949 // The global_proxy_constructor is used to (re)initialize the | 930 // The global_proxy_constructor is used to (re)initialize the |
| 950 // global_proxy. The global_proxy_constructor also has a prototype_template | 931 // global_proxy. The global_proxy_constructor also has a prototype_template |
| 951 // pointer that points at js_global_object_template which is an | 932 // pointer that points at js_global_object_template which is an |
| 952 // ObjectTemplateInfo. | 933 // ObjectTemplateInfo. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 global_object->set_global_proxy(*global_proxy); | 1019 global_object->set_global_proxy(*global_proxy); |
| 1039 global_proxy->set_native_context(*native_context()); | 1020 global_proxy->set_native_context(*native_context()); |
| 1040 // If we deserialized the context, the global proxy is already | 1021 // If we deserialized the context, the global proxy is already |
| 1041 // correctly set up. Otherwise it's undefined. | 1022 // correctly set up. Otherwise it's undefined. |
| 1042 DCHECK(native_context()->get(Context::GLOBAL_PROXY_INDEX)->IsUndefined() || | 1023 DCHECK(native_context()->get(Context::GLOBAL_PROXY_INDEX)->IsUndefined() || |
| 1043 native_context()->global_proxy() == *global_proxy); | 1024 native_context()->global_proxy() == *global_proxy); |
| 1044 native_context()->set_global_proxy(*global_proxy); | 1025 native_context()->set_global_proxy(*global_proxy); |
| 1045 } | 1026 } |
| 1046 | 1027 |
| 1047 | 1028 |
| 1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object, | 1029 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) { |
| 1049 Handle<FixedArray> outdated_contexts) { | |
| 1050 Handle<JSGlobalObject> global_object_from_snapshot( | 1030 Handle<JSGlobalObject> global_object_from_snapshot( |
| 1051 JSGlobalObject::cast(native_context()->extension())); | 1031 JSGlobalObject::cast(native_context()->extension())); |
| 1052 native_context()->set_extension(*global_object); | 1032 native_context()->set_extension(*global_object); |
| 1053 native_context()->set_security_token(*global_object); | 1033 native_context()->set_security_token(*global_object); |
| 1054 | 1034 |
| 1055 TransferNamedProperties(global_object_from_snapshot, global_object); | 1035 TransferNamedProperties(global_object_from_snapshot, global_object); |
| 1056 TransferIndexedProperties(global_object_from_snapshot, global_object); | 1036 TransferIndexedProperties(global_object_from_snapshot, global_object); |
| 1057 } | 1037 } |
| 1058 | 1038 |
| 1059 | 1039 |
| (...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3100 // Create an uninitialized global proxy now if we don't have one | 3080 // Create an uninitialized global proxy now if we don't have one |
| 3101 // and initialize it later in CreateNewGlobals. | 3081 // and initialize it later in CreateNewGlobals. |
| 3102 Handle<JSGlobalProxy> global_proxy; | 3082 Handle<JSGlobalProxy> global_proxy; |
| 3103 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 3083 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
| 3104 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); | 3084 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); |
| 3105 } | 3085 } |
| 3106 | 3086 |
| 3107 // We can only de-serialize a context if the isolate was initialized from | 3087 // We can only de-serialize a context if the isolate was initialized from |
| 3108 // a snapshot. Otherwise we have to build the context from scratch. | 3088 // a snapshot. Otherwise we have to build the context from scratch. |
| 3109 // Also create a context from scratch to expose natives, if required by flag. | 3089 // Also create a context from scratch to expose natives, if required by flag. |
| 3110 Handle<FixedArray> outdated_contexts; | |
| 3111 if (!isolate->initialized_from_snapshot() || | 3090 if (!isolate->initialized_from_snapshot() || |
| 3112 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, | 3091 !Snapshot::NewContextFromSnapshot(isolate, global_proxy) |
| 3113 &outdated_contexts) | |
| 3114 .ToHandle(&native_context_)) { | 3092 .ToHandle(&native_context_)) { |
| 3115 native_context_ = Handle<Context>(); | 3093 native_context_ = Handle<Context>(); |
| 3116 } | 3094 } |
| 3117 | 3095 |
| 3118 if (!native_context().is_null()) { | 3096 if (!native_context().is_null()) { |
| 3119 AddToWeakNativeContextList(*native_context()); | 3097 AddToWeakNativeContextList(*native_context()); |
| 3120 isolate->set_context(*native_context()); | 3098 isolate->set_context(*native_context()); |
| 3121 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 3099 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
| 3122 #if TRACE_MAPS | 3100 #if TRACE_MAPS |
| 3123 if (FLAG_trace_maps) { | 3101 if (FLAG_trace_maps) { |
| 3124 Handle<JSFunction> object_fun = isolate->object_function(); | 3102 Handle<JSFunction> object_fun = isolate->object_function(); |
| 3125 PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n", | 3103 PrintF("[TraceMap: InitialMap map= %p SFI= %d_Object ]\n", |
| 3126 reinterpret_cast<void*>(object_fun->initial_map()), | 3104 reinterpret_cast<void*>(object_fun->initial_map()), |
| 3127 object_fun->shared()->unique_id()); | 3105 object_fun->shared()->unique_id()); |
| 3128 Map::TraceAllTransitions(object_fun->initial_map()); | 3106 Map::TraceAllTransitions(object_fun->initial_map()); |
| 3129 } | 3107 } |
| 3130 #endif | 3108 #endif |
| 3131 Handle<JSGlobalObject> global_object = | 3109 Handle<JSGlobalObject> global_object = |
| 3132 CreateNewGlobals(global_proxy_template, global_proxy); | 3110 CreateNewGlobals(global_proxy_template, global_proxy); |
| 3133 | 3111 |
| 3134 HookUpGlobalProxy(global_object, global_proxy); | 3112 HookUpGlobalProxy(global_object, global_proxy); |
| 3135 HookUpGlobalObject(global_object, outdated_contexts); | 3113 HookUpGlobalObject(global_object); |
| 3136 HookUpGlobalThisBinding(outdated_contexts); | |
| 3137 | 3114 |
| 3138 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3115 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
| 3139 } else { | 3116 } else { |
| 3140 // We get here if there was no context snapshot. | 3117 // We get here if there was no context snapshot. |
| 3141 CreateRoots(); | 3118 CreateRoots(); |
| 3142 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3119 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
| 3143 CreateStrictModeFunctionMaps(empty_function); | 3120 CreateStrictModeFunctionMaps(empty_function); |
| 3144 CreateStrongModeFunctionMaps(empty_function); | 3121 CreateStrongModeFunctionMaps(empty_function); |
| 3145 CreateIteratorMaps(); | 3122 CreateIteratorMaps(); |
| 3146 Handle<JSGlobalObject> global_object = | 3123 Handle<JSGlobalObject> global_object = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 } | 3197 } |
| 3221 | 3198 |
| 3222 | 3199 |
| 3223 // Called when the top-level V8 mutex is destroyed. | 3200 // Called when the top-level V8 mutex is destroyed. |
| 3224 void Bootstrapper::FreeThreadResources() { | 3201 void Bootstrapper::FreeThreadResources() { |
| 3225 DCHECK(!IsActive()); | 3202 DCHECK(!IsActive()); |
| 3226 } | 3203 } |
| 3227 | 3204 |
| 3228 } // namespace internal | 3205 } // namespace internal |
| 3229 } // namespace v8 | 3206 } // namespace v8 |
| OLD | NEW |