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/ieee754.h" | 9 #include "src/base/ieee754.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 134 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 class Genesis BASE_EMBEDDED { | 138 class Genesis BASE_EMBEDDED { |
139 public: | 139 public: |
140 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 140 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
141 v8::Local<v8::ObjectTemplate> global_proxy_template, | 141 v8::Local<v8::ObjectTemplate> global_proxy_template, |
142 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, | 142 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
143 GlobalContextType context_type); | 143 GlobalContextType context_type); |
144 Genesis(Isolate* isolate, | |
145 v8::Local<v8::ObjectTemplate> global_proxy_template); | |
144 ~Genesis() { } | 146 ~Genesis() { } |
145 | 147 |
146 Isolate* isolate() const { return isolate_; } | 148 Isolate* isolate() const { return isolate_; } |
147 Factory* factory() const { return isolate_->factory(); } | 149 Factory* factory() const { return isolate_->factory(); } |
148 Heap* heap() const { return isolate_->heap(); } | 150 Heap* heap() const { return isolate_->heap(); } |
149 | 151 |
150 Handle<Context> result() { return result_; } | 152 Handle<Context> result() { return result_; } |
151 | 153 |
154 Handle<JSGlobalProxy> global_proxy() { return global_proxy_; } | |
155 | |
152 private: | 156 private: |
153 Handle<Context> native_context() { return native_context_; } | 157 Handle<Context> native_context() { return native_context_; } |
154 | 158 |
155 // Creates some basic objects. Used for creating a context from scratch. | 159 // Creates some basic objects. Used for creating a context from scratch. |
156 void CreateRoots(); | 160 void CreateRoots(); |
157 // Creates the empty function. Used for creating a context from scratch. | 161 // Creates the empty function. Used for creating a context from scratch. |
158 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); | 162 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); |
159 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 | 163 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 |
160 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); | 164 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); |
161 Handle<JSFunction> GetStrictArgumentsPoisonFunction(); | 165 Handle<JSFunction> GetStrictArgumentsPoisonFunction(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, | 299 void SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
296 FunctionMode function_mode); | 300 FunctionMode function_mode); |
297 | 301 |
298 static bool CallUtilsFunction(Isolate* isolate, const char* name); | 302 static bool CallUtilsFunction(Isolate* isolate, const char* name); |
299 | 303 |
300 static bool CompileExtension(Isolate* isolate, v8::Extension* extension); | 304 static bool CompileExtension(Isolate* isolate, v8::Extension* extension); |
301 | 305 |
302 Isolate* isolate_; | 306 Isolate* isolate_; |
303 Handle<Context> result_; | 307 Handle<Context> result_; |
304 Handle<Context> native_context_; | 308 Handle<Context> native_context_; |
309 Handle<JSGlobalProxy> global_proxy_; | |
305 | 310 |
306 // Function maps. Function maps are created initially with a read only | 311 // Function maps. Function maps are created initially with a read only |
307 // prototype for the processing of JS builtins. Later the function maps are | 312 // prototype for the processing of JS builtins. Later the function maps are |
308 // replaced in order to make prototype writable. These are the final, writable | 313 // replaced in order to make prototype writable. These are the final, writable |
309 // prototype, maps. | 314 // prototype, maps. |
310 Handle<Map> sloppy_function_map_writable_prototype_; | 315 Handle<Map> sloppy_function_map_writable_prototype_; |
311 Handle<Map> strict_function_map_writable_prototype_; | 316 Handle<Map> strict_function_map_writable_prototype_; |
312 Handle<JSFunction> strict_poison_function_; | 317 Handle<JSFunction> strict_poison_function_; |
313 Handle<JSFunction> restricted_function_properties_thrower_; | 318 Handle<JSFunction> restricted_function_properties_thrower_; |
314 | 319 |
(...skipping 15 matching lines...) Expand all Loading... | |
330 HandleScope scope(isolate_); | 335 HandleScope scope(isolate_); |
331 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, | 336 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, |
332 extensions, context_snapshot_index, context_type); | 337 extensions, context_snapshot_index, context_type); |
333 Handle<Context> env = genesis.result(); | 338 Handle<Context> env = genesis.result(); |
334 if (env.is_null() || !InstallExtensions(env, extensions)) { | 339 if (env.is_null() || !InstallExtensions(env, extensions)) { |
335 return Handle<Context>(); | 340 return Handle<Context>(); |
336 } | 341 } |
337 return scope.CloseAndEscape(env); | 342 return scope.CloseAndEscape(env); |
338 } | 343 } |
339 | 344 |
345 Handle<JSGlobalProxy> Bootstrapper::NewDetachedGlobal( | |
346 v8::Local<v8::ObjectTemplate> global_proxy_template) { | |
347 HandleScope scope(isolate_); | |
348 Genesis genesis(isolate_, global_proxy_template); | |
349 Handle<JSGlobalProxy> global_proxy = genesis.global_proxy(); | |
350 if (global_proxy.is_null()) return Handle<JSGlobalProxy>(); | |
351 return scope.CloseAndEscape(global_proxy); | |
352 } | |
340 | 353 |
341 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 354 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
342 // object.__proto__ = proto; | 355 // object.__proto__ = proto; |
343 Handle<Map> old_map = Handle<Map>(object->map()); | 356 Handle<Map> old_map = Handle<Map>(object->map()); |
344 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); | 357 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); |
345 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); | 358 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); |
346 JSObject::MigrateToMap(object, new_map); | 359 JSObject::MigrateToMap(object, new_map); |
347 } | 360 } |
348 | 361 |
349 | 362 |
(...skipping 3457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3807 }; | 3820 }; |
3808 | 3821 |
3809 Genesis::Genesis(Isolate* isolate, | 3822 Genesis::Genesis(Isolate* isolate, |
3810 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 3823 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
3811 v8::Local<v8::ObjectTemplate> global_proxy_template, | 3824 v8::Local<v8::ObjectTemplate> global_proxy_template, |
3812 v8::ExtensionConfiguration* extensions, | 3825 v8::ExtensionConfiguration* extensions, |
3813 size_t context_snapshot_index, GlobalContextType context_type) | 3826 size_t context_snapshot_index, GlobalContextType context_type) |
3814 : isolate_(isolate), active_(isolate->bootstrapper()) { | 3827 : isolate_(isolate), active_(isolate->bootstrapper()) { |
3815 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | 3828 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
3816 result_ = Handle<Context>::null(); | 3829 result_ = Handle<Context>::null(); |
3830 global_proxy_ = Handle<JSGlobalProxy>::null(); | |
3831 | |
3817 // Before creating the roots we must save the context and restore it | 3832 // Before creating the roots we must save the context and restore it |
3818 // on all function exits. | 3833 // on all function exits. |
3819 SaveContext saved_context(isolate); | 3834 SaveContext saved_context(isolate); |
3820 | 3835 |
3821 // During genesis, the boilerplate for stack overflow won't work until the | 3836 // During genesis, the boilerplate for stack overflow won't work until the |
3822 // environment has been at least partially initialized. Add a stack check | 3837 // environment has been at least partially initialized. Add a stack check |
3823 // before entering JS code to catch overflow early. | 3838 // before entering JS code to catch overflow early. |
3824 StackLimitCheck check(isolate); | 3839 StackLimitCheck check(isolate); |
3825 if (check.HasOverflowed()) { | 3840 if (check.HasOverflowed()) { |
3826 isolate->StackOverflow(); | 3841 isolate->StackOverflow(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3915 | 3930 |
3916 // Check that the script context table is empty except for the 'this' binding. | 3931 // Check that the script context table is empty except for the 'this' binding. |
3917 // We do not need script contexts for native scripts. | 3932 // We do not need script contexts for native scripts. |
3918 if (!FLAG_global_var_shortcuts) { | 3933 if (!FLAG_global_var_shortcuts) { |
3919 DCHECK_EQ(1, native_context()->script_context_table()->used()); | 3934 DCHECK_EQ(1, native_context()->script_context_table()->used()); |
3920 } | 3935 } |
3921 | 3936 |
3922 result_ = native_context(); | 3937 result_ = native_context(); |
3923 } | 3938 } |
3924 | 3939 |
3940 Genesis::Genesis(Isolate* isolate, | |
Toon Verwaest
2016/07/06 15:34:34
Don't you want to do the same as above and also pa
| |
3941 v8::Local<v8::ObjectTemplate> global_proxy_template) | |
3942 : isolate_(isolate), active_(isolate->bootstrapper()) { | |
3943 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | |
3944 result_ = Handle<Context>::null(); | |
3945 global_proxy_ = Handle<JSGlobalProxy>::null(); | |
3946 | |
3947 // Before creating the roots we must save the context and restore it | |
3948 // on all function exits. | |
3949 SaveContext saved_context(isolate); | |
3950 | |
3951 // During genesis, the boilerplate for stack overflow won't work until the | |
3952 // environment has been at least partially initialized. Add a stack check | |
3953 // before entering JS code to catch overflow early. | |
3954 StackLimitCheck check(isolate); | |
3955 if (check.HasOverflowed()) { | |
3956 isolate->StackOverflow(); | |
3957 return; | |
3958 } | |
3959 | |
3960 Handle<JSGlobalProxy> global_proxy = | |
3961 factory()->NewUninitializedJSGlobalProxy(); | |
3962 | |
3963 // CreateNewGlobals. | |
3964 Handle<ObjectTemplateInfo> global_proxy_data = | |
3965 v8::Utils::OpenHandle(*global_proxy_template); | |
3966 Handle<FunctionTemplateInfo> global_constructor( | |
3967 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | |
3968 Handle<SharedFunctionInfo> shared = | |
3969 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, | |
3970 global_constructor); | |
3971 Handle<Map> initial_map = | |
3972 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | |
3973 Handle<JSFunction> global_proxy_function = | |
3974 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
3975 initial_map, shared, factory()->undefined_value()); | |
3976 DCHECK_EQ(Smi::cast(global_proxy_data->internal_field_count())->value(), 0); | |
3977 Handle<Map> global_proxy_map = isolate->factory()->NewMap( | |
3978 JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, FAST_HOLEY_SMI_ELEMENTS); | |
3979 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, | |
3980 factory()->null_value()); | |
3981 global_proxy_map->set_is_access_check_needed(true); | |
3982 global_proxy_map->set_is_callable(); | |
3983 global_proxy_map->set_is_constructor(true); | |
3984 global_proxy_map->set_has_hidden_prototype(true); | |
3985 | |
3986 Handle<String> global_name = factory()->global_string(); | |
3987 global_proxy_function->shared()->set_instance_class_name(*global_name); | |
3988 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | |
3989 | |
3990 // HookUpGlobalProxy. | |
3991 global_proxy->set_native_context(*factory()->null_value()); | |
3992 | |
3993 // DetachGlobal. | |
3994 SetObjectPrototype(global_proxy, factory()->null_value()); | |
3995 | |
3996 global_proxy_ = global_proxy; | |
3997 } | |
3925 | 3998 |
3926 // Support for thread preemption. | 3999 // Support for thread preemption. |
3927 | 4000 |
3928 // Reserve space for statics needing saving and restoring. | 4001 // Reserve space for statics needing saving and restoring. |
3929 int Bootstrapper::ArchiveSpacePerThread() { | 4002 int Bootstrapper::ArchiveSpacePerThread() { |
3930 return sizeof(NestingCounterType); | 4003 return sizeof(NestingCounterType); |
3931 } | 4004 } |
3932 | 4005 |
3933 | 4006 |
3934 // Archive statics that are thread-local. | 4007 // Archive statics that are thread-local. |
(...skipping 11 matching lines...) Expand all Loading... | |
3946 } | 4019 } |
3947 | 4020 |
3948 | 4021 |
3949 // Called when the top-level V8 mutex is destroyed. | 4022 // Called when the top-level V8 mutex is destroyed. |
3950 void Bootstrapper::FreeThreadResources() { | 4023 void Bootstrapper::FreeThreadResources() { |
3951 DCHECK(!IsActive()); | 4024 DCHECK(!IsActive()); |
3952 } | 4025 } |
3953 | 4026 |
3954 } // namespace internal | 4027 } // namespace internal |
3955 } // namespace v8 | 4028 } // namespace v8 |
OLD | NEW |