| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); | 127 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); |
| 128 | 128 |
| 129 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 129 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 class Genesis BASE_EMBEDDED { | 133 class Genesis BASE_EMBEDDED { |
| 134 public: | 134 public: |
| 135 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 135 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 136 v8::Local<v8::ObjectTemplate> global_proxy_template, | 136 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 137 v8::ExtensionConfiguration* extensions, ContextType context_type); | 137 v8::ExtensionConfiguration* extensions, |
| 138 GlobalContextType context_type); |
| 138 ~Genesis() { } | 139 ~Genesis() { } |
| 139 | 140 |
| 140 Isolate* isolate() const { return isolate_; } | 141 Isolate* isolate() const { return isolate_; } |
| 141 Factory* factory() const { return isolate_->factory(); } | 142 Factory* factory() const { return isolate_->factory(); } |
| 142 Heap* heap() const { return isolate_->heap(); } | 143 Heap* heap() const { return isolate_->heap(); } |
| 143 | 144 |
| 144 Handle<Context> result() { return result_; } | 145 Handle<Context> result() { return result_; } |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 Handle<Context> native_context() { return native_context_; } | 148 Handle<Context> native_context() { return native_context_; } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // passed through the API. The global from the snapshot is detached from the | 181 // passed through the API. The global from the snapshot is detached from the |
| 181 // other objects in the snapshot. | 182 // other objects in the snapshot. |
| 182 void HookUpGlobalObject(Handle<JSGlobalObject> global_object); | 183 void HookUpGlobalObject(Handle<JSGlobalObject> global_object); |
| 183 // The native context has a ScriptContextTable that store declarative bindings | 184 // The native context has a ScriptContextTable that store declarative bindings |
| 184 // made in script scopes. Add a "this" binding to that table pointing to the | 185 // made in script scopes. Add a "this" binding to that table pointing to the |
| 185 // global proxy. | 186 // global proxy. |
| 186 void InstallGlobalThisBinding(); | 187 void InstallGlobalThisBinding(); |
| 187 // New context initialization. Used for creating a context from scratch. | 188 // New context initialization. Used for creating a context from scratch. |
| 188 void InitializeGlobal(Handle<JSGlobalObject> global_object, | 189 void InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 189 Handle<JSFunction> empty_function, | 190 Handle<JSFunction> empty_function, |
| 190 ContextType context_type); | 191 GlobalContextType context_type); |
| 191 void InitializeExperimentalGlobal(); | 192 void InitializeExperimentalGlobal(); |
| 192 // Depending on the situation, expose and/or get rid of the utils object. | 193 // Depending on the situation, expose and/or get rid of the utils object. |
| 193 void ConfigureUtilsObject(ContextType context_type); | 194 void ConfigureUtilsObject(GlobalContextType context_type); |
| 194 | 195 |
| 195 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ | 196 #define DECLARE_FEATURE_INITIALIZATION(id, descr) \ |
| 196 void InitializeGlobal_##id(); | 197 void InitializeGlobal_##id(); |
| 197 | 198 |
| 198 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) | 199 HARMONY_INPROGRESS(DECLARE_FEATURE_INITIALIZATION) |
| 199 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) | 200 HARMONY_STAGED(DECLARE_FEATURE_INITIALIZATION) |
| 200 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) | 201 HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION) |
| 201 DECLARE_FEATURE_INITIALIZATION(promise_extra, "") | 202 DECLARE_FEATURE_INITIALIZATION(promise_extra, "") |
| 202 #undef DECLARE_FEATURE_INITIALIZATION | 203 #undef DECLARE_FEATURE_INITIALIZATION |
| 203 | 204 |
| 204 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, | 205 Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, |
| 205 const char* name); | 206 const char* name); |
| 206 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, | 207 Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, |
| 207 const char* name, | 208 const char* name, |
| 208 ElementsKind elements_kind); | 209 ElementsKind elements_kind); |
| 209 bool InstallNatives(ContextType context_type); | 210 bool InstallNatives(GlobalContextType context_type); |
| 210 | 211 |
| 211 void InstallTypedArray(const char* name, ElementsKind elements_kind, | 212 void InstallTypedArray(const char* name, ElementsKind elements_kind, |
| 212 Handle<JSFunction>* fun); | 213 Handle<JSFunction>* fun); |
| 213 bool InstallExperimentalNatives(); | 214 bool InstallExperimentalNatives(); |
| 214 bool InstallExtraNatives(); | 215 bool InstallExtraNatives(); |
| 215 bool InstallExperimentalExtraNatives(); | 216 bool InstallExperimentalExtraNatives(); |
| 216 bool InstallDebuggerNatives(); | 217 bool InstallDebuggerNatives(); |
| 217 void InstallBuiltinFunctionIds(); | 218 void InstallBuiltinFunctionIds(); |
| 218 void InstallExperimentalBuiltinFunctionIds(); | 219 void InstallExperimentalBuiltinFunctionIds(); |
| 219 void InitializeNormalizedMapCaches(); | 220 void InitializeNormalizedMapCaches(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 BootstrapperActive active_; | 312 BootstrapperActive active_; |
| 312 friend class Bootstrapper; | 313 friend class Bootstrapper; |
| 313 }; | 314 }; |
| 314 | 315 |
| 315 | 316 |
| 316 void Bootstrapper::Iterate(ObjectVisitor* v) { | 317 void Bootstrapper::Iterate(ObjectVisitor* v) { |
| 317 extensions_cache_.Iterate(v); | 318 extensions_cache_.Iterate(v); |
| 318 v->Synchronize(VisitorSynchronization::kExtensions); | 319 v->Synchronize(VisitorSynchronization::kExtensions); |
| 319 } | 320 } |
| 320 | 321 |
| 321 | |
| 322 Handle<Context> Bootstrapper::CreateEnvironment( | 322 Handle<Context> Bootstrapper::CreateEnvironment( |
| 323 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 323 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 324 v8::Local<v8::ObjectTemplate> global_proxy_template, | 324 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 325 v8::ExtensionConfiguration* extensions, ContextType context_type) { | 325 v8::ExtensionConfiguration* extensions, GlobalContextType context_type) { |
| 326 HandleScope scope(isolate_); | 326 HandleScope scope(isolate_); |
| 327 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, | 327 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, |
| 328 extensions, context_type); | 328 extensions, context_type); |
| 329 Handle<Context> env = genesis.result(); | 329 Handle<Context> env = genesis.result(); |
| 330 if (env.is_null() || | 330 if (env.is_null() || |
| 331 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { | 331 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { |
| 332 return Handle<Context>(); | 332 return Handle<Context>(); |
| 333 } | 333 } |
| 334 return scope.CloseAndEscape(env); | 334 return scope.CloseAndEscape(env); |
| 335 } | 335 } |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 JSObject::AddProperty( | 1059 JSObject::AddProperty( |
| 1060 function, isolate->factory()->native_context_index_symbol(), index, NONE); | 1060 function, isolate->factory()->native_context_index_symbol(), index, NONE); |
| 1061 isolate->native_context()->set(context_index, *function); | 1061 isolate->native_context()->set(context_index, *function); |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 | 1064 |
| 1065 // This is only called if we are not using snapshots. The equivalent | 1065 // This is only called if we are not using snapshots. The equivalent |
| 1066 // work in the snapshot case is done in HookUpGlobalObject. | 1066 // work in the snapshot case is done in HookUpGlobalObject. |
| 1067 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, | 1067 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, |
| 1068 Handle<JSFunction> empty_function, | 1068 Handle<JSFunction> empty_function, |
| 1069 ContextType context_type) { | 1069 GlobalContextType context_type) { |
| 1070 // --- N a t i v e C o n t e x t --- | 1070 // --- N a t i v e C o n t e x t --- |
| 1071 // Use the empty function as closure (no scope info). | 1071 // Use the empty function as closure (no scope info). |
| 1072 native_context()->set_closure(*empty_function); | 1072 native_context()->set_closure(*empty_function); |
| 1073 native_context()->set_previous(NULL); | 1073 native_context()->set_previous(NULL); |
| 1074 // Set extension and global object. | 1074 // Set extension and global object. |
| 1075 native_context()->set_extension(*global_object); | 1075 native_context()->set_extension(*global_object); |
| 1076 // Security setup: Set the security token of the native context to the global | 1076 // Security setup: Set the security token of the native context to the global |
| 1077 // object. This makes the security check between two different contexts fail | 1077 // object. This makes the security check between two different contexts fail |
| 1078 // by default even in case of global object reinitialization. | 1078 // by default even in case of global object reinitialization. |
| 1079 native_context()->set_security_token(*global_object); | 1079 native_context()->set_security_token(*global_object); |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 Handle<JSFunction> function = Handle<JSFunction>::cast(object); | 1986 Handle<JSFunction> function = Handle<JSFunction>::cast(object); |
| 1987 return Handle<JSObject>(JSObject::cast(function->prototype())); | 1987 return Handle<JSObject>(JSObject::cast(function->prototype())); |
| 1988 } | 1988 } |
| 1989 Handle<String> inner_string = factory->InternalizeUtf8String(inner); | 1989 Handle<String> inner_string = factory->InternalizeUtf8String(inner); |
| 1990 DCHECK(!inner_string.is_null()); | 1990 DCHECK(!inner_string.is_null()); |
| 1991 Handle<Object> value = | 1991 Handle<Object> value = |
| 1992 Object::GetProperty(object, inner_string).ToHandleChecked(); | 1992 Object::GetProperty(object, inner_string).ToHandleChecked(); |
| 1993 return Handle<JSObject>::cast(value); | 1993 return Handle<JSObject>::cast(value); |
| 1994 } | 1994 } |
| 1995 | 1995 |
| 1996 | 1996 void Genesis::ConfigureUtilsObject(GlobalContextType context_type) { |
| 1997 void Genesis::ConfigureUtilsObject(ContextType context_type) { | |
| 1998 switch (context_type) { | 1997 switch (context_type) { |
| 1999 // We still need the utils object to find debug functions. | 1998 // We still need the utils object to find debug functions. |
| 2000 case DEBUG_CONTEXT: | 1999 case DEBUG_CONTEXT: |
| 2001 return; | 2000 return; |
| 2002 // Expose the natives in global if a valid name for it is specified. | 2001 // Expose the natives in global if a valid name for it is specified. |
| 2003 case FULL_CONTEXT: { | 2002 case FULL_CONTEXT: { |
| 2004 // We still need the utils object after deserialization. | 2003 // We still need the utils object after deserialization. |
| 2005 if (isolate()->serializer_enabled()) return; | 2004 if (isolate()->serializer_enabled()) return; |
| 2006 if (FLAG_expose_natives_as == NULL) break; | 2005 if (FLAG_expose_natives_as == NULL) break; |
| 2007 if (strlen(FLAG_expose_natives_as) == 0) break; | 2006 if (strlen(FLAG_expose_natives_as) == 0) break; |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2600 Accessors::ArrayLengthInfo(isolate(), attribs); | 2599 Accessors::ArrayLengthInfo(isolate(), attribs); |
| 2601 { // Add length. | 2600 { // Add length. |
| 2602 AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())), | 2601 AccessorConstantDescriptor d(Handle<Name>(Name::cast(array_length->name())), |
| 2603 array_length, attribs); | 2602 array_length, attribs); |
| 2604 initial_map->AppendDescriptor(&d); | 2603 initial_map->AppendDescriptor(&d); |
| 2605 } | 2604 } |
| 2606 | 2605 |
| 2607 return array_function; | 2606 return array_function; |
| 2608 } | 2607 } |
| 2609 | 2608 |
| 2610 | 2609 bool Genesis::InstallNatives(GlobalContextType context_type) { |
| 2611 bool Genesis::InstallNatives(ContextType context_type) { | |
| 2612 HandleScope scope(isolate()); | 2610 HandleScope scope(isolate()); |
| 2613 | 2611 |
| 2614 // Set up the utils object as shared container between native scripts. | 2612 // Set up the utils object as shared container between native scripts. |
| 2615 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); | 2613 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); |
| 2616 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, | 2614 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, |
| 2617 "utils container for native scripts"); | 2615 "utils container for native scripts"); |
| 2618 native_context()->set_natives_utils_object(*utils); | 2616 native_context()->set_natives_utils_object(*utils); |
| 2619 | 2617 |
| 2620 // Set up the extras utils object as a shared container between native | 2618 // Set up the extras utils object as a shared container between native |
| 2621 // scripts and extras. (Extras consume things added there by native scripts.) | 2619 // scripts and extras. (Extras consume things added there by native scripts.) |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3483 if (enabled_) { | 3481 if (enabled_) { |
| 3484 FLAG_track_double_fields = flag_; | 3482 FLAG_track_double_fields = flag_; |
| 3485 } | 3483 } |
| 3486 } | 3484 } |
| 3487 | 3485 |
| 3488 private: | 3486 private: |
| 3489 bool flag_; | 3487 bool flag_; |
| 3490 bool enabled_; | 3488 bool enabled_; |
| 3491 }; | 3489 }; |
| 3492 | 3490 |
| 3493 | |
| 3494 Genesis::Genesis(Isolate* isolate, | 3491 Genesis::Genesis(Isolate* isolate, |
| 3495 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 3492 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 3496 v8::Local<v8::ObjectTemplate> global_proxy_template, | 3493 v8::Local<v8::ObjectTemplate> global_proxy_template, |
| 3497 v8::ExtensionConfiguration* extensions, | 3494 v8::ExtensionConfiguration* extensions, |
| 3498 ContextType context_type) | 3495 GlobalContextType context_type) |
| 3499 : isolate_(isolate), active_(isolate->bootstrapper()) { | 3496 : isolate_(isolate), active_(isolate->bootstrapper()) { |
| 3500 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | 3497 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
| 3501 result_ = Handle<Context>::null(); | 3498 result_ = Handle<Context>::null(); |
| 3502 // Before creating the roots we must save the context and restore it | 3499 // Before creating the roots we must save the context and restore it |
| 3503 // on all function exits. | 3500 // on all function exits. |
| 3504 SaveContext saved_context(isolate); | 3501 SaveContext saved_context(isolate); |
| 3505 | 3502 |
| 3506 // During genesis, the boilerplate for stack overflow won't work until the | 3503 // During genesis, the boilerplate for stack overflow won't work until the |
| 3507 // environment has been at least partially initialized. Add a stack check | 3504 // environment has been at least partially initialized. Add a stack check |
| 3508 // before entering JS code to catch overflow early. | 3505 // before entering JS code to catch overflow early. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3631 } | 3628 } |
| 3632 | 3629 |
| 3633 | 3630 |
| 3634 // Called when the top-level V8 mutex is destroyed. | 3631 // Called when the top-level V8 mutex is destroyed. |
| 3635 void Bootstrapper::FreeThreadResources() { | 3632 void Bootstrapper::FreeThreadResources() { |
| 3636 DCHECK(!IsActive()); | 3633 DCHECK(!IsActive()); |
| 3637 } | 3634 } |
| 3638 | 3635 |
| 3639 } // namespace internal | 3636 } // namespace internal |
| 3640 } // namespace v8 | 3637 } // namespace v8 |
| OLD | NEW |