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

Side by Side Diff: src/bootstrapper.cc

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: fix some nits Created 4 years, 7 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 | « BUILD.gn ('k') | src/builtins.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/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/extensions/externalize-string-extension.h" 10 #include "src/extensions/externalize-string-extension.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void CreateRoots(); 156 void CreateRoots();
157 // Creates the empty function. Used for creating a context from scratch. 157 // Creates the empty function. Used for creating a context from scratch.
158 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); 158 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
159 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 159 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
160 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); 160 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower();
161 Handle<JSFunction> GetStrictArgumentsPoisonFunction(); 161 Handle<JSFunction> GetStrictArgumentsPoisonFunction();
162 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name); 162 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);
163 163
164 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 164 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
165 void CreateIteratorMaps(Handle<JSFunction> empty); 165 void CreateIteratorMaps(Handle<JSFunction> empty);
166 void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
166 void CreateJSProxyMaps(); 167 void CreateJSProxyMaps();
167 168
168 // Make the "arguments" and "caller" properties throw a TypeError on access. 169 // Make the "arguments" and "caller" properties throw a TypeError on access.
169 void AddRestrictedFunctionProperties(Handle<Map> map); 170 void AddRestrictedFunctionProperties(Handle<Map> map);
170 171
171 // Creates the global objects using the global proxy and the template passed 172 // Creates the global objects using the global proxy and the template passed
172 // in through the API. We call this regardless of whether we are building a 173 // in through the API. We call this regardless of whether we are building a
173 // context from scratch or using a deserialized one from the partial snapshot 174 // context from scratch or using a deserialized one from the partial snapshot
174 // but in the latter case we don't use the objects it produces directly, as 175 // but in the latter case we don't use the objects it produces directly, as
175 // we have to used the deserialized ones that are linked together with the 176 // we have to used the deserialized ones that are linked together with the
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 native_context()->set_strict_generator_function_map( 800 native_context()->set_strict_generator_function_map(
800 *strict_generator_function_map); 801 *strict_generator_function_map);
801 802
802 Handle<JSFunction> object_function(native_context()->object_function()); 803 Handle<JSFunction> object_function(native_context()->object_function());
803 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); 804 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
804 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); 805 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
805 native_context()->set_generator_object_prototype_map( 806 native_context()->set_generator_object_prototype_map(
806 *generator_object_prototype_map); 807 *generator_object_prototype_map);
807 } 808 }
808 809
810 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
811 // %AsyncFunctionPrototype% intrinsic
812 Handle<JSObject> async_function_prototype =
813 factory()->NewJSObject(isolate()->object_function(), TENURED);
814 SetObjectPrototype(async_function_prototype, empty);
815
816 JSObject::AddProperty(async_function_prototype,
817 factory()->to_string_tag_symbol(),
818 factory()->NewStringFromAsciiChecked("AsyncFunction"),
819 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
820
821 Handle<Map> strict_function_map(
822 native_context()->strict_function_without_prototype_map());
823 Handle<Map> sloppy_async_function_map =
824 Map::Copy(strict_function_map, "SloppyAsyncFunction");
825 sloppy_async_function_map->set_is_constructor(false);
826 Map::SetPrototype(sloppy_async_function_map, async_function_prototype);
827 native_context()->set_sloppy_async_function_map(*sloppy_async_function_map);
828
829 Handle<Map> strict_async_function_map =
830 Map::Copy(strict_function_map, "StrictAsyncFunction");
831 strict_async_function_map->set_is_constructor(false);
832 Map::SetPrototype(strict_async_function_map, async_function_prototype);
833 native_context()->set_strict_async_function_map(*strict_async_function_map);
834 }
835
809 void Genesis::CreateJSProxyMaps() { 836 void Genesis::CreateJSProxyMaps() {
810 // Allocate the different maps for all Proxy types. 837 // Allocate the different maps for all Proxy types.
811 // Next to the default proxy, we need maps indicating callable and 838 // Next to the default proxy, we need maps indicating callable and
812 // constructable proxies. 839 // constructable proxies.
813 Handle<Map> proxy_function_map = 840 Handle<Map> proxy_function_map =
814 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); 841 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy");
815 proxy_function_map->set_is_constructor(true); 842 proxy_function_map->set_is_constructor(true);
816 native_context()->set_proxy_function_map(*proxy_function_map); 843 native_context()->set_proxy_function_map(*proxy_function_map);
817 844
818 Handle<Map> proxy_map = 845 Handle<Map> proxy_map =
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 } 2431 }
2405 2432
2406 Handle<AccessorInfo> script_is_embedder_debug_script = 2433 Handle<AccessorInfo> script_is_embedder_debug_script =
2407 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs); 2434 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs);
2408 { 2435 {
2409 AccessorConstantDescriptor d( 2436 AccessorConstantDescriptor d(
2410 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())), 2437 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())),
2411 script_is_embedder_debug_script, attribs); 2438 script_is_embedder_debug_script, attribs);
2412 script_map->AppendDescriptor(&d); 2439 script_map->AppendDescriptor(&d);
2413 } 2440 }
2441
2442 {
2443 PrototypeIterator iter(native_context->sloppy_async_function_map());
2444 Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
2445
2446 static const bool kUseStrictFunctionMap = true;
2447 Handle<JSFunction> async_function_constructor = InstallFunction(
2448 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
2449 async_function_prototype, Builtins::kAsyncFunctionConstructor,
2450 kUseStrictFunctionMap);
2451 async_function_constructor->set_prototype_or_initial_map(
2452 native_context->sloppy_async_function_map());
2453 async_function_constructor->shared()->DontAdaptArguments();
2454 async_function_constructor->shared()->set_construct_stub(
2455 *isolate->builtins()->AsyncFunctionConstructor());
2456 async_function_constructor->shared()->set_length(1);
2457 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
2458 Context::ASYNC_FUNCTION_FUNCTION_INDEX);
2459
2460 JSObject::AddProperty(
2461 async_function_prototype, factory->constructor_string(),
2462 async_function_constructor,
2463 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2464
2465 JSFunction::SetPrototype(async_function_constructor,
2466 async_function_prototype);
2467
2468 Handle<JSFunction> async_function_next =
2469 SimpleInstallFunction(container, "AsyncFunctionNext",
2470 Builtins::kGeneratorPrototypeNext, 2, false);
2471 Handle<JSFunction> async_function_throw =
2472 SimpleInstallFunction(container, "AsyncFunctionThrow",
2473 Builtins::kGeneratorPrototypeThrow, 2, false);
2474 async_function_next->shared()->set_native(true);
2475 async_function_throw->shared()->set_native(true);
2476 }
2414 } 2477 }
2415 } 2478 }
2416 2479
2417 2480
2418 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 2481 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
2419 Handle<JSObject> container) { 2482 Handle<JSObject> container) {
2420 HandleScope scope(isolate); 2483 HandleScope scope(isolate);
2421 2484
2422 #define INITIALIZE_FLAG(FLAG) \ 2485 #define INITIALIZE_FLAG(FLAG) \
2423 { \ 2486 { \
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 static const char* harmony_object_own_property_descriptors_natives[] = { 3087 static const char* harmony_object_own_property_descriptors_natives[] = {
3025 nullptr}; 3088 nullptr};
3026 static const char* harmony_array_prototype_values_natives[] = {nullptr}; 3089 static const char* harmony_array_prototype_values_natives[] = {nullptr};
3027 static const char* harmony_exponentiation_operator_natives[] = {nullptr}; 3090 static const char* harmony_exponentiation_operator_natives[] = {nullptr};
3028 static const char* harmony_string_padding_natives[] = { 3091 static const char* harmony_string_padding_natives[] = {
3029 "native harmony-string-padding.js", nullptr}; 3092 "native harmony-string-padding.js", nullptr};
3030 #ifdef V8_I18N_SUPPORT 3093 #ifdef V8_I18N_SUPPORT
3031 static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js", 3094 static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js",
3032 nullptr}; 3095 nullptr};
3033 #endif 3096 #endif
3034 static const char* harmony_async_await_natives[] = {nullptr}; 3097 static const char* harmony_async_await_natives[] = {
3098 "native harmony-async-await.js", nullptr};
3035 3099
3036 for (int i = ExperimentalNatives::GetDebuggerCount(); 3100 for (int i = ExperimentalNatives::GetDebuggerCount();
3037 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 3101 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
3038 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 3102 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
3039 if (FLAG_##id) { \ 3103 if (FLAG_##id) { \
3040 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 3104 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
3041 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 3105 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
3042 if (strncmp(script_name.start(), id##_natives[j], \ 3106 if (strncmp(script_name.start(), id##_natives[j], \
3043 script_name.length()) == 0) { \ 3107 script_name.length()) == 0) { \
3044 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ 3108 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 HookUpGlobalProxy(global_object, global_proxy); 3684 HookUpGlobalProxy(global_object, global_proxy);
3621 HookUpGlobalObject(global_object); 3685 HookUpGlobalObject(global_object);
3622 3686
3623 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3687 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3624 } else { 3688 } else {
3625 // We get here if there was no context snapshot. 3689 // We get here if there was no context snapshot.
3626 CreateRoots(); 3690 CreateRoots();
3627 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3691 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3628 CreateStrictModeFunctionMaps(empty_function); 3692 CreateStrictModeFunctionMaps(empty_function);
3629 CreateIteratorMaps(empty_function); 3693 CreateIteratorMaps(empty_function);
3694 CreateAsyncFunctionMaps(empty_function);
3630 Handle<JSGlobalObject> global_object = 3695 Handle<JSGlobalObject> global_object =
3631 CreateNewGlobals(global_proxy_template, global_proxy); 3696 CreateNewGlobals(global_proxy_template, global_proxy);
3632 HookUpGlobalProxy(global_object, global_proxy); 3697 HookUpGlobalProxy(global_object, global_proxy);
3633 InitializeGlobal(global_object, empty_function, context_type); 3698 InitializeGlobal(global_object, empty_function, context_type);
3634 InitializeNormalizedMapCaches(); 3699 InitializeNormalizedMapCaches();
3635 3700
3636 if (!InstallNatives(context_type)) return; 3701 if (!InstallNatives(context_type)) return;
3637 3702
3638 MakeFunctionInstancePrototypeWritable(); 3703 MakeFunctionInstancePrototypeWritable();
3639 3704
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3702 } 3767 }
3703 3768
3704 3769
3705 // Called when the top-level V8 mutex is destroyed. 3770 // Called when the top-level V8 mutex is destroyed.
3706 void Bootstrapper::FreeThreadResources() { 3771 void Bootstrapper::FreeThreadResources() {
3707 DCHECK(!IsActive()); 3772 DCHECK(!IsActive());
3708 } 3773 }
3709 3774
3710 } // namespace internal 3775 } // namespace internal
3711 } // namespace v8 3776 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698