Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: src/bootstrapper.cc

Issue 2107673003: Add an API to create a detached global object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/bootstrapper.h ('k') | src/counters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
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
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
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::NewRemoteContext(
346 MaybeHandle<JSGlobalProxy> maybe_global_proxy,
347 v8::Local<v8::ObjectTemplate> global_proxy_template) {
348 HandleScope scope(isolate_);
349 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template);
350 Handle<JSGlobalProxy> global_proxy = genesis.global_proxy();
351 if (global_proxy.is_null()) return Handle<JSGlobalProxy>();
352 return scope.CloseAndEscape(global_proxy);
353 }
340 354
341 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { 355 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
342 // object.__proto__ = proto; 356 // object.__proto__ = proto;
343 Handle<Map> old_map = Handle<Map>(object->map()); 357 Handle<Map> old_map = Handle<Map>(object->map());
344 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); 358 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype");
345 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); 359 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE);
346 JSObject::MigrateToMap(object, new_map); 360 JSObject::MigrateToMap(object, new_map);
347 } 361 }
348 362
349 363
(...skipping 3527 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 }; 3891 };
3878 3892
3879 Genesis::Genesis(Isolate* isolate, 3893 Genesis::Genesis(Isolate* isolate,
3880 MaybeHandle<JSGlobalProxy> maybe_global_proxy, 3894 MaybeHandle<JSGlobalProxy> maybe_global_proxy,
3881 v8::Local<v8::ObjectTemplate> global_proxy_template, 3895 v8::Local<v8::ObjectTemplate> global_proxy_template,
3882 v8::ExtensionConfiguration* extensions, 3896 v8::ExtensionConfiguration* extensions,
3883 size_t context_snapshot_index, GlobalContextType context_type) 3897 size_t context_snapshot_index, GlobalContextType context_type)
3884 : isolate_(isolate), active_(isolate->bootstrapper()) { 3898 : isolate_(isolate), active_(isolate->bootstrapper()) {
3885 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); 3899 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
3886 result_ = Handle<Context>::null(); 3900 result_ = Handle<Context>::null();
3901 global_proxy_ = Handle<JSGlobalProxy>::null();
3902
3887 // Before creating the roots we must save the context and restore it 3903 // Before creating the roots we must save the context and restore it
3888 // on all function exits. 3904 // on all function exits.
3889 SaveContext saved_context(isolate); 3905 SaveContext saved_context(isolate);
3890 3906
3891 // During genesis, the boilerplate for stack overflow won't work until the 3907 // During genesis, the boilerplate for stack overflow won't work until the
3892 // environment has been at least partially initialized. Add a stack check 3908 // environment has been at least partially initialized. Add a stack check
3893 // before entering JS code to catch overflow early. 3909 // before entering JS code to catch overflow early.
3894 StackLimitCheck check(isolate); 3910 StackLimitCheck check(isolate);
3895 if (check.HasOverflowed()) { 3911 if (check.HasOverflowed()) {
3896 isolate->StackOverflow(); 3912 isolate->StackOverflow();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 4001
3986 // Check that the script context table is empty except for the 'this' binding. 4002 // Check that the script context table is empty except for the 'this' binding.
3987 // We do not need script contexts for native scripts. 4003 // We do not need script contexts for native scripts.
3988 if (!FLAG_global_var_shortcuts) { 4004 if (!FLAG_global_var_shortcuts) {
3989 DCHECK_EQ(1, native_context()->script_context_table()->used()); 4005 DCHECK_EQ(1, native_context()->script_context_table()->used());
3990 } 4006 }
3991 4007
3992 result_ = native_context(); 4008 result_ = native_context();
3993 } 4009 }
3994 4010
4011 Genesis::Genesis(Isolate* isolate,
4012 MaybeHandle<JSGlobalProxy> maybe_global_proxy,
4013 v8::Local<v8::ObjectTemplate> global_proxy_template)
4014 : isolate_(isolate), active_(isolate->bootstrapper()) {
4015 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
4016 result_ = Handle<Context>::null();
4017 global_proxy_ = Handle<JSGlobalProxy>::null();
4018
4019 // Before creating the roots we must save the context and restore it
4020 // on all function exits.
4021 SaveContext saved_context(isolate);
4022
4023 // During genesis, the boilerplate for stack overflow won't work until the
4024 // environment has been at least partially initialized. Add a stack check
4025 // before entering JS code to catch overflow early.
4026 StackLimitCheck check(isolate);
4027 if (check.HasOverflowed()) {
4028 isolate->StackOverflow();
4029 return;
4030 }
4031
4032 Handle<JSGlobalProxy> global_proxy;
4033 if (maybe_global_proxy.ToHandle(&global_proxy)) {
4034 if (global_proxy->native_context()->IsContext()) {
4035 Handle<Context> env =
4036 handle(Context::cast(global_proxy->native_context()));
4037 isolate->bootstrapper()->DetachGlobal(env);
Toon Verwaest 2016/07/07 11:15:25 Why do you manually detach here but not in regular
4038 }
4039 } else {
4040 global_proxy = factory()->NewUninitializedJSGlobalProxy();
4041 }
4042
4043 // CreateNewGlobals.
4044 Handle<ObjectTemplateInfo> global_proxy_data =
4045 v8::Utils::OpenHandle(*global_proxy_template);
4046 Handle<FunctionTemplateInfo> global_constructor(
4047 FunctionTemplateInfo::cast(global_proxy_data->constructor()));
4048 Handle<SharedFunctionInfo> shared =
4049 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate,
4050 global_constructor);
4051 Handle<Map> initial_map =
4052 CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE);
4053 Handle<JSFunction> global_proxy_function =
4054 isolate->factory()->NewFunctionFromSharedFunctionInfo(
4055 initial_map, shared, factory()->undefined_value());
4056 DCHECK_EQ(global_proxy_data->internal_field_count(), 0);
4057 Handle<Map> global_proxy_map = isolate->factory()->NewMap(
4058 JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, FAST_HOLEY_SMI_ELEMENTS);
4059 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map,
4060 factory()->null_value());
4061 global_proxy_map->set_is_access_check_needed(true);
4062 global_proxy_map->set_is_callable();
4063 global_proxy_map->set_is_constructor(true);
4064 global_proxy_map->set_has_hidden_prototype(true);
4065
4066 Handle<String> global_name = factory()->global_string();
4067 global_proxy_function->shared()->set_instance_class_name(*global_name);
4068 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
4069
4070 // HookUpGlobalProxy.
4071 global_proxy->set_native_context(*factory()->null_value());
4072
4073 // DetachGlobal.
4074 SetObjectPrototype(global_proxy, factory()->null_value());
4075
4076 global_proxy_ = global_proxy;
4077 }
3995 4078
3996 // Support for thread preemption. 4079 // Support for thread preemption.
3997 4080
3998 // Reserve space for statics needing saving and restoring. 4081 // Reserve space for statics needing saving and restoring.
3999 int Bootstrapper::ArchiveSpacePerThread() { 4082 int Bootstrapper::ArchiveSpacePerThread() {
4000 return sizeof(NestingCounterType); 4083 return sizeof(NestingCounterType);
4001 } 4084 }
4002 4085
4003 4086
4004 // Archive statics that are thread-local. 4087 // Archive statics that are thread-local.
(...skipping 11 matching lines...) Expand all
4016 } 4099 }
4017 4100
4018 4101
4019 // Called when the top-level V8 mutex is destroyed. 4102 // Called when the top-level V8 mutex is destroyed.
4020 void Bootstrapper::FreeThreadResources() { 4103 void Bootstrapper::FreeThreadResources() {
4021 DCHECK(!IsActive()); 4104 DCHECK(!IsActive());
4022 } 4105 }
4023 4106
4024 } // namespace internal 4107 } // namespace internal
4025 } // namespace v8 4108 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698