Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: src/bootstrapper.cc

Issue 2095953002: Refactor CreateApiFunction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Create the template instantiation cache early enough Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/api-natives.cc ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
1017 js_global_object_function = factory()->NewFunction( 1015 js_global_object_function = factory()->NewFunction(
1018 name, code, prototype, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); 1016 name, code, 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
1026 } else { 1017 } else {
1027 Handle<FunctionTemplateInfo> js_global_object_constructor( 1018 Handle<FunctionTemplateInfo> js_global_object_constructor(
1028 FunctionTemplateInfo::cast(js_global_object_template->constructor())); 1019 FunctionTemplateInfo::cast(js_global_object_template->constructor()));
1029 js_global_object_function = ApiNatives::CreateApiFunction( 1020 js_global_object_function = ApiNatives::CreateApiFunction(
1030 isolate(), js_global_object_constructor, factory()->the_hole_value(), 1021 isolate(), js_global_object_constructor, JS_GLOBAL_OBJECT_TYPE);
1031 ApiNatives::GlobalObjectType);
1032 } 1022 }
1033 1023
1034 js_global_object_function->initial_map()->set_is_prototype_map(true); 1024 js_global_object_function->initial_map()->set_is_prototype_map(true);
1035 js_global_object_function->initial_map()->set_dictionary_map(true); 1025 js_global_object_function->initial_map()->set_dictionary_map(true);
1036 Handle<JSGlobalObject> global_object = 1026 Handle<JSGlobalObject> global_object =
1037 factory()->NewJSGlobalObject(js_global_object_function); 1027 factory()->NewJSGlobalObject(js_global_object_function);
1038 1028
1039 // Step 2: (re)initialize the global proxy object. 1029 // Step 2: (re)initialize the global proxy object.
1040 Handle<JSFunction> global_proxy_function; 1030 Handle<JSFunction> global_proxy_function;
1041 if (global_proxy_template.IsEmpty()) { 1031 if (global_proxy_template.IsEmpty()) {
1042 Handle<String> name = Handle<String>(heap()->empty_string()); 1032 Handle<String> name = Handle<String>(heap()->empty_string());
1043 Handle<Code> code = isolate()->builtins()->Illegal(); 1033 Handle<Code> code = isolate()->builtins()->Illegal();
1044 global_proxy_function = factory()->NewFunction( 1034 global_proxy_function = factory()->NewFunction(
1045 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); 1035 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
1046 } else { 1036 } else {
1047 Handle<ObjectTemplateInfo> data = 1037 Handle<ObjectTemplateInfo> data =
1048 v8::Utils::OpenHandle(*global_proxy_template); 1038 v8::Utils::OpenHandle(*global_proxy_template);
1049 Handle<FunctionTemplateInfo> global_constructor( 1039 Handle<FunctionTemplateInfo> global_constructor(
1050 FunctionTemplateInfo::cast(data->constructor())); 1040 FunctionTemplateInfo::cast(data->constructor()));
1051 global_proxy_function = ApiNatives::CreateApiFunction( 1041 global_proxy_function = ApiNatives::CreateApiFunction(
1052 isolate(), global_constructor, factory()->the_hole_value(), 1042 isolate(), global_constructor, JS_GLOBAL_PROXY_TYPE);
1053 ApiNatives::GlobalProxyType);
1054 } 1043 }
1055 Handle<String> global_name = factory()->global_string(); 1044 Handle<String> global_name = factory()->global_string();
1056 global_proxy_function->shared()->set_instance_class_name(*global_name); 1045 global_proxy_function->shared()->set_instance_class_name(*global_name);
1057 global_proxy_function->initial_map()->set_is_access_check_needed(true); 1046 global_proxy_function->initial_map()->set_is_access_check_needed(true);
1058 global_proxy_function->initial_map()->set_has_hidden_prototype(true); 1047 global_proxy_function->initial_map()->set_has_hidden_prototype(true);
1059 1048
1060 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects 1049 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
1061 // Return the global proxy. 1050 // Return the global proxy.
1062 1051
1063 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); 1052 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function);
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 2905
2917 // A thin context is ready at this point. 2906 // A thin context is ready at this point.
2918 if (context_type == THIN_CONTEXT) return true; 2907 if (context_type == THIN_CONTEXT) return true;
2919 2908
2920 { 2909 {
2921 // Builtin function for OpaqueReference -- a JSValue-based object, 2910 // Builtin function for OpaqueReference -- a JSValue-based object,
2922 // that keeps its field isolated from JavaScript code. It may store 2911 // that keeps its field isolated from JavaScript code. It may store
2923 // objects, that JavaScript code may not access. 2912 // objects, that JavaScript code may not access.
2924 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( 2913 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction(
2925 factory()->empty_string(), isolate()->builtins()->Illegal(), 2914 factory()->empty_string(), isolate()->builtins()->Illegal(),
2926 isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); 2915 JS_VALUE_TYPE, JSValue::kSize);
2927 Handle<JSObject> prototype = 2916 Handle<JSObject> prototype =
2928 factory()->NewJSObject(isolate()->object_function(), TENURED); 2917 factory()->NewJSObject(isolate()->object_function(), TENURED);
2929 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); 2918 JSFunction::SetPrototype(opaque_reference_fun, prototype);
2930 native_context()->set_opaque_reference_function(*opaque_reference_fun); 2919 native_context()->set_opaque_reference_function(*opaque_reference_fun);
2931 } 2920 }
2932 2921
2933 // InternalArrays should not use Smi-Only array optimizations. There are too 2922 // InternalArrays should not use Smi-Only array optimizations. There are too
2934 // many places in the C++ runtime code (e.g. RegEx) that assume that 2923 // many places in the C++ runtime code (e.g. RegEx) that assume that
2935 // elements in InternalArrays can be set to non-Smi values without going 2924 // elements in InternalArrays can be set to non-Smi values without going
2936 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT 2925 // through a common bottleneck that would make the SMI_ONLY -> FAST_ELEMENT
2937 // transition easy to trap. Moreover, they rarely are smi-only. 2926 // transition easy to trap. Moreover, they rarely are smi-only.
2938 { 2927 {
2939 HandleScope scope(isolate()); 2928 HandleScope scope(isolate());
2940 Handle<JSObject> utils = 2929 Handle<JSObject> utils =
2941 Handle<JSObject>::cast(isolate()->natives_utils_object()); 2930 Handle<JSObject>::cast(isolate()->natives_utils_object());
2942 Handle<JSFunction> array_function = 2931 Handle<JSFunction> array_function =
2943 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS); 2932 InstallInternalArray(utils, "InternalArray", FAST_HOLEY_ELEMENTS);
2944 native_context()->set_internal_array_function(*array_function); 2933 native_context()->set_internal_array_function(*array_function);
2945 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS); 2934 InstallInternalArray(utils, "InternalPackedArray", FAST_ELEMENTS);
2946 } 2935 }
2947 2936
2948 // Run the rest of the native scripts. 2937 // Run the rest of the native scripts.
2949 while (builtin_index < Natives::GetBuiltinsCount()) { 2938 while (builtin_index < Natives::GetBuiltinsCount()) {
2950 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; 2939 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false;
2951 } 2940 }
2952 2941
2953 if (!CallUtilsFunction(isolate(), "PostNatives")) return false; 2942 if (!CallUtilsFunction(isolate(), "PostNatives")) return false;
2954 2943
2955 auto template_instantiations_cache = UnseededNumberDictionary::New(
2956 isolate(), ApiNatives::kInitialFunctionCacheSize);
2957 native_context()->set_template_instantiations_cache(
2958 *template_instantiations_cache);
2959
2960 // Store the map for the %ObjectPrototype% after the natives has been compiled 2944 // Store the map for the %ObjectPrototype% after the natives has been compiled
2961 // and the Object function has been set up. 2945 // and the Object function has been set up.
2962 Handle<JSFunction> object_function(native_context()->object_function()); 2946 Handle<JSFunction> object_function(native_context()->object_function());
2963 DCHECK(JSObject::cast(object_function->initial_map()->prototype()) 2947 DCHECK(JSObject::cast(object_function->initial_map()->prototype())
2964 ->HasFastProperties()); 2948 ->HasFastProperties());
2965 native_context()->set_object_function_prototype_map( 2949 native_context()->set_object_function_prototype_map(
2966 HeapObject::cast(object_function->initial_map()->prototype())->map()); 2950 HeapObject::cast(object_function->initial_map()->prototype())->map());
2967 2951
2968 // Set up the map for Object.create(null) instances. 2952 // Set up the map for Object.create(null) instances.
2969 Handle<Map> object_with_null_prototype_map = 2953 Handle<Map> object_with_null_prototype_map =
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
3866 HookUpGlobalObject(global_object); 3850 HookUpGlobalObject(global_object);
3867 3851
3868 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3852 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3869 } else { 3853 } else {
3870 // We get here if there was no context snapshot. 3854 // We get here if there was no context snapshot.
3871 CreateRoots(); 3855 CreateRoots();
3872 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3856 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3873 CreateStrictModeFunctionMaps(empty_function); 3857 CreateStrictModeFunctionMaps(empty_function);
3874 CreateIteratorMaps(empty_function); 3858 CreateIteratorMaps(empty_function);
3875 CreateAsyncFunctionMaps(empty_function); 3859 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
3876 Handle<JSGlobalObject> global_object = 3868 Handle<JSGlobalObject> global_object =
3877 CreateNewGlobals(global_proxy_template, global_proxy); 3869 CreateNewGlobals(global_proxy_template, global_proxy);
3878 HookUpGlobalProxy(global_object, global_proxy); 3870 HookUpGlobalProxy(global_object, global_proxy);
3879 InitializeGlobal(global_object, empty_function, context_type); 3871 InitializeGlobal(global_object, empty_function, context_type);
3880 InitializeNormalizedMapCaches(); 3872 InitializeNormalizedMapCaches();
3881 3873
3882 if (!InstallNatives(context_type)) return; 3874 if (!InstallNatives(context_type)) return;
3883 3875
3884 MakeFunctionInstancePrototypeWritable(); 3876 MakeFunctionInstancePrototypeWritable();
3885 3877
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 } 3940 }
3949 3941
3950 3942
3951 // Called when the top-level V8 mutex is destroyed. 3943 // Called when the top-level V8 mutex is destroyed.
3952 void Bootstrapper::FreeThreadResources() { 3944 void Bootstrapper::FreeThreadResources() {
3953 DCHECK(!IsActive()); 3945 DCHECK(!IsActive());
3954 } 3946 }
3955 3947
3956 } // namespace internal 3948 } // namespace internal
3957 } // namespace v8 3949 } // namespace v8
OLDNEW
« no previous file with comments | « src/api-natives.cc ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698