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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 isolate()); | 1005 isolate()); |
1006 if (!proto_template->IsUndefined(isolate())) { | 1006 if (!proto_template->IsUndefined(isolate())) { |
1007 js_global_object_template = | 1007 js_global_object_template = |
1008 Handle<ObjectTemplateInfo>::cast(proto_template); | 1008 Handle<ObjectTemplateInfo>::cast(proto_template); |
1009 } | 1009 } |
1010 } | 1010 } |
1011 | 1011 |
1012 if (js_global_object_template.is_null()) { | 1012 if (js_global_object_template.is_null()) { |
1013 Handle<String> name = Handle<String>(heap()->empty_string()); | 1013 Handle<String> name = Handle<String>(heap()->empty_string()); |
1014 Handle<Code> code = isolate()->builtins()->Illegal(); | 1014 Handle<Code> code = isolate()->builtins()->Illegal(); |
| 1015 Handle<JSObject> prototype = |
| 1016 factory()->NewFunctionPrototype(isolate()->object_function()); |
1015 js_global_object_function = factory()->NewFunction( | 1017 js_global_object_function = factory()->NewFunction( |
1016 name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); | 1018 name, code, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); |
| 1019 #ifdef DEBUG |
| 1020 LookupIterator it(prototype, factory()->constructor_string(), |
| 1021 LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 1022 Handle<Object> value = Object::GetProperty(&it).ToHandleChecked(); |
| 1023 DCHECK(it.IsFound()); |
| 1024 DCHECK_EQ(*isolate()->object_function(), *value); |
| 1025 #endif |
1017 } else { | 1026 } else { |
1018 Handle<FunctionTemplateInfo> js_global_object_constructor( | 1027 Handle<FunctionTemplateInfo> js_global_object_constructor( |
1019 FunctionTemplateInfo::cast(js_global_object_template->constructor())); | 1028 FunctionTemplateInfo::cast(js_global_object_template->constructor())); |
1020 js_global_object_function = ApiNatives::CreateApiFunction( | 1029 js_global_object_function = ApiNatives::CreateApiFunction( |
1021 isolate(), js_global_object_constructor, JS_GLOBAL_OBJECT_TYPE); | 1030 isolate(), js_global_object_constructor, factory()->the_hole_value(), |
| 1031 ApiNatives::GlobalObjectType); |
1022 } | 1032 } |
1023 | 1033 |
1024 js_global_object_function->initial_map()->set_is_prototype_map(true); | 1034 js_global_object_function->initial_map()->set_is_prototype_map(true); |
1025 js_global_object_function->initial_map()->set_dictionary_map(true); | 1035 js_global_object_function->initial_map()->set_dictionary_map(true); |
1026 Handle<JSGlobalObject> global_object = | 1036 Handle<JSGlobalObject> global_object = |
1027 factory()->NewJSGlobalObject(js_global_object_function); | 1037 factory()->NewJSGlobalObject(js_global_object_function); |
1028 | 1038 |
1029 // Step 2: (re)initialize the global proxy object. | 1039 // Step 2: (re)initialize the global proxy object. |
1030 Handle<JSFunction> global_proxy_function; | 1040 Handle<JSFunction> global_proxy_function; |
1031 if (global_proxy_template.IsEmpty()) { | 1041 if (global_proxy_template.IsEmpty()) { |
1032 Handle<String> name = Handle<String>(heap()->empty_string()); | 1042 Handle<String> name = Handle<String>(heap()->empty_string()); |
1033 Handle<Code> code = isolate()->builtins()->Illegal(); | 1043 Handle<Code> code = isolate()->builtins()->Illegal(); |
1034 global_proxy_function = factory()->NewFunction( | 1044 global_proxy_function = factory()->NewFunction( |
1035 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); | 1045 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); |
1036 } else { | 1046 } else { |
1037 Handle<ObjectTemplateInfo> data = | 1047 Handle<ObjectTemplateInfo> data = |
1038 v8::Utils::OpenHandle(*global_proxy_template); | 1048 v8::Utils::OpenHandle(*global_proxy_template); |
1039 Handle<FunctionTemplateInfo> global_constructor( | 1049 Handle<FunctionTemplateInfo> global_constructor( |
1040 FunctionTemplateInfo::cast(data->constructor())); | 1050 FunctionTemplateInfo::cast(data->constructor())); |
1041 global_proxy_function = ApiNatives::CreateApiFunction( | 1051 global_proxy_function = ApiNatives::CreateApiFunction( |
1042 isolate(), global_constructor, JS_GLOBAL_PROXY_TYPE); | 1052 isolate(), global_constructor, factory()->the_hole_value(), |
| 1053 ApiNatives::GlobalProxyType); |
1043 } | 1054 } |
1044 Handle<String> global_name = factory()->global_string(); | 1055 Handle<String> global_name = factory()->global_string(); |
1045 global_proxy_function->shared()->set_instance_class_name(*global_name); | 1056 global_proxy_function->shared()->set_instance_class_name(*global_name); |
1046 global_proxy_function->initial_map()->set_is_access_check_needed(true); | 1057 global_proxy_function->initial_map()->set_is_access_check_needed(true); |
1047 global_proxy_function->initial_map()->set_has_hidden_prototype(true); | 1058 global_proxy_function->initial_map()->set_has_hidden_prototype(true); |
1048 | 1059 |
1049 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects | 1060 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects |
1050 // Return the global proxy. | 1061 // Return the global proxy. |
1051 | 1062 |
1052 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 1063 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2905 | 2916 |
2906 // A thin context is ready at this point. | 2917 // A thin context is ready at this point. |
2907 if (context_type == THIN_CONTEXT) return true; | 2918 if (context_type == THIN_CONTEXT) return true; |
2908 | 2919 |
2909 { | 2920 { |
2910 // Builtin function for OpaqueReference -- a JSValue-based object, | 2921 // Builtin function for OpaqueReference -- a JSValue-based object, |
2911 // that keeps its field isolated from JavaScript code. It may store | 2922 // that keeps its field isolated from JavaScript code. It may store |
2912 // objects, that JavaScript code may not access. | 2923 // objects, that JavaScript code may not access. |
2913 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( | 2924 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( |
2914 factory()->empty_string(), isolate()->builtins()->Illegal(), | 2925 factory()->empty_string(), isolate()->builtins()->Illegal(), |
2915 JS_VALUE_TYPE, JSValue::kSize); | 2926 isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); |
2916 Handle<JSObject> prototype = | 2927 Handle<JSObject> prototype = |
2917 factory()->NewJSObject(isolate()->object_function(), TENURED); | 2928 factory()->NewJSObject(isolate()->object_function(), TENURED); |
2918 JSFunction::SetPrototype(opaque_reference_fun, prototype); | 2929 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); |
2919 native_context()->set_opaque_reference_function(*opaque_reference_fun); | 2930 native_context()->set_opaque_reference_function(*opaque_reference_fun); |
2920 } | 2931 } |
2921 | 2932 |
2922 // InternalArrays should not use Smi-Only array optimizations. There are too | 2933 // InternalArrays should not use Smi-Only array optimizations. There are too |
2923 // many places in the C++ runtime code (e.g. RegEx) that assume that | 2934 // many places in the C++ runtime code (e.g. RegEx) that assume that |
2924 // elements in InternalArrays can be set to non-Smi values without going | 2935 // elements in InternalArrays can be set to non-Smi values without going |
2925 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT | 2936 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT |
2926 // transition easy to trap. Moreover, they rarely are smi-only. | 2937 // transition easy to trap. Moreover, they rarely are smi-only. |
2927 { | 2938 { |
2928 HandleScope scope(isolate()); | 2939 HandleScope scope(isolate()); |
2929 Handle<JSObject> utils = | 2940 Handle<JSObject> utils = |
2930 Handle<JSObject>::cast(isolate()->natives_utils_object()); | 2941 Handle<JSObject>::cast(isolate()->natives_utils_object()); |
2931 Handle<JSFunction> array_function = | 2942 Handle<JSFunction> array_function = |
2932 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); | 2943 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); |
2933 native_context()->set_internal_array_function(*array_function); | 2944 native_context()->set_internal_array_function(*array_function); |
2934 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); | 2945 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); |
2935 } | 2946 } |
2936 | 2947 |
2937 // Run the rest of the native scripts. | 2948 // Run the rest of the native scripts. |
2938 while (builtin_index < Natives::GetBuiltinsCount()) { | 2949 while (builtin_index < Natives::GetBuiltinsCount()) { |
2939 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2950 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2940 } | 2951 } |
2941 | 2952 |
2942 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; | 2953 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; |
2943 | 2954 |
| 2955 auto template_instantiations_cache = UnseededNumberDictionary::New( |
| 2956 isolate(), ApiNatives::kInitialFunctionCacheSize); |
| 2957 native_context()->set_template_instantiations_cache( |
| 2958 *template_instantiations_cache); |
| 2959 |
2944 // Store the map for the %ObjectPrototype% after the natives has been compiled | 2960 // Store the map for the %ObjectPrototype% after the natives has been compiled |
2945 // and the Object function has been set up. | 2961 // and the Object function has been set up. |
2946 Handle<JSFunction> object_function(native_context()->object_function()); | 2962 Handle<JSFunction> object_function(native_context()->object_function()); |
2947 DCHECK(JSObject::cast(object_function->initial_map()->prototype()) | 2963 DCHECK(JSObject::cast(object_function->initial_map()->prototype()) |
2948 ->HasFastProperties()); | 2964 ->HasFastProperties()); |
2949 native_context()->set_object_function_prototype_map( | 2965 native_context()->set_object_function_prototype_map( |
2950 HeapObject::cast(object_function->initial_map()->prototype())->map()); | 2966 HeapObject::cast(object_function->initial_map()->prototype())->map()); |
2951 | 2967 |
2952 // Set up the map for Object.create(null) instances. | 2968 // Set up the map for Object.create(null) instances. |
2953 Handle<Map> object_with_null_prototype_map = | 2969 Handle<Map> object_with_null_prototype_map = |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3850 HookUpGlobalObject(global_object); | 3866 HookUpGlobalObject(global_object); |
3851 | 3867 |
3852 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3868 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3853 } else { | 3869 } else { |
3854 // We get here if there was no context snapshot. | 3870 // We get here if there was no context snapshot. |
3855 CreateRoots(); | 3871 CreateRoots(); |
3856 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 3872 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
3857 CreateStrictModeFunctionMaps(empty_function); | 3873 CreateStrictModeFunctionMaps(empty_function); |
3858 CreateIteratorMaps(empty_function); | 3874 CreateIteratorMaps(empty_function); |
3859 CreateAsyncFunctionMaps(empty_function); | 3875 CreateAsyncFunctionMaps(empty_function); |
3860 | |
3861 // Set up the template instantiations cache before creating the globals, | |
3862 // since they may want to use the cache. | |
3863 auto template_instantiations_cache = UnseededNumberDictionary::New( | |
3864 isolate, ApiNatives::kInitialFunctionCacheSize); | |
3865 native_context()->set_template_instantiations_cache( | |
3866 *template_instantiations_cache); | |
3867 | |
3868 Handle<JSGlobalObject> global_object = | 3876 Handle<JSGlobalObject> global_object = |
3869 CreateNewGlobals(global_proxy_template, global_proxy); | 3877 CreateNewGlobals(global_proxy_template, global_proxy); |
3870 HookUpGlobalProxy(global_object, global_proxy); | 3878 HookUpGlobalProxy(global_object, global_proxy); |
3871 InitializeGlobal(global_object, empty_function, context_type); | 3879 InitializeGlobal(global_object, empty_function, context_type); |
3872 InitializeNormalizedMapCaches(); | 3880 InitializeNormalizedMapCaches(); |
3873 | 3881 |
3874 if (!InstallNatives(context_type)) return; | 3882 if (!InstallNatives(context_type)) return; |
3875 | 3883 |
3876 MakeFunctionInstancePrototypeWritable(); | 3884 MakeFunctionInstancePrototypeWritable(); |
3877 | 3885 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3940 } | 3948 } |
3941 | 3949 |
3942 | 3950 |
3943 // Called when the top-level V8 mutex is destroyed. | 3951 // Called when the top-level V8 mutex is destroyed. |
3944 void Bootstrapper::FreeThreadResources() { | 3952 void Bootstrapper::FreeThreadResources() { |
3945 DCHECK(!IsActive()); | 3953 DCHECK(!IsActive()); |
3946 } | 3954 } |
3947 | 3955 |
3948 } // namespace internal | 3956 } // namespace internal |
3949 } // namespace v8 | 3957 } // namespace v8 |
OLD | NEW |