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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 Handle<JSGlobalProxy> Bootstrapper::NewRemoteContext( | 346 Handle<JSGlobalProxy> Bootstrapper::NewRemoteContext( |
347 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 347 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
348 v8::Local<v8::ObjectTemplate> global_proxy_template) { | 348 v8::Local<v8::ObjectTemplate> global_proxy_template) { |
349 HandleScope scope(isolate_); | 349 HandleScope scope(isolate_); |
350 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template); | 350 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template); |
351 Handle<JSGlobalProxy> global_proxy = genesis.global_proxy(); | 351 Handle<JSGlobalProxy> global_proxy = genesis.global_proxy(); |
352 if (global_proxy.is_null()) return Handle<JSGlobalProxy>(); | 352 if (global_proxy.is_null()) return Handle<JSGlobalProxy>(); |
353 return scope.CloseAndEscape(global_proxy); | 353 return scope.CloseAndEscape(global_proxy); |
354 } | 354 } |
355 | 355 |
356 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | |
357 // object.__proto__ = proto; | |
358 Handle<Map> old_map = Handle<Map>(object->map()); | |
359 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); | |
360 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); | |
361 JSObject::MigrateToMap(object, new_map); | |
362 } | |
363 | |
364 | |
365 void Bootstrapper::DetachGlobal(Handle<Context> env) { | 356 void Bootstrapper::DetachGlobal(Handle<Context> env) { |
366 env->GetIsolate()->counters()->errors_thrown_per_context()->AddSample( | 357 env->GetIsolate()->counters()->errors_thrown_per_context()->AddSample( |
367 env->GetErrorsThrown()); | 358 env->GetErrorsThrown()); |
368 | 359 |
369 Factory* factory = env->GetIsolate()->factory(); | 360 Factory* factory = env->GetIsolate()->factory(); |
370 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); | 361 Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy())); |
371 global_proxy->set_native_context(*factory->null_value()); | 362 global_proxy->set_native_context(*factory->null_value()); |
372 SetObjectPrototype(global_proxy, factory->null_value()); | 363 JSObject::ForceSetPrototype(global_proxy, factory->null_value()); |
373 global_proxy->map()->SetConstructor(*factory->null_value()); | 364 global_proxy->map()->SetConstructor(*factory->null_value()); |
374 if (FLAG_track_detached_contexts) { | 365 if (FLAG_track_detached_contexts) { |
375 env->GetIsolate()->AddDetachedContext(env); | 366 env->GetIsolate()->AddDetachedContext(env); |
376 } | 367 } |
377 } | 368 } |
378 | 369 |
379 namespace { | 370 namespace { |
380 | 371 |
381 void InstallFunction(Handle<JSObject> target, Handle<Name> property_name, | 372 void InstallFunction(Handle<JSObject> target, Handle<Name> property_name, |
382 Handle<JSFunction> function, Handle<String> function_name, | 373 Handle<JSFunction> function, Handle<String> function_name, |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 } | 787 } |
797 | 788 |
798 void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) { | 789 void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) { |
799 // Create iterator-related meta-objects. | 790 // Create iterator-related meta-objects. |
800 Handle<JSObject> iterator_prototype = | 791 Handle<JSObject> iterator_prototype = |
801 factory()->NewJSObject(isolate()->object_function(), TENURED); | 792 factory()->NewJSObject(isolate()->object_function(), TENURED); |
802 Handle<JSObject> generator_object_prototype = | 793 Handle<JSObject> generator_object_prototype = |
803 factory()->NewJSObject(isolate()->object_function(), TENURED); | 794 factory()->NewJSObject(isolate()->object_function(), TENURED); |
804 native_context()->set_initial_generator_prototype( | 795 native_context()->set_initial_generator_prototype( |
805 *generator_object_prototype); | 796 *generator_object_prototype); |
806 SetObjectPrototype(generator_object_prototype, iterator_prototype); | 797 JSObject::ForceSetPrototype(generator_object_prototype, iterator_prototype); |
807 Handle<JSObject> generator_function_prototype = | 798 Handle<JSObject> generator_function_prototype = |
808 factory()->NewJSObject(isolate()->object_function(), TENURED); | 799 factory()->NewJSObject(isolate()->object_function(), TENURED); |
809 SetObjectPrototype(generator_function_prototype, empty); | 800 JSObject::ForceSetPrototype(generator_function_prototype, empty); |
810 | 801 |
811 JSObject::AddProperty( | 802 JSObject::AddProperty( |
812 generator_function_prototype, factory()->to_string_tag_symbol(), | 803 generator_function_prototype, factory()->to_string_tag_symbol(), |
813 factory()->NewStringFromAsciiChecked("GeneratorFunction"), | 804 factory()->NewStringFromAsciiChecked("GeneratorFunction"), |
814 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 805 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
815 JSObject::AddProperty(generator_function_prototype, | 806 JSObject::AddProperty(generator_function_prototype, |
816 factory()->prototype_string(), | 807 factory()->prototype_string(), |
817 generator_object_prototype, | 808 generator_object_prototype, |
818 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 809 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
819 | 810 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); | 849 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); |
859 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); | 850 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); |
860 native_context()->set_generator_object_prototype_map( | 851 native_context()->set_generator_object_prototype_map( |
861 *generator_object_prototype_map); | 852 *generator_object_prototype_map); |
862 } | 853 } |
863 | 854 |
864 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) { | 855 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) { |
865 // %AsyncFunctionPrototype% intrinsic | 856 // %AsyncFunctionPrototype% intrinsic |
866 Handle<JSObject> async_function_prototype = | 857 Handle<JSObject> async_function_prototype = |
867 factory()->NewJSObject(isolate()->object_function(), TENURED); | 858 factory()->NewJSObject(isolate()->object_function(), TENURED); |
868 SetObjectPrototype(async_function_prototype, empty); | 859 JSObject::ForceSetPrototype(async_function_prototype, empty); |
869 | 860 |
870 JSObject::AddProperty(async_function_prototype, | 861 JSObject::AddProperty(async_function_prototype, |
871 factory()->to_string_tag_symbol(), | 862 factory()->to_string_tag_symbol(), |
872 factory()->NewStringFromAsciiChecked("AsyncFunction"), | 863 factory()->NewStringFromAsciiChecked("AsyncFunction"), |
873 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 864 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
874 | 865 |
875 Handle<Map> strict_function_map( | 866 Handle<Map> strict_function_map( |
876 native_context()->strict_function_without_prototype_map()); | 867 native_context()->strict_function_without_prototype_map()); |
877 Handle<Map> sloppy_async_function_map = | 868 Handle<Map> sloppy_async_function_map = |
878 Map::Copy(strict_function_map, "SloppyAsyncFunction"); | 869 Map::Copy(strict_function_map, "SloppyAsyncFunction"); |
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 generator_function_function->set_prototype_or_initial_map( | 2506 generator_function_function->set_prototype_or_initial_map( |
2516 native_context->sloppy_generator_function_map()); | 2507 native_context->sloppy_generator_function_map()); |
2517 generator_function_function->shared()->DontAdaptArguments(); | 2508 generator_function_function->shared()->DontAdaptArguments(); |
2518 generator_function_function->shared()->SetConstructStub( | 2509 generator_function_function->shared()->SetConstructStub( |
2519 *isolate->builtins()->GeneratorFunctionConstructor()); | 2510 *isolate->builtins()->GeneratorFunctionConstructor()); |
2520 generator_function_function->shared()->set_length(1); | 2511 generator_function_function->shared()->set_length(1); |
2521 InstallWithIntrinsicDefaultProto( | 2512 InstallWithIntrinsicDefaultProto( |
2522 isolate, generator_function_function, | 2513 isolate, generator_function_function, |
2523 Context::GENERATOR_FUNCTION_FUNCTION_INDEX); | 2514 Context::GENERATOR_FUNCTION_FUNCTION_INDEX); |
2524 | 2515 |
2525 SetObjectPrototype(generator_function_function, | 2516 JSObject::ForceSetPrototype(generator_function_function, |
2526 isolate->function_function()); | 2517 isolate->function_function()); |
2527 JSObject::AddProperty( | 2518 JSObject::AddProperty( |
2528 generator_function_prototype, factory->constructor_string(), | 2519 generator_function_prototype, factory->constructor_string(), |
2529 generator_function_function, | 2520 generator_function_function, |
2530 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 2521 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
2531 | 2522 |
2532 native_context->sloppy_generator_function_map()->SetConstructor( | 2523 native_context->sloppy_generator_function_map()->SetConstructor( |
2533 *generator_function_function); | 2524 *generator_function_function); |
2534 native_context->strict_generator_function_map()->SetConstructor( | 2525 native_context->strict_generator_function_map()->SetConstructor( |
2535 *generator_function_function); | 2526 *generator_function_function); |
2536 } | 2527 } |
2537 | 2528 |
2538 { // -- S e t I t e r a t o r | 2529 { // -- S e t I t e r a t o r |
2539 Handle<JSObject> set_iterator_prototype = | 2530 Handle<JSObject> set_iterator_prototype = |
2540 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); | 2531 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |
2541 SetObjectPrototype(set_iterator_prototype, iterator_prototype); | 2532 JSObject::ForceSetPrototype(set_iterator_prototype, iterator_prototype); |
2542 Handle<JSFunction> set_iterator_function = InstallFunction( | 2533 Handle<JSFunction> set_iterator_function = InstallFunction( |
2543 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, | 2534 container, "SetIterator", JS_SET_ITERATOR_TYPE, JSSetIterator::kSize, |
2544 set_iterator_prototype, Builtins::kIllegal); | 2535 set_iterator_prototype, Builtins::kIllegal); |
2545 native_context->set_set_iterator_map(set_iterator_function->initial_map()); | 2536 native_context->set_set_iterator_map(set_iterator_function->initial_map()); |
2546 } | 2537 } |
2547 | 2538 |
2548 { // -- M a p I t e r a t o r | 2539 { // -- M a p I t e r a t o r |
2549 Handle<JSObject> map_iterator_prototype = | 2540 Handle<JSObject> map_iterator_prototype = |
2550 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); | 2541 isolate->factory()->NewJSObject(isolate->object_function(), TENURED); |
2551 SetObjectPrototype(map_iterator_prototype, iterator_prototype); | 2542 JSObject::ForceSetPrototype(map_iterator_prototype, iterator_prototype); |
2552 Handle<JSFunction> map_iterator_function = InstallFunction( | 2543 Handle<JSFunction> map_iterator_function = InstallFunction( |
2553 container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, | 2544 container, "MapIterator", JS_MAP_ITERATOR_TYPE, JSMapIterator::kSize, |
2554 map_iterator_prototype, Builtins::kIllegal); | 2545 map_iterator_prototype, Builtins::kIllegal); |
2555 native_context->set_map_iterator_map(map_iterator_function->initial_map()); | 2546 native_context->set_map_iterator_map(map_iterator_function->initial_map()); |
2556 } | 2547 } |
2557 | 2548 |
2558 { // -- S c r i p t | 2549 { // -- S c r i p t |
2559 // Builtin functions for Script. | 2550 // Builtin functions for Script. |
2560 Handle<JSFunction> script_fun = InstallFunction( | 2551 Handle<JSFunction> script_fun = InstallFunction( |
2561 container, "Script", JS_VALUE_TYPE, JSValue::kSize, | 2552 container, "Script", JS_VALUE_TYPE, JSValue::kSize, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2710 Handle<JSFunction> async_function_constructor = InstallFunction( | 2701 Handle<JSFunction> async_function_constructor = InstallFunction( |
2711 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize, | 2702 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize, |
2712 async_function_prototype, Builtins::kAsyncFunctionConstructor, | 2703 async_function_prototype, Builtins::kAsyncFunctionConstructor, |
2713 kUseStrictFunctionMap); | 2704 kUseStrictFunctionMap); |
2714 async_function_constructor->shared()->DontAdaptArguments(); | 2705 async_function_constructor->shared()->DontAdaptArguments(); |
2715 async_function_constructor->shared()->SetConstructStub( | 2706 async_function_constructor->shared()->SetConstructStub( |
2716 *isolate->builtins()->AsyncFunctionConstructor()); | 2707 *isolate->builtins()->AsyncFunctionConstructor()); |
2717 async_function_constructor->shared()->set_length(1); | 2708 async_function_constructor->shared()->set_length(1); |
2718 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor, | 2709 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor, |
2719 Context::ASYNC_FUNCTION_FUNCTION_INDEX); | 2710 Context::ASYNC_FUNCTION_FUNCTION_INDEX); |
2720 SetObjectPrototype(async_function_constructor, | 2711 JSObject::ForceSetPrototype(async_function_constructor, |
2721 isolate->function_function()); | 2712 isolate->function_function()); |
2722 | 2713 |
2723 JSObject::AddProperty( | 2714 JSObject::AddProperty( |
2724 async_function_prototype, factory->constructor_string(), | 2715 async_function_prototype, factory->constructor_string(), |
2725 async_function_constructor, | 2716 async_function_constructor, |
2726 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); | 2717 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); |
2727 | 2718 |
2728 JSFunction::SetPrototype(async_function_constructor, | 2719 JSFunction::SetPrototype(async_function_constructor, |
2729 async_function_prototype); | 2720 async_function_prototype); |
2730 | 2721 |
2731 Handle<JSFunction> async_function_next = | 2722 Handle<JSFunction> async_function_next = |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3695 // Configure the global object. | 3686 // Configure the global object. |
3696 Handle<FunctionTemplateInfo> proxy_constructor( | 3687 Handle<FunctionTemplateInfo> proxy_constructor( |
3697 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 3688 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
3698 if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) { | 3689 if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) { |
3699 Handle<ObjectTemplateInfo> global_object_data( | 3690 Handle<ObjectTemplateInfo> global_object_data( |
3700 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 3691 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
3701 if (!ConfigureApiObject(global_object, global_object_data)) return false; | 3692 if (!ConfigureApiObject(global_object, global_object_data)) return false; |
3702 } | 3693 } |
3703 } | 3694 } |
3704 | 3695 |
3705 SetObjectPrototype(global_proxy, global_object); | 3696 JSObject::ForceSetPrototype(global_proxy, global_object); |
3706 | 3697 |
3707 native_context()->set_initial_array_prototype( | 3698 native_context()->set_initial_array_prototype( |
3708 JSArray::cast(native_context()->array_function()->prototype())); | 3699 JSArray::cast(native_context()->array_function()->prototype())); |
3709 native_context()->set_array_buffer_map( | 3700 native_context()->set_array_buffer_map( |
3710 native_context()->array_buffer_fun()->initial_map()); | 3701 native_context()->array_buffer_fun()->initial_map()); |
3711 native_context()->set_js_map_map( | 3702 native_context()->set_js_map_map( |
3712 native_context()->js_map_fun()->initial_map()); | 3703 native_context()->js_map_fun()->initial_map()); |
3713 native_context()->set_js_set_map( | 3704 native_context()->set_js_set_map( |
3714 native_context()->js_set_fun()->initial_map()); | 3705 native_context()->js_set_fun()->initial_map()); |
3715 | 3706 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3849 HandleScope outer(isolate()); | 3840 HandleScope outer(isolate()); |
3850 | 3841 |
3851 DCHECK(!from->IsJSArray()); | 3842 DCHECK(!from->IsJSArray()); |
3852 DCHECK(!to->IsJSArray()); | 3843 DCHECK(!to->IsJSArray()); |
3853 | 3844 |
3854 TransferNamedProperties(from, to); | 3845 TransferNamedProperties(from, to); |
3855 TransferIndexedProperties(from, to); | 3846 TransferIndexedProperties(from, to); |
3856 | 3847 |
3857 // Transfer the prototype (new map is needed). | 3848 // Transfer the prototype (new map is needed). |
3858 Handle<Object> proto(from->map()->prototype(), isolate()); | 3849 Handle<Object> proto(from->map()->prototype(), isolate()); |
3859 SetObjectPrototype(to, proto); | 3850 JSObject::ForceSetPrototype(to, proto); |
3860 } | 3851 } |
3861 | 3852 |
3862 | 3853 |
3863 void Genesis::MakeFunctionInstancePrototypeWritable() { | 3854 void Genesis::MakeFunctionInstancePrototypeWritable() { |
3864 // The maps with writable prototype are created in CreateEmptyFunction | 3855 // The maps with writable prototype are created in CreateEmptyFunction |
3865 // and CreateStrictModeFunctionMaps respectively. Initially the maps are | 3856 // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
3866 // created with read-only prototype for JS builtins processing. | 3857 // created with read-only prototype for JS builtins processing. |
3867 DCHECK(!sloppy_function_map_writable_prototype_.is_null()); | 3858 DCHECK(!sloppy_function_map_writable_prototype_.is_null()); |
3868 DCHECK(!strict_function_map_writable_prototype_.is_null()); | 3859 DCHECK(!strict_function_map_writable_prototype_.is_null()); |
3869 | 3860 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4066 global_proxy_map->set_has_hidden_prototype(true); | 4057 global_proxy_map->set_has_hidden_prototype(true); |
4067 | 4058 |
4068 Handle<String> global_name = factory()->global_string(); | 4059 Handle<String> global_name = factory()->global_string(); |
4069 global_proxy_function->shared()->set_instance_class_name(*global_name); | 4060 global_proxy_function->shared()->set_instance_class_name(*global_name); |
4070 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 4061 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
4071 | 4062 |
4072 // HookUpGlobalProxy. | 4063 // HookUpGlobalProxy. |
4073 global_proxy->set_native_context(*factory()->null_value()); | 4064 global_proxy->set_native_context(*factory()->null_value()); |
4074 | 4065 |
4075 // DetachGlobal. | 4066 // DetachGlobal. |
4076 SetObjectPrototype(global_proxy, factory()->null_value()); | 4067 JSObject::ForceSetPrototype(global_proxy, factory()->null_value()); |
4077 | 4068 |
4078 global_proxy_ = global_proxy; | 4069 global_proxy_ = global_proxy; |
4079 } | 4070 } |
4080 | 4071 |
4081 // Support for thread preemption. | 4072 // Support for thread preemption. |
4082 | 4073 |
4083 // Reserve space for statics needing saving and restoring. | 4074 // Reserve space for statics needing saving and restoring. |
4084 int Bootstrapper::ArchiveSpacePerThread() { | 4075 int Bootstrapper::ArchiveSpacePerThread() { |
4085 return sizeof(NestingCounterType); | 4076 return sizeof(NestingCounterType); |
4086 } | 4077 } |
(...skipping 14 matching lines...) Expand all Loading... |
4101 } | 4092 } |
4102 | 4093 |
4103 | 4094 |
4104 // Called when the top-level V8 mutex is destroyed. | 4095 // Called when the top-level V8 mutex is destroyed. |
4105 void Bootstrapper::FreeThreadResources() { | 4096 void Bootstrapper::FreeThreadResources() { |
4106 DCHECK(!IsActive()); | 4097 DCHECK(!IsActive()); |
4107 } | 4098 } |
4108 | 4099 |
4109 } // namespace internal | 4100 } // namespace internal |
4110 } // namespace v8 | 4101 } // namespace v8 |
OLD | NEW |