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 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4772 } | 4772 } |
| 4773 | 4773 |
| 4774 const int proxy_size = JSGlobalProxy::SizeWithInternalFields( | 4774 const int proxy_size = JSGlobalProxy::SizeWithInternalFields( |
| 4775 global_proxy_template->InternalFieldCount()); | 4775 global_proxy_template->InternalFieldCount()); |
| 4776 | 4776 |
| 4777 Handle<JSGlobalProxy> global_proxy; | 4777 Handle<JSGlobalProxy> global_proxy; |
| 4778 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 4778 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
| 4779 global_proxy = factory()->NewUninitializedJSGlobalProxy(proxy_size); | 4779 global_proxy = factory()->NewUninitializedJSGlobalProxy(proxy_size); |
| 4780 } | 4780 } |
| 4781 | 4781 |
| 4782 // CreateNewGlobals. | 4782 // Create a remote object as the global object. |
| 4783 Handle<ObjectTemplateInfo> global_proxy_data = | 4783 Handle<ObjectTemplateInfo> global_proxy_data = |
| 4784 v8::Utils::OpenHandle(*global_proxy_template); | 4784 Utils::OpenHandle(*global_proxy_template); |
| 4785 Handle<FunctionTemplateInfo> global_constructor( | 4785 Handle<FunctionTemplateInfo> global_constructor( |
| 4786 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 4786 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
| 4787 | |
| 4788 Handle<ObjectTemplateInfo> global_object_template( | |
| 4789 ObjectTemplateInfo::cast(global_constructor->prototype_template())); | |
| 4790 Handle<JSObject> global_object = | |
| 4791 ApiNatives::InstantiateRemoteObject( | |
| 4792 global_object_template).ToHandleChecked(); | |
| 4793 | |
| 4794 // (Re)initialize the global proxy object. | |
| 4787 Handle<SharedFunctionInfo> shared = | 4795 Handle<SharedFunctionInfo> shared = |
| 4788 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, | 4796 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, |
| 4789 global_constructor); | 4797 global_constructor); |
| 4790 Handle<Map> initial_map = | 4798 Handle<Map> initial_map = |
| 4791 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | 4799 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); |
| 4792 Handle<JSFunction> global_proxy_function = | 4800 Handle<JSFunction> global_proxy_function = |
| 4793 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 4801 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 4794 initial_map, shared, factory()->undefined_value()); | 4802 initial_map, shared, factory()->undefined_value()); |
| 4795 DCHECK_EQ(global_proxy_data->internal_field_count(), | 4803 DCHECK_EQ(global_proxy_data->internal_field_count(), |
| 4796 global_proxy_template->InternalFieldCount()); | 4804 global_proxy_template->InternalFieldCount()); |
| 4797 Handle<Map> global_proxy_map = isolate->factory()->NewMap( | 4805 Handle<Map> global_proxy_map = isolate->factory()->NewMap( |
| 4798 JS_GLOBAL_PROXY_TYPE, proxy_size, FAST_HOLEY_SMI_ELEMENTS); | 4806 JS_GLOBAL_PROXY_TYPE, proxy_size, FAST_HOLEY_SMI_ELEMENTS); |
| 4799 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, | 4807 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, |
| 4800 factory()->null_value()); | 4808 factory()->null_value()); |
| 4801 global_proxy_map->set_is_access_check_needed(true); | 4809 global_proxy_map->set_is_access_check_needed(true); |
| 4802 global_proxy_map->set_is_callable(); | 4810 global_proxy_map->set_is_callable(); |
| 4803 global_proxy_map->set_is_constructor(true); | 4811 global_proxy_map->set_is_constructor(true); |
| 4804 global_proxy_map->set_has_hidden_prototype(true); | 4812 global_proxy_map->set_has_hidden_prototype(true); |
| 4805 | 4813 |
| 4806 Handle<String> global_name = factory()->global_string(); | 4814 Handle<String> global_name = factory()->global_string(); |
| 4807 global_proxy_function->shared()->set_instance_class_name(*global_name); | 4815 global_proxy_function->shared()->set_instance_class_name(*global_name); |
| 4808 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 4816 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
| 4809 | 4817 |
| 4810 // GlobalProxy. | 4818 // A remote global proxy has no native context. |
| 4811 global_proxy->set_native_context(heap()->null_value()); | 4819 global_proxy->set_native_context(heap()->null_value()); |
| 4812 | 4820 |
| 4813 // DetachGlobal. | 4821 // Configure the hidden prototype chain of the global proxy. |
| 4814 JSObject::ForceSetPrototype(global_proxy, factory()->null_value()); | 4822 JSObject::ForceSetPrototype(global_proxy, global_object); |
| 4823 // TODO(dcheng): This is a hack. Why does this need to be manually called | |
| 4824 // here? Line 4812 should have taken care of it? | |
| 4825 global_proxy->map()->set_has_hidden_prototype(true); | |
|
dcheng
2017/02/17 07:29:08
I don't actually understand why this is needed, so
jochen (gone - plz use gerrit)
2017/02/17 08:40:26
ForceSetPrototype creates a new map
dcheng
2017/02/17 10:08:27
Initialization of a full context does this too; ye
| |
| 4815 | 4826 |
| 4816 global_proxy_ = global_proxy; | 4827 global_proxy_ = global_proxy; |
| 4817 } | 4828 } |
| 4818 | 4829 |
| 4819 // Support for thread preemption. | 4830 // Support for thread preemption. |
| 4820 | 4831 |
| 4821 // Reserve space for statics needing saving and restoring. | 4832 // Reserve space for statics needing saving and restoring. |
| 4822 int Bootstrapper::ArchiveSpacePerThread() { | 4833 int Bootstrapper::ArchiveSpacePerThread() { |
| 4823 return sizeof(NestingCounterType); | 4834 return sizeof(NestingCounterType); |
| 4824 } | 4835 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4839 } | 4850 } |
| 4840 | 4851 |
| 4841 | 4852 |
| 4842 // Called when the top-level V8 mutex is destroyed. | 4853 // Called when the top-level V8 mutex is destroyed. |
| 4843 void Bootstrapper::FreeThreadResources() { | 4854 void Bootstrapper::FreeThreadResources() { |
| 4844 DCHECK(!IsActive()); | 4855 DCHECK(!IsActive()); |
| 4845 } | 4856 } |
| 4846 | 4857 |
| 4847 } // namespace internal | 4858 } // namespace internal |
| 4848 } // namespace v8 | 4859 } // namespace v8 |
| OLD | NEW |