| 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/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/extensions/externalize-string-extension.h" | 9 #include "src/extensions/externalize-string-extension.h" |
| 10 #include "src/extensions/free-buffer-extension.h" | 10 #include "src/extensions/free-buffer-extension.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 delete_these_arrays_on_tear_down_ = NULL; | 141 delete_these_arrays_on_tear_down_ = NULL; |
| 142 } | 142 } |
| 143 | 143 |
| 144 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 144 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 class Genesis BASE_EMBEDDED { | 148 class Genesis BASE_EMBEDDED { |
| 149 public: | 149 public: |
| 150 Genesis(Isolate* isolate, | 150 Genesis(Isolate* isolate, |
| 151 Handle<Object> global_object, | 151 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 152 v8::Handle<v8::ObjectTemplate> global_template, | 152 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 153 v8::ExtensionConfiguration* extensions); | 153 v8::ExtensionConfiguration* extensions); |
| 154 ~Genesis() { } | 154 ~Genesis() { } |
| 155 | 155 |
| 156 Isolate* isolate() const { return isolate_; } | 156 Isolate* isolate() const { return isolate_; } |
| 157 Factory* factory() const { return isolate_->factory(); } | 157 Factory* factory() const { return isolate_->factory(); } |
| 158 Heap* heap() const { return isolate_->heap(); } | 158 Heap* heap() const { return isolate_->heap(); } |
| 159 | 159 |
| 160 Handle<Context> result() { return result_; } | 160 Handle<Context> result() { return result_; } |
| 161 | 161 |
| 162 private: | 162 private: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 176 // Make the "arguments" and "caller" properties throw a TypeError on access. | 176 // Make the "arguments" and "caller" properties throw a TypeError on access. |
| 177 void PoisonArgumentsAndCaller(Handle<Map> map); | 177 void PoisonArgumentsAndCaller(Handle<Map> map); |
| 178 | 178 |
| 179 // Creates the global objects using the global and the template passed in | 179 // Creates the global objects using the global and the template passed in |
| 180 // through the API. We call this regardless of whether we are building a | 180 // through the API. We call this regardless of whether we are building a |
| 181 // context from scratch or using a deserialized one from the partial snapshot | 181 // context from scratch or using a deserialized one from the partial snapshot |
| 182 // but in the latter case we don't use the objects it produces directly, as | 182 // but in the latter case we don't use the objects it produces directly, as |
| 183 // we have to used the deserialized ones that are linked together with the | 183 // we have to used the deserialized ones that are linked together with the |
| 184 // rest of the context snapshot. | 184 // rest of the context snapshot. |
| 185 Handle<JSGlobalProxy> CreateNewGlobals( | 185 Handle<JSGlobalProxy> CreateNewGlobals( |
| 186 v8::Handle<v8::ObjectTemplate> global_template, | 186 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 187 Handle<Object> global_object, | 187 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 188 Handle<GlobalObject>* global_proxy_out); | 188 Handle<GlobalObject>* global_object_out); |
| 189 // Hooks the given global proxy into the context. If the context was created | 189 // Hooks the given global proxy into the context. If the context was created |
| 190 // by deserialization then this will unhook the global proxy that was | 190 // by deserialization then this will unhook the global proxy that was |
| 191 // deserialized, leaving the GC to pick it up. | 191 // deserialized, leaving the GC to pick it up. |
| 192 void HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 192 void HookUpGlobalProxy(Handle<GlobalObject> global_object, |
| 193 Handle<JSGlobalProxy> global_proxy); | 193 Handle<JSGlobalProxy> global_proxy); |
| 194 // Similarly, we want to use the inner global that has been created by the | 194 // Similarly, we want to use the global that has been created by the templates |
| 195 // templates passed through the API. The inner global from the snapshot is | 195 // passed through the API. The global from the snapshot is detached from the |
| 196 // detached from the other objects in the snapshot. | 196 // other objects in the snapshot. |
| 197 void HookUpInnerGlobal(Handle<GlobalObject> inner_global); | 197 void HookUpGlobalObject(Handle<GlobalObject> global_object); |
| 198 // New context initialization. Used for creating a context from scratch. | 198 // New context initialization. Used for creating a context from scratch. |
| 199 void InitializeGlobal(Handle<GlobalObject> inner_global, | 199 void InitializeGlobal(Handle<GlobalObject> global_object, |
| 200 Handle<JSFunction> empty_function); | 200 Handle<JSFunction> empty_function); |
| 201 void InitializeExperimentalGlobal(); | 201 void InitializeExperimentalGlobal(); |
| 202 // Installs the contents of the native .js files on the global objects. | 202 // Installs the contents of the native .js files on the global objects. |
| 203 // Used for creating a context from scratch. | 203 // Used for creating a context from scratch. |
| 204 void InstallNativeFunctions(); | 204 void InstallNativeFunctions(); |
| 205 void InstallExperimentalBuiltinFunctionIds(); | 205 void InstallExperimentalBuiltinFunctionIds(); |
| 206 void InstallExperimentalNativeFunctions(); | 206 void InstallExperimentalNativeFunctions(); |
| 207 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, | 207 Handle<JSFunction> InstallInternalArray(Handle<JSBuiltinsObject> builtins, |
| 208 const char* name, | 208 const char* name, |
| 209 ElementsKind elements_kind); | 209 ElementsKind elements_kind); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 static bool InstallExtension(Isolate* isolate, | 246 static bool InstallExtension(Isolate* isolate, |
| 247 const char* name, | 247 const char* name, |
| 248 ExtensionStates* extension_states); | 248 ExtensionStates* extension_states); |
| 249 static bool InstallExtension(Isolate* isolate, | 249 static bool InstallExtension(Isolate* isolate, |
| 250 v8::RegisteredExtension* current, | 250 v8::RegisteredExtension* current, |
| 251 ExtensionStates* extension_states); | 251 ExtensionStates* extension_states); |
| 252 static bool InstallSpecialObjects(Handle<Context> native_context); | 252 static bool InstallSpecialObjects(Handle<Context> native_context); |
| 253 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); | 253 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); |
| 254 bool ConfigureApiObject(Handle<JSObject> object, | 254 bool ConfigureApiObject(Handle<JSObject> object, |
| 255 Handle<ObjectTemplateInfo> object_template); | 255 Handle<ObjectTemplateInfo> object_template); |
| 256 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); | 256 bool ConfigureGlobalObjects( |
| 257 v8::Handle<v8::ObjectTemplate> global_proxy_template); |
| 257 | 258 |
| 258 // Migrates all properties from the 'from' object to the 'to' | 259 // Migrates all properties from the 'from' object to the 'to' |
| 259 // object and overrides the prototype in 'to' with the one from | 260 // object and overrides the prototype in 'to' with the one from |
| 260 // 'from'. | 261 // 'from'. |
| 261 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 262 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 262 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 263 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 263 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 264 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 264 | 265 |
| 265 enum FunctionMode { | 266 enum FunctionMode { |
| 266 // With prototype. | 267 // With prototype. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 }; | 321 }; |
| 321 | 322 |
| 322 | 323 |
| 323 void Bootstrapper::Iterate(ObjectVisitor* v) { | 324 void Bootstrapper::Iterate(ObjectVisitor* v) { |
| 324 extensions_cache_.Iterate(v); | 325 extensions_cache_.Iterate(v); |
| 325 v->Synchronize(VisitorSynchronization::kExtensions); | 326 v->Synchronize(VisitorSynchronization::kExtensions); |
| 326 } | 327 } |
| 327 | 328 |
| 328 | 329 |
| 329 Handle<Context> Bootstrapper::CreateEnvironment( | 330 Handle<Context> Bootstrapper::CreateEnvironment( |
| 330 Handle<Object> global_object, | 331 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 331 v8::Handle<v8::ObjectTemplate> global_template, | 332 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 332 v8::ExtensionConfiguration* extensions) { | 333 v8::ExtensionConfiguration* extensions) { |
| 333 HandleScope scope(isolate_); | 334 HandleScope scope(isolate_); |
| 334 Genesis genesis(isolate_, global_object, global_template, extensions); | 335 Genesis genesis( |
| 336 isolate_, maybe_global_proxy, global_proxy_template, extensions); |
| 335 Handle<Context> env = genesis.result(); | 337 Handle<Context> env = genesis.result(); |
| 336 if (env.is_null() || !InstallExtensions(env, extensions)) { | 338 if (env.is_null() || !InstallExtensions(env, extensions)) { |
| 337 return Handle<Context>(); | 339 return Handle<Context>(); |
| 338 } | 340 } |
| 339 return scope.CloseAndEscape(env); | 341 return scope.CloseAndEscape(env); |
| 340 } | 342 } |
| 341 | 343 |
| 342 | 344 |
| 343 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 345 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
| 344 // object.__proto__ = proto; | 346 // object.__proto__ = proto; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 725 |
| 724 // Allocate the message listeners object. | 726 // Allocate the message listeners object. |
| 725 { | 727 { |
| 726 v8::NeanderArray listeners(isolate()); | 728 v8::NeanderArray listeners(isolate()); |
| 727 native_context()->set_message_listeners(*listeners.value()); | 729 native_context()->set_message_listeners(*listeners.value()); |
| 728 } | 730 } |
| 729 } | 731 } |
| 730 | 732 |
| 731 | 733 |
| 732 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 734 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| 733 v8::Handle<v8::ObjectTemplate> global_template, | 735 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 734 Handle<Object> global_object, | 736 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 735 Handle<GlobalObject>* inner_global_out) { | 737 Handle<GlobalObject>* global_object_out) { |
| 736 // The argument global_template aka data is an ObjectTemplateInfo. | 738 // The argument global_proxy_template aka data is an ObjectTemplateInfo. |
| 737 // It has a constructor pointer that points at global_constructor which is a | 739 // It has a constructor pointer that points at global_constructor which is a |
| 738 // FunctionTemplateInfo. | 740 // FunctionTemplateInfo. |
| 739 // The global_constructor is used to create or reinitialize the global_proxy. | 741 // The global_proxy_constructor is used to create or reinitialize the |
| 740 // The global_constructor also has a prototype_template pointer that points at | 742 // global_proxy. The global_proxy_constructor also has a prototype_template |
| 741 // js_global_template which is an ObjectTemplateInfo. | 743 // pointer that points at js_global_object_template which is an |
| 744 // ObjectTemplateInfo. |
| 742 // That in turn has a constructor pointer that points at | 745 // That in turn has a constructor pointer that points at |
| 743 // js_global_constructor which is a FunctionTemplateInfo. | 746 // js_global_object_constructor which is a FunctionTemplateInfo. |
| 744 // js_global_constructor is used to make js_global_function | 747 // js_global_object_constructor is used to make js_global_object_function |
| 745 // js_global_function is used to make the new inner_global. | 748 // js_global_object_function is used to make the new global_object. |
| 746 // | 749 // |
| 747 // --- G l o b a l --- | 750 // --- G l o b a l --- |
| 748 // Step 1: Create a fresh inner JSGlobalObject. | 751 // Step 1: Create a fresh JSGlobalObject. |
| 749 Handle<JSFunction> js_global_function; | 752 Handle<JSFunction> js_global_object_function; |
| 750 Handle<ObjectTemplateInfo> js_global_template; | 753 Handle<ObjectTemplateInfo> js_global_object_template; |
| 751 if (!global_template.IsEmpty()) { | 754 if (!global_proxy_template.IsEmpty()) { |
| 752 // Get prototype template of the global_template. | 755 // Get prototype template of the global_proxy_template. |
| 753 Handle<ObjectTemplateInfo> data = | 756 Handle<ObjectTemplateInfo> data = |
| 754 v8::Utils::OpenHandle(*global_template); | 757 v8::Utils::OpenHandle(*global_proxy_template); |
| 755 Handle<FunctionTemplateInfo> global_constructor = | 758 Handle<FunctionTemplateInfo> global_constructor = |
| 756 Handle<FunctionTemplateInfo>( | 759 Handle<FunctionTemplateInfo>( |
| 757 FunctionTemplateInfo::cast(data->constructor())); | 760 FunctionTemplateInfo::cast(data->constructor())); |
| 758 Handle<Object> proto_template(global_constructor->prototype_template(), | 761 Handle<Object> proto_template(global_constructor->prototype_template(), |
| 759 isolate()); | 762 isolate()); |
| 760 if (!proto_template->IsUndefined()) { | 763 if (!proto_template->IsUndefined()) { |
| 761 js_global_template = | 764 js_global_object_template = |
| 762 Handle<ObjectTemplateInfo>::cast(proto_template); | 765 Handle<ObjectTemplateInfo>::cast(proto_template); |
| 763 } | 766 } |
| 764 } | 767 } |
| 765 | 768 |
| 766 if (js_global_template.is_null()) { | 769 if (js_global_object_template.is_null()) { |
| 767 Handle<String> name = Handle<String>(heap()->empty_string()); | 770 Handle<String> name = Handle<String>(heap()->empty_string()); |
| 768 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( | 771 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
| 769 Builtins::kIllegal)); | 772 Builtins::kIllegal)); |
| 770 js_global_function = factory()->NewFunction( | 773 js_global_object_function = factory()->NewFunction( |
| 771 name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); | 774 name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); |
| 772 // Change the constructor property of the prototype of the | 775 // Change the constructor property of the prototype of the |
| 773 // hidden global function to refer to the Object function. | 776 // hidden global function to refer to the Object function. |
| 774 Handle<JSObject> prototype = | 777 Handle<JSObject> prototype = |
| 775 Handle<JSObject>( | 778 Handle<JSObject>( |
| 776 JSObject::cast(js_global_function->instance_prototype())); | 779 JSObject::cast(js_global_object_function->instance_prototype())); |
| 777 JSObject::SetOwnPropertyIgnoreAttributes( | 780 JSObject::SetOwnPropertyIgnoreAttributes( |
| 778 prototype, factory()->constructor_string(), | 781 prototype, factory()->constructor_string(), |
| 779 isolate()->object_function(), NONE).Check(); | 782 isolate()->object_function(), NONE).Check(); |
| 780 } else { | 783 } else { |
| 781 Handle<FunctionTemplateInfo> js_global_constructor( | 784 Handle<FunctionTemplateInfo> js_global_object_constructor( |
| 782 FunctionTemplateInfo::cast(js_global_template->constructor())); | 785 FunctionTemplateInfo::cast(js_global_object_template->constructor())); |
| 783 js_global_function = | 786 js_global_object_function = |
| 784 factory()->CreateApiFunction(js_global_constructor, | 787 factory()->CreateApiFunction(js_global_object_constructor, |
| 785 factory()->the_hole_value(), | 788 factory()->the_hole_value(), |
| 786 factory()->InnerGlobalObject); | 789 factory()->GlobalObjectType); |
| 787 } | 790 } |
| 788 | 791 |
| 789 js_global_function->initial_map()->set_is_hidden_prototype(); | 792 js_global_object_function->initial_map()->set_is_hidden_prototype(); |
| 790 js_global_function->initial_map()->set_dictionary_map(true); | 793 js_global_object_function->initial_map()->set_dictionary_map(true); |
| 791 Handle<GlobalObject> inner_global = | 794 Handle<GlobalObject> global_object = |
| 792 factory()->NewGlobalObject(js_global_function); | 795 factory()->NewGlobalObject(js_global_object_function); |
| 793 if (inner_global_out != NULL) { | 796 if (global_object_out != NULL) { |
| 794 *inner_global_out = inner_global; | 797 *global_object_out = global_object; |
| 795 } | 798 } |
| 796 | 799 |
| 797 // Step 2: create or re-initialize the global proxy object. | 800 // Step 2: create or re-initialize the global proxy object. |
| 798 Handle<JSFunction> global_proxy_function; | 801 Handle<JSFunction> global_proxy_function; |
| 799 if (global_template.IsEmpty()) { | 802 if (global_proxy_template.IsEmpty()) { |
| 800 Handle<String> name = Handle<String>(heap()->empty_string()); | 803 Handle<String> name = Handle<String>(heap()->empty_string()); |
| 801 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( | 804 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
| 802 Builtins::kIllegal)); | 805 Builtins::kIllegal)); |
| 803 global_proxy_function = factory()->NewFunction( | 806 global_proxy_function = factory()->NewFunction( |
| 804 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); | 807 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); |
| 805 } else { | 808 } else { |
| 806 Handle<ObjectTemplateInfo> data = | 809 Handle<ObjectTemplateInfo> data = |
| 807 v8::Utils::OpenHandle(*global_template); | 810 v8::Utils::OpenHandle(*global_proxy_template); |
| 808 Handle<FunctionTemplateInfo> global_constructor( | 811 Handle<FunctionTemplateInfo> global_constructor( |
| 809 FunctionTemplateInfo::cast(data->constructor())); | 812 FunctionTemplateInfo::cast(data->constructor())); |
| 810 global_proxy_function = | 813 global_proxy_function = |
| 811 factory()->CreateApiFunction(global_constructor, | 814 factory()->CreateApiFunction(global_constructor, |
| 812 factory()->the_hole_value(), | 815 factory()->the_hole_value(), |
| 813 factory()->OuterGlobalObject); | 816 factory()->GlobalProxyType); |
| 814 } | 817 } |
| 815 | 818 |
| 816 Handle<String> global_name = factory()->InternalizeOneByteString( | 819 Handle<String> global_name = factory()->InternalizeOneByteString( |
| 817 STATIC_ASCII_VECTOR("global")); | 820 STATIC_ASCII_VECTOR("global")); |
| 818 global_proxy_function->shared()->set_instance_class_name(*global_name); | 821 global_proxy_function->shared()->set_instance_class_name(*global_name); |
| 819 global_proxy_function->initial_map()->set_is_access_check_needed(true); | 822 global_proxy_function->initial_map()->set_is_access_check_needed(true); |
| 820 | 823 |
| 821 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects | 824 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects |
| 822 // Return the global proxy. | 825 // Return the global proxy. |
| 823 | 826 |
| 824 Handle<JSGlobalProxy> global_proxy; | 827 Handle<JSGlobalProxy> global_proxy; |
| 825 if (global_object.location() != NULL) { | 828 if (maybe_global_proxy.ToHandle(&global_proxy)) { |
| 826 ASSERT(global_object->IsJSGlobalProxy()); | |
| 827 global_proxy = Handle<JSGlobalProxy>::cast(global_object); | |
| 828 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 829 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
| 829 } else { | 830 } else { |
| 830 global_proxy = Handle<JSGlobalProxy>::cast( | 831 global_proxy = Handle<JSGlobalProxy>::cast( |
| 831 factory()->NewJSObject(global_proxy_function, TENURED)); | 832 factory()->NewJSObject(global_proxy_function, TENURED)); |
| 832 global_proxy->set_hash(heap()->undefined_value()); | 833 global_proxy->set_hash(heap()->undefined_value()); |
| 833 } | 834 } |
| 834 return global_proxy; | 835 return global_proxy; |
| 835 } | 836 } |
| 836 | 837 |
| 837 | 838 |
| 838 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 839 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> global_object, |
| 839 Handle<JSGlobalProxy> global_proxy) { | 840 Handle<JSGlobalProxy> global_proxy) { |
| 840 // Set the native context for the global object. | 841 // Set the native context for the global object. |
| 841 inner_global->set_native_context(*native_context()); | 842 global_object->set_native_context(*native_context()); |
| 842 inner_global->set_global_context(*native_context()); | 843 global_object->set_global_context(*native_context()); |
| 843 inner_global->set_global_receiver(*global_proxy); | 844 global_object->set_global_proxy(*global_proxy); |
| 844 global_proxy->set_native_context(*native_context()); | 845 global_proxy->set_native_context(*native_context()); |
| 845 native_context()->set_global_proxy(*global_proxy); | 846 native_context()->set_global_proxy(*global_proxy); |
| 846 } | 847 } |
| 847 | 848 |
| 848 | 849 |
| 849 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { | 850 void Genesis::HookUpGlobalObject(Handle<GlobalObject> global_object) { |
| 850 Handle<GlobalObject> inner_global_from_snapshot( | 851 Handle<GlobalObject> global_object_from_snapshot( |
| 851 GlobalObject::cast(native_context()->extension())); | 852 GlobalObject::cast(native_context()->extension())); |
| 852 Handle<JSBuiltinsObject> builtins_global(native_context()->builtins()); | 853 Handle<JSBuiltinsObject> builtins_global(native_context()->builtins()); |
| 853 native_context()->set_extension(*inner_global); | 854 native_context()->set_extension(*global_object); |
| 854 native_context()->set_global_object(*inner_global); | 855 native_context()->set_global_object(*global_object); |
| 855 native_context()->set_security_token(*inner_global); | 856 native_context()->set_security_token(*global_object); |
| 856 static const PropertyAttributes attributes = | 857 static const PropertyAttributes attributes = |
| 857 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 858 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 858 Runtime::DefineObjectProperty(builtins_global, | 859 Runtime::DefineObjectProperty(builtins_global, |
| 859 factory()->InternalizeOneByteString( | 860 factory()->InternalizeOneByteString( |
| 860 STATIC_ASCII_VECTOR("global")), | 861 STATIC_ASCII_VECTOR("global")), |
| 861 inner_global, | 862 global_object, |
| 862 attributes).Assert(); | 863 attributes).Assert(); |
| 863 // Set up the reference from the global object to the builtins object. | 864 // Set up the reference from the global object to the builtins object. |
| 864 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); | 865 JSGlobalObject::cast(*global_object)->set_builtins(*builtins_global); |
| 865 TransferNamedProperties(inner_global_from_snapshot, inner_global); | 866 TransferNamedProperties(global_object_from_snapshot, global_object); |
| 866 TransferIndexedProperties(inner_global_from_snapshot, inner_global); | 867 TransferIndexedProperties(global_object_from_snapshot, global_object); |
| 867 } | 868 } |
| 868 | 869 |
| 869 | 870 |
| 870 // This is only called if we are not using snapshots. The equivalent | 871 // This is only called if we are not using snapshots. The equivalent |
| 871 // work in the snapshot case is done in HookUpInnerGlobal. | 872 // work in the snapshot case is done in HookUpGlobalObject. |
| 872 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, | 873 void Genesis::InitializeGlobal(Handle<GlobalObject> global_object, |
| 873 Handle<JSFunction> empty_function) { | 874 Handle<JSFunction> empty_function) { |
| 874 // --- N a t i v e C o n t e x t --- | 875 // --- N a t i v e C o n t e x t --- |
| 875 // Use the empty function as closure (no scope info). | 876 // Use the empty function as closure (no scope info). |
| 876 native_context()->set_closure(*empty_function); | 877 native_context()->set_closure(*empty_function); |
| 877 native_context()->set_previous(NULL); | 878 native_context()->set_previous(NULL); |
| 878 // Set extension and global object. | 879 // Set extension and global object. |
| 879 native_context()->set_extension(*inner_global); | 880 native_context()->set_extension(*global_object); |
| 880 native_context()->set_global_object(*inner_global); | 881 native_context()->set_global_object(*global_object); |
| 881 // Security setup: Set the security token of the global object to | 882 // Security setup: Set the security token of the native context to the global |
| 882 // its the inner global. This makes the security check between two | 883 // object. This makes the security check between two different contexts fail |
| 883 // different contexts fail by default even in case of global | 884 // by default even in case of global object reinitialization. |
| 884 // object reinitialization. | 885 native_context()->set_security_token(*global_object); |
| 885 native_context()->set_security_token(*inner_global); | |
| 886 | 886 |
| 887 Isolate* isolate = inner_global->GetIsolate(); | 887 Isolate* isolate = global_object->GetIsolate(); |
| 888 Factory* factory = isolate->factory(); | 888 Factory* factory = isolate->factory(); |
| 889 Heap* heap = isolate->heap(); | 889 Heap* heap = isolate->heap(); |
| 890 | 890 |
| 891 Handle<String> object_name = factory->Object_string(); | 891 Handle<String> object_name = factory->Object_string(); |
| 892 JSObject::SetOwnPropertyIgnoreAttributes( | 892 JSObject::SetOwnPropertyIgnoreAttributes( |
| 893 inner_global, object_name, | 893 global_object, object_name, |
| 894 isolate->object_function(), DONT_ENUM).Check(); | 894 isolate->object_function(), DONT_ENUM).Check(); |
| 895 | 895 |
| 896 Handle<JSObject> global(native_context()->global_object()); | 896 Handle<JSObject> global(native_context()->global_object()); |
| 897 | 897 |
| 898 // Install global Function object | 898 // Install global Function object |
| 899 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 899 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 900 empty_function, Builtins::kIllegal); | 900 empty_function, Builtins::kIllegal); |
| 901 | 901 |
| 902 { // --- A r r a y --- | 902 { // --- A r r a y --- |
| 903 Handle<JSFunction> array_function = | 903 Handle<JSFunction> array_function = |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 builtins_fun->shared()->set_instance_class_name(*name); | 1716 builtins_fun->shared()->set_instance_class_name(*name); |
| 1717 builtins_fun->initial_map()->set_dictionary_map(true); | 1717 builtins_fun->initial_map()->set_dictionary_map(true); |
| 1718 builtins_fun->initial_map()->set_prototype(heap()->null_value()); | 1718 builtins_fun->initial_map()->set_prototype(heap()->null_value()); |
| 1719 | 1719 |
| 1720 // Allocate the builtins object. | 1720 // Allocate the builtins object. |
| 1721 Handle<JSBuiltinsObject> builtins = | 1721 Handle<JSBuiltinsObject> builtins = |
| 1722 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); | 1722 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); |
| 1723 builtins->set_builtins(*builtins); | 1723 builtins->set_builtins(*builtins); |
| 1724 builtins->set_native_context(*native_context()); | 1724 builtins->set_native_context(*native_context()); |
| 1725 builtins->set_global_context(*native_context()); | 1725 builtins->set_global_context(*native_context()); |
| 1726 builtins->set_global_receiver(*builtins); | 1726 builtins->set_global_proxy(native_context()->global_proxy()); |
| 1727 builtins->set_global_receiver(native_context()->global_proxy()); | |
| 1728 | 1727 |
| 1729 | 1728 |
| 1730 // Set up the 'global' properties of the builtins object. The | 1729 // Set up the 'global' properties of the builtins object. The |
| 1731 // 'global' property that refers to the global object is the only | 1730 // 'global' property that refers to the global object is the only |
| 1732 // way to get from code running in the builtins context to the | 1731 // way to get from code running in the builtins context to the |
| 1733 // global object. | 1732 // global object. |
| 1734 static const PropertyAttributes attributes = | 1733 static const PropertyAttributes attributes = |
| 1735 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1734 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 1736 Handle<String> global_string = | 1735 Handle<String> global_string = |
| 1737 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); | 1736 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 Handle<JSFunction> string_function(native_context()->string_function()); | 1931 Handle<JSFunction> string_function(native_context()->string_function()); |
| 1933 ASSERT(JSObject::cast( | 1932 ASSERT(JSObject::cast( |
| 1934 string_function->initial_map()->prototype())->HasFastProperties()); | 1933 string_function->initial_map()->prototype())->HasFastProperties()); |
| 1935 native_context()->set_string_function_prototype_map( | 1934 native_context()->set_string_function_prototype_map( |
| 1936 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 1935 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
| 1937 | 1936 |
| 1938 // Install Function.prototype.call and apply. | 1937 // Install Function.prototype.call and apply. |
| 1939 { Handle<String> key = factory()->function_class_string(); | 1938 { Handle<String> key = factory()->function_class_string(); |
| 1940 Handle<JSFunction> function = | 1939 Handle<JSFunction> function = |
| 1941 Handle<JSFunction>::cast(Object::GetProperty( | 1940 Handle<JSFunction>::cast(Object::GetProperty( |
| 1942 isolate()->global_object(), key).ToHandleChecked()); | 1941 handle(native_context()->global_object()), key).ToHandleChecked()); |
| 1943 Handle<JSObject> proto = | 1942 Handle<JSObject> proto = |
| 1944 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 1943 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 1945 | 1944 |
| 1946 // Install the call and the apply functions. | 1945 // Install the call and the apply functions. |
| 1947 Handle<JSFunction> call = | 1946 Handle<JSFunction> call = |
| 1948 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1947 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1949 MaybeHandle<JSObject>(), Builtins::kFunctionCall); | 1948 MaybeHandle<JSObject>(), Builtins::kFunctionCall); |
| 1950 Handle<JSFunction> apply = | 1949 Handle<JSFunction> apply = |
| 1951 InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1950 InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1952 MaybeHandle<JSObject>(), Builtins::kFunctionApply); | 1951 MaybeHandle<JSObject>(), Builtins::kFunctionApply); |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2385 builtins->set_javascript_builtin_code(id, function->shared()->code()); | 2384 builtins->set_javascript_builtin_code(id, function->shared()->code()); |
| 2386 } | 2385 } |
| 2387 return true; | 2386 return true; |
| 2388 } | 2387 } |
| 2389 | 2388 |
| 2390 | 2389 |
| 2391 bool Genesis::ConfigureGlobalObjects( | 2390 bool Genesis::ConfigureGlobalObjects( |
| 2392 v8::Handle<v8::ObjectTemplate> global_proxy_template) { | 2391 v8::Handle<v8::ObjectTemplate> global_proxy_template) { |
| 2393 Handle<JSObject> global_proxy( | 2392 Handle<JSObject> global_proxy( |
| 2394 JSObject::cast(native_context()->global_proxy())); | 2393 JSObject::cast(native_context()->global_proxy())); |
| 2395 Handle<JSObject> inner_global( | 2394 Handle<JSObject> global_object( |
| 2396 JSObject::cast(native_context()->global_object())); | 2395 JSObject::cast(native_context()->global_object())); |
| 2397 | 2396 |
| 2398 if (!global_proxy_template.IsEmpty()) { | 2397 if (!global_proxy_template.IsEmpty()) { |
| 2399 // Configure the global proxy object. | 2398 // Configure the global proxy object. |
| 2400 Handle<ObjectTemplateInfo> proxy_data = | 2399 Handle<ObjectTemplateInfo> global_proxy_data = |
| 2401 v8::Utils::OpenHandle(*global_proxy_template); | 2400 v8::Utils::OpenHandle(*global_proxy_template); |
| 2402 if (!ConfigureApiObject(global_proxy, proxy_data)) return false; | 2401 if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; |
| 2403 | 2402 |
| 2404 // Configure the inner global object. | 2403 // Configure the global object. |
| 2405 Handle<FunctionTemplateInfo> proxy_constructor( | 2404 Handle<FunctionTemplateInfo> proxy_constructor( |
| 2406 FunctionTemplateInfo::cast(proxy_data->constructor())); | 2405 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
| 2407 if (!proxy_constructor->prototype_template()->IsUndefined()) { | 2406 if (!proxy_constructor->prototype_template()->IsUndefined()) { |
| 2408 Handle<ObjectTemplateInfo> inner_data( | 2407 Handle<ObjectTemplateInfo> global_object_data( |
| 2409 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 2408 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
| 2410 if (!ConfigureApiObject(inner_global, inner_data)) return false; | 2409 if (!ConfigureApiObject(global_object, global_object_data)) return false; |
| 2411 } | 2410 } |
| 2412 } | 2411 } |
| 2413 | 2412 |
| 2414 SetObjectPrototype(global_proxy, inner_global); | 2413 SetObjectPrototype(global_proxy, global_object); |
| 2415 | 2414 |
| 2416 native_context()->set_initial_array_prototype( | 2415 native_context()->set_initial_array_prototype( |
| 2417 JSArray::cast(native_context()->array_function()->prototype())); | 2416 JSArray::cast(native_context()->array_function()->prototype())); |
| 2418 | 2417 |
| 2419 return true; | 2418 return true; |
| 2420 } | 2419 } |
| 2421 | 2420 |
| 2422 | 2421 |
| 2423 bool Genesis::ConfigureApiObject(Handle<JSObject> object, | 2422 bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
| 2424 Handle<ObjectTemplateInfo> object_template) { | 2423 Handle<ObjectTemplateInfo> object_template) { |
| 2425 ASSERT(!object_template.is_null()); | 2424 ASSERT(!object_template.is_null()); |
| 2426 ASSERT(FunctionTemplateInfo::cast(object_template->constructor()) | 2425 ASSERT(FunctionTemplateInfo::cast(object_template->constructor()) |
| 2427 ->IsTemplateFor(object->map()));; | 2426 ->IsTemplateFor(object->map()));; |
| 2428 | 2427 |
| 2429 MaybeHandle<JSObject> maybe_obj = | 2428 MaybeHandle<JSObject> maybe_obj = |
| 2430 Execution::InstantiateObject(object_template); | 2429 Execution::InstantiateObject(object_template); |
| 2431 Handle<JSObject> obj; | 2430 Handle<JSObject> obj; |
| 2432 if (!maybe_obj.ToHandle(&obj)) { | 2431 if (!maybe_obj.ToHandle(&obj)) { |
| 2433 ASSERT(isolate()->has_pending_exception()); | 2432 ASSERT(isolate()->has_pending_exception()); |
| 2434 isolate()->clear_pending_exception(); | 2433 isolate()->clear_pending_exception(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 ~NoTrackDoubleFieldsForSerializerScope() { | 2574 ~NoTrackDoubleFieldsForSerializerScope() { |
| 2576 FLAG_track_double_fields = flag_; | 2575 FLAG_track_double_fields = flag_; |
| 2577 } | 2576 } |
| 2578 | 2577 |
| 2579 private: | 2578 private: |
| 2580 bool flag_; | 2579 bool flag_; |
| 2581 }; | 2580 }; |
| 2582 | 2581 |
| 2583 | 2582 |
| 2584 Genesis::Genesis(Isolate* isolate, | 2583 Genesis::Genesis(Isolate* isolate, |
| 2585 Handle<Object> global_object, | 2584 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
| 2586 v8::Handle<v8::ObjectTemplate> global_template, | 2585 v8::Handle<v8::ObjectTemplate> global_proxy_template, |
| 2587 v8::ExtensionConfiguration* extensions) | 2586 v8::ExtensionConfiguration* extensions) |
| 2588 : isolate_(isolate), | 2587 : isolate_(isolate), |
| 2589 active_(isolate->bootstrapper()) { | 2588 active_(isolate->bootstrapper()) { |
| 2590 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); | 2589 NoTrackDoubleFieldsForSerializerScope disable_scope(isolate); |
| 2591 result_ = Handle<Context>::null(); | 2590 result_ = Handle<Context>::null(); |
| 2592 // If V8 cannot be initialized, just return. | 2591 // If V8 cannot be initialized, just return. |
| 2593 if (!V8::Initialize(NULL)) return; | 2592 if (!V8::Initialize(NULL)) return; |
| 2594 | 2593 |
| 2595 // Before creating the roots we must save the context and restore it | 2594 // Before creating the roots we must save the context and restore it |
| 2596 // on all function exits. | 2595 // on all function exits. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2607 if (isolate->initialized_from_snapshot()) { | 2606 if (isolate->initialized_from_snapshot()) { |
| 2608 native_context_ = Snapshot::NewContextFromSnapshot(isolate); | 2607 native_context_ = Snapshot::NewContextFromSnapshot(isolate); |
| 2609 } else { | 2608 } else { |
| 2610 native_context_ = Handle<Context>(); | 2609 native_context_ = Handle<Context>(); |
| 2611 } | 2610 } |
| 2612 | 2611 |
| 2613 if (!native_context().is_null()) { | 2612 if (!native_context().is_null()) { |
| 2614 AddToWeakNativeContextList(*native_context()); | 2613 AddToWeakNativeContextList(*native_context()); |
| 2615 isolate->set_context(*native_context()); | 2614 isolate->set_context(*native_context()); |
| 2616 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 2615 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
| 2617 Handle<GlobalObject> inner_global; | 2616 Handle<GlobalObject> global_object; |
| 2618 Handle<JSGlobalProxy> global_proxy = | 2617 Handle<JSGlobalProxy> global_proxy = CreateNewGlobals( |
| 2619 CreateNewGlobals(global_template, | 2618 global_proxy_template, maybe_global_proxy, &global_object); |
| 2620 global_object, | |
| 2621 &inner_global); | |
| 2622 | 2619 |
| 2623 HookUpGlobalProxy(inner_global, global_proxy); | 2620 HookUpGlobalProxy(global_object, global_proxy); |
| 2624 HookUpInnerGlobal(inner_global); | 2621 HookUpGlobalObject(global_object); |
| 2625 native_context()->builtins()->set_global_receiver( | 2622 native_context()->builtins()->set_global_proxy( |
| 2626 native_context()->global_proxy()); | 2623 native_context()->global_proxy()); |
| 2627 | 2624 |
| 2628 if (!ConfigureGlobalObjects(global_template)) return; | 2625 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
| 2629 } else { | 2626 } else { |
| 2630 // We get here if there was no context snapshot. | 2627 // We get here if there was no context snapshot. |
| 2631 CreateRoots(); | 2628 CreateRoots(); |
| 2632 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 2629 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
| 2633 CreateStrictModeFunctionMaps(empty_function); | 2630 CreateStrictModeFunctionMaps(empty_function); |
| 2634 Handle<GlobalObject> inner_global; | 2631 Handle<GlobalObject> global_object; |
| 2635 Handle<JSGlobalProxy> global_proxy = | 2632 Handle<JSGlobalProxy> global_proxy = CreateNewGlobals( |
| 2636 CreateNewGlobals(global_template, global_object, &inner_global); | 2633 global_proxy_template, maybe_global_proxy, &global_object); |
| 2637 HookUpGlobalProxy(inner_global, global_proxy); | 2634 HookUpGlobalProxy(global_object, global_proxy); |
| 2638 InitializeGlobal(inner_global, empty_function); | 2635 InitializeGlobal(global_object, empty_function); |
| 2639 InstallJSFunctionResultCaches(); | 2636 InstallJSFunctionResultCaches(); |
| 2640 InitializeNormalizedMapCaches(); | 2637 InitializeNormalizedMapCaches(); |
| 2641 if (!InstallNatives()) return; | 2638 if (!InstallNatives()) return; |
| 2642 | 2639 |
| 2643 MakeFunctionInstancePrototypeWritable(); | 2640 MakeFunctionInstancePrototypeWritable(); |
| 2644 | 2641 |
| 2645 if (!ConfigureGlobalObjects(global_template)) return; | 2642 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
| 2646 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2643 isolate->counters()->contexts_created_from_scratch()->Increment(); |
| 2647 } | 2644 } |
| 2648 | 2645 |
| 2649 // Initialize experimental globals and install experimental natives. | 2646 // Initialize experimental globals and install experimental natives. |
| 2650 InitializeExperimentalGlobal(); | 2647 InitializeExperimentalGlobal(); |
| 2651 if (!InstallExperimentalNatives()) return; | 2648 if (!InstallExperimentalNatives()) return; |
| 2652 | 2649 |
| 2653 // We can't (de-)serialize typed arrays currently, but we are lucky: The state | 2650 // We can't (de-)serialize typed arrays currently, but we are lucky: The state |
| 2654 // of the random number generator needs no initialization during snapshot | 2651 // of the random number generator needs no initialization during snapshot |
| 2655 // creation time and we don't need trigonometric functions then. | 2652 // creation time and we don't need trigonometric functions then. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2741 return from + sizeof(NestingCounterType); | 2738 return from + sizeof(NestingCounterType); |
| 2742 } | 2739 } |
| 2743 | 2740 |
| 2744 | 2741 |
| 2745 // Called when the top-level V8 mutex is destroyed. | 2742 // Called when the top-level V8 mutex is destroyed. |
| 2746 void Bootstrapper::FreeThreadResources() { | 2743 void Bootstrapper::FreeThreadResources() { |
| 2747 ASSERT(!IsActive()); | 2744 ASSERT(!IsActive()); |
| 2748 } | 2745 } |
| 2749 | 2746 |
| 2750 } } // namespace v8::internal | 2747 } } // namespace v8::internal |
| OLD | NEW |