Chromium Code Reviews| 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 3454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3804 }; | 3817 }; |
| 3805 | 3818 |
| 3806 Genesis::Genesis(Isolate* isolate, | 3819 Genesis::Genesis(Isolate* isolate, |
| 3807 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 3820 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 3808 v8::Local<v8::ObjectTemplate> global_proxy_template, | 3821 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 3809 v8::ExtensionConfiguration* extensions, | 3822 v8::ExtensionConfiguration* extensions, |
| 3810 size_t context_snapshot_index, GlobalContextType context_type) | 3823 size_t context_snapshot_index, GlobalContextType context_type) |
| 3811 : isolate_(isolate), active_(isolate->bootstrapper()) { | 3824 : isolate_(isolate), active_(isolate->bootstrapper()) { |
| 3812 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | 3825 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
| 3813 result_ = Handle<Context>::null(); | 3826 result_ = Handle<Context>::null(); |
| 3827 global_proxy_ = Handle<JSGlobalProxy>::null(); | |
| 3828 | |
| 3814 // Before creating the roots we must save the context and restore it | 3829 // Before creating the roots we must save the context and restore it |
| 3815 // on all function exits. | 3830 // on all function exits. |
| 3816 SaveContext saved_context(isolate); | 3831 SaveContext saved_context(isolate); |
| 3817 | 3832 |
| 3818 // During genesis, the boilerplate for stack overflow won't work until the | 3833 // During genesis, the boilerplate for stack overflow won't work until the |
| 3819 // environment has been at least partially initialized. Add a stack check | 3834 // environment has been at least partially initialized. Add a stack check |
| 3820 // before entering JS code to catch overflow early. | 3835 // before entering JS code to catch overflow early. |
| 3821 StackLimitCheck check(isolate); | 3836 StackLimitCheck check(isolate); |
| 3822 if (check.HasOverflowed()) { | 3837 if (check.HasOverflowed()) { |
| 3823 isolate->StackOverflow(); | 3838 isolate->StackOverflow(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3912 | 3927 |
| 3913 // Check that the script context table is empty except for the 'this' binding. | 3928 // Check that the script context table is empty except for the 'this' binding. |
| 3914 // We do not need script contexts for native scripts. | 3929 // We do not need script contexts for native scripts. |
| 3915 if (!FLAG_global_var_shortcuts) { | 3930 if (!FLAG_global_var_shortcuts) { |
| 3916 DCHECK_EQ(1, native_context()->script_context_table()->used()); | 3931 DCHECK_EQ(1, native_context()->script_context_table()->used()); |
| 3917 } | 3932 } |
| 3918 | 3933 |
| 3919 result_ = native_context(); | 3934 result_ = native_context(); |
| 3920 } | 3935 } |
| 3921 | 3936 |
| 3937 Genesis::Genesis(Isolate* isolate, | |
| 3938 v8::Local<v8::ObjectTemplate> global_proxy_template) | |
| 3939 : isolate_(isolate), active_(isolate->bootstrapper()) { | |
| 3940 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | |
| 3941 result_ = Handle<Context>::null(); | |
| 3942 global_proxy_ = Handle<JSGlobalProxy>::null(); | |
| 3943 | |
| 3944 // Before creating the roots we must save the context and restore it | |
| 3945 // on all function exits. | |
| 3946 SaveContext saved_context(isolate); | |
| 3947 | |
| 3948 // During genesis, the boilerplate for stack overflow won't work until the | |
| 3949 // environment has been at least partially initialized. Add a stack check | |
| 3950 // before entering JS code to catch overflow early. | |
| 3951 StackLimitCheck check(isolate); | |
| 3952 if (check.HasOverflowed()) { | |
| 3953 isolate->StackOverflow(); | |
| 3954 return; | |
| 3955 } | |
| 3956 | |
| 3957 Handle<JSGlobalProxy> global_proxy = | |
| 3958 factory()->NewUninitializedJSGlobalProxy(); | |
| 3959 | |
| 3960 // CreateNewGlobals. | |
| 3961 Handle<ObjectTemplateInfo> global_proxy_data = | |
| 3962 v8::Utils::OpenHandle(*global_proxy_template); | |
| 3963 Handle<FunctionTemplateInfo> global_constructor( | |
| 3964 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | |
| 3965 | |
| 3966 Handle<Map> initial_map = | |
| 3967 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | |
| 3968 Handle<JSFunction> global_proxy_function = | |
| 3969 ApiNatives::CreateApiFunctionWithMap( | |
| 3970 isolate, factory()->undefined_value(), global_constructor, | |
| 3971 initial_map, factory()->the_hole_value(), | |
| 3972 ApiNatives::GlobalProxyType); | |
| 3973 Handle<String> global_name = factory()->global_string(); | |
| 3974 global_proxy_function->shared()->set_instance_class_name(*global_name); | |
| 3975 global_proxy_function->initial_map()->set_is_access_check_needed(true); | |
| 3976 global_proxy_function->initial_map()->set_has_hidden_prototype(true); | |
| 3977 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | |
| 3978 | |
| 3979 // HookUpGlobalProxy. | |
| 3980 global_proxy->set_native_context(*factory()->null_value()); | |
| 3981 | |
|
jochen (gone - plz use gerrit)
2016/06/28 14:27:00
The regular genesis path would also invoke Configu
| |
| 3982 // DetachGlobal. | |
| 3983 SetObjectPrototype(global_proxy, factory()->null_value()); | |
|
jochen (gone - plz use gerrit)
2016/06/28 14:27:00
regular DetachGlobal would also delete the constru
| |
| 3984 | |
| 3985 global_proxy_ = global_proxy; | |
| 3986 } | |
| 3922 | 3987 |
| 3923 // Support for thread preemption. | 3988 // Support for thread preemption. |
| 3924 | 3989 |
| 3925 // Reserve space for statics needing saving and restoring. | 3990 // Reserve space for statics needing saving and restoring. |
| 3926 int Bootstrapper::ArchiveSpacePerThread() { | 3991 int Bootstrapper::ArchiveSpacePerThread() { |
| 3927 return sizeof(NestingCounterType); | 3992 return sizeof(NestingCounterType); |
| 3928 } | 3993 } |
| 3929 | 3994 |
| 3930 | 3995 |
| 3931 // Archive statics that are thread-local. | 3996 // Archive statics that are thread-local. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 3943 } | 4008 } |
| 3944 | 4009 |
| 3945 | 4010 |
| 3946 // Called when the top-level V8 mutex is destroyed. | 4011 // Called when the top-level V8 mutex is destroyed. |
| 3947 void Bootstrapper::FreeThreadResources() { | 4012 void Bootstrapper::FreeThreadResources() { |
| 3948 DCHECK(!IsActive()); | 4013 DCHECK(!IsActive()); |
| 3949 } | 4014 } |
| 3950 | 4015 |
| 3951 } // namespace internal | 4016 } // namespace internal |
| 3952 } // namespace v8 | 4017 } // namespace v8 |
| OLD | NEW |