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

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 test 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') | src/builtins.cc » ('J')
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 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 } 2459 }
2433 2460
2434 Handle<AccessorInfo> script_is_embedder_debug_script = 2461 Handle<AccessorInfo> script_is_embedder_debug_script =
2435 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs); 2462 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs);
2436 { 2463 {
2437 AccessorConstantDescriptor d( 2464 AccessorConstantDescriptor d(
2438 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())), 2465 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())),
2439 script_is_embedder_debug_script, attribs); 2466 script_is_embedder_debug_script, attribs);
2440 script_map->AppendDescriptor(&d); 2467 script_map->AppendDescriptor(&d);
2441 } 2468 }
2469
2470 {
2471 PrototypeIterator iter(native_context->sloppy_async_function_map());
2472 Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
2473
2474 static const bool kUseStrictFunctionMap = true;
2475 Handle<JSFunction> async_function_constructor = InstallFunction(
2476 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
2477 async_function_prototype, Builtins::kAsyncFunctionConstructor,
2478 kUseStrictFunctionMap);
2479 async_function_constructor->set_prototype_or_initial_map(
2480 native_context->sloppy_async_function_map());
2481 async_function_constructor->shared()->DontAdaptArguments();
2482 async_function_constructor->shared()->set_construct_stub(
2483 *isolate->builtins()->GeneratorFunctionConstructor());
2484 async_function_constructor->shared()->set_length(1);
2485 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
2486 Context::ASYNC_FUNCTION_FUNCTION_INDEX);
2487
2488 JSObject::AddProperty(
2489 async_function_prototype, factory->constructor_string(),
2490 async_function_constructor,
2491 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2492
2493 JSFunction::SetPrototype(async_function_constructor,
2494 async_function_prototype);
2495
2496 Handle<JSFunction> async_function_next =
2497 SimpleInstallFunction(container, "AsyncFunctionNext",
2498 Builtins::kAsyncFunctionNext, 2, false);
2499 Handle<JSFunction> async_function_throw =
2500 SimpleInstallFunction(container, "AsyncFunctionThrow",
2501 Builtins::kAsyncFunctionThrow, 2, false);
2502 async_function_next->shared()->set_native(true);
2503 async_function_throw->shared()->set_native(true);
2504 }
2442 } 2505 }
2443 } 2506 }
2444 2507
2445 2508
2446 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 2509 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
2447 Handle<JSObject> container) { 2510 Handle<JSObject> container) {
2448 HandleScope scope(isolate); 2511 HandleScope scope(isolate);
2449 2512
2450 #define INITIALIZE_FLAG(FLAG) \ 2513 #define INITIALIZE_FLAG(FLAG) \
2451 { \ 2514 { \
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 static const char* harmony_object_own_property_descriptors_natives[] = { 3115 static const char* harmony_object_own_property_descriptors_natives[] = {
3053 nullptr}; 3116 nullptr};
3054 static const char* harmony_array_prototype_values_natives[] = {nullptr}; 3117 static const char* harmony_array_prototype_values_natives[] = {nullptr};
3055 static const char* harmony_exponentiation_operator_natives[] = {nullptr}; 3118 static const char* harmony_exponentiation_operator_natives[] = {nullptr};
3056 static const char* harmony_string_padding_natives[] = { 3119 static const char* harmony_string_padding_natives[] = {
3057 "native harmony-string-padding.js", nullptr}; 3120 "native harmony-string-padding.js", nullptr};
3058 #ifdef V8_I18N_SUPPORT 3121 #ifdef V8_I18N_SUPPORT
3059 static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js", 3122 static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js",
3060 nullptr}; 3123 nullptr};
3061 #endif 3124 #endif
3062 static const char* harmony_async_await_natives[] = {nullptr}; 3125 static const char* harmony_async_await_natives[] = {
3126 "native harmony-async-await.js", nullptr};
3063 3127
3064 for (int i = ExperimentalNatives::GetDebuggerCount(); 3128 for (int i = ExperimentalNatives::GetDebuggerCount();
3065 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 3129 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
3066 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 3130 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
3067 if (FLAG_##id) { \ 3131 if (FLAG_##id) { \
3068 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 3132 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
3069 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 3133 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
3070 if (strncmp(script_name.start(), id##_natives[j], \ 3134 if (strncmp(script_name.start(), id##_natives[j], \
3071 script_name.length()) == 0) { \ 3135 script_name.length()) == 0) { \
3072 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ 3136 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
3648 HookUpGlobalProxy(global_object, global_proxy); 3712 HookUpGlobalProxy(global_object, global_proxy);
3649 HookUpGlobalObject(global_object); 3713 HookUpGlobalObject(global_object);
3650 3714
3651 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3715 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3652 } else { 3716 } else {
3653 // We get here if there was no context snapshot. 3717 // We get here if there was no context snapshot.
3654 CreateRoots(); 3718 CreateRoots();
3655 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3719 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3656 CreateStrictModeFunctionMaps(empty_function); 3720 CreateStrictModeFunctionMaps(empty_function);
3657 CreateIteratorMaps(empty_function); 3721 CreateIteratorMaps(empty_function);
3722 CreateAsyncFunctionMaps(empty_function);
3658 Handle<JSGlobalObject> global_object = 3723 Handle<JSGlobalObject> global_object =
3659 CreateNewGlobals(global_proxy_template, global_proxy); 3724 CreateNewGlobals(global_proxy_template, global_proxy);
3660 HookUpGlobalProxy(global_object, global_proxy); 3725 HookUpGlobalProxy(global_object, global_proxy);
3661 InitializeGlobal(global_object, empty_function, context_type); 3726 InitializeGlobal(global_object, empty_function, context_type);
3662 InitializeNormalizedMapCaches(); 3727 InitializeNormalizedMapCaches();
3663 3728
3664 if (!InstallNatives(context_type)) return; 3729 if (!InstallNatives(context_type)) return;
3665 3730
3666 MakeFunctionInstancePrototypeWritable(); 3731 MakeFunctionInstancePrototypeWritable();
3667 3732
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3730 } 3795 }
3731 3796
3732 3797
3733 // Called when the top-level V8 mutex is destroyed. 3798 // Called when the top-level V8 mutex is destroyed.
3734 void Bootstrapper::FreeThreadResources() { 3799 void Bootstrapper::FreeThreadResources() {
3735 DCHECK(!IsActive()); 3800 DCHECK(!IsActive());
3736 } 3801 }
3737 3802
3738 } // namespace internal 3803 } // namespace internal
3739 } // namespace v8 3804 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/builtins.h » ('j') | src/builtins.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698