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

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: remove weird arrow-generator thing 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/compiler.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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 native_context()->set_strict_generator_function_map( 799 native_context()->set_strict_generator_function_map(
799 *strict_generator_function_map); 800 *strict_generator_function_map);
800 801
801 Handle<JSFunction> object_function(native_context()->object_function()); 802 Handle<JSFunction> object_function(native_context()->object_function());
802 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); 803 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
803 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); 804 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
804 native_context()->set_generator_object_prototype_map( 805 native_context()->set_generator_object_prototype_map(
805 *generator_object_prototype_map); 806 *generator_object_prototype_map);
806 } 807 }
807 808
809 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
810 // %AsyncFunctionPrototype% intrinsic
811 Handle<JSObject> async_function_prototype =
812 factory()->NewJSObject(isolate()->object_function(), TENURED);
813 SetObjectPrototype(async_function_prototype, empty);
814
815 JSObject::AddProperty(async_function_prototype,
816 factory()->to_string_tag_symbol(),
817 factory()->NewStringFromAsciiChecked("AsyncFunction"),
818 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
819
820 Handle<Map> strict_function_map(
821 native_context()->strict_function_without_prototype_map());
822 Handle<Map> sloppy_async_function_map =
823 Map::Copy(strict_function_map, "SloppyAsyncFunction");
824 sloppy_async_function_map->set_is_constructor(false);
825 Map::SetPrototype(sloppy_async_function_map, async_function_prototype);
826 native_context()->set_sloppy_async_function_map(*sloppy_async_function_map);
827
828 Handle<Map> strict_async_function_map =
829 Map::Copy(strict_function_map, "StrictAsyncFunction");
830 strict_async_function_map->set_is_constructor(false);
831 Map::SetPrototype(strict_async_function_map, async_function_prototype);
832 native_context()->set_strict_async_function_map(*strict_async_function_map);
833 }
834
808 void Genesis::CreateJSProxyMaps() { 835 void Genesis::CreateJSProxyMaps() {
809 // Allocate the different maps for all Proxy types. 836 // Allocate the different maps for all Proxy types.
810 // Next to the default proxy, we need maps indicating callable and 837 // Next to the default proxy, we need maps indicating callable and
811 // constructable proxies. 838 // constructable proxies.
812 Handle<Map> proxy_function_map = 839 Handle<Map> proxy_function_map =
813 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy"); 840 Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy");
814 proxy_function_map->set_is_constructor(true); 841 proxy_function_map->set_is_constructor(true);
815 native_context()->set_proxy_function_map(*proxy_function_map); 842 native_context()->set_proxy_function_map(*proxy_function_map);
816 843
817 Handle<Map> proxy_map = 844 Handle<Map> proxy_map =
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
2402 } 2429 }
2403 2430
2404 Handle<AccessorInfo> script_is_embedder_debug_script = 2431 Handle<AccessorInfo> script_is_embedder_debug_script =
2405 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs); 2432 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs);
2406 { 2433 {
2407 AccessorConstantDescriptor d( 2434 AccessorConstantDescriptor d(
2408 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())), 2435 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())),
2409 script_is_embedder_debug_script, attribs); 2436 script_is_embedder_debug_script, attribs);
2410 script_map->AppendDescriptor(&d); 2437 script_map->AppendDescriptor(&d);
2411 } 2438 }
2439
2440 {
2441 PrototypeIterator iter(native_context->sloppy_async_function_map());
2442 Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
2443
2444 static const bool kUseStrictFunctionMap = true;
2445 Handle<JSFunction> async_function_constructor = InstallFunction(
2446 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
2447 async_function_prototype, Builtins::kAsyncFunctionConstructor,
2448 kUseStrictFunctionMap);
2449 async_function_constructor->set_prototype_or_initial_map(
2450 native_context->sloppy_async_function_map());
2451 async_function_constructor->shared()->DontAdaptArguments();
2452 async_function_constructor->shared()->set_construct_stub(
2453 *isolate->builtins()->GeneratorFunctionConstructor());
2454 async_function_constructor->shared()->set_length(1);
2455 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
2456 Context::ASYNC_FUNCTION_FUNCTION_INDEX);
2457
2458 JSObject::AddProperty(
2459 async_function_prototype, factory->constructor_string(),
2460 async_function_constructor,
2461 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2462
2463 JSFunction::SetPrototype(async_function_constructor,
2464 async_function_prototype);
2465
2466 Handle<JSFunction> async_function_next =
2467 SimpleInstallFunction(container, "AsyncFunctionNext",
2468 Builtins::kAsyncFunctionNext, 2, false);
2469 Handle<JSFunction> async_function_throw =
2470 SimpleInstallFunction(container, "AsyncFunctionThrow",
2471 Builtins::kAsyncFunctionThrow, 2, false);
2472 async_function_next->shared()->set_native(true);
2473 async_function_throw->shared()->set_native(true);
2474 }
2412 } 2475 }
2413 } 2476 }
2414 2477
2415 2478
2416 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 2479 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
2417 Handle<JSObject> container) { 2480 Handle<JSObject> container) {
2418 HandleScope scope(isolate); 2481 HandleScope scope(isolate);
2419 2482
2420 #define INITIALIZE_FLAG(FLAG) \ 2483 #define INITIALIZE_FLAG(FLAG) \
2421 { \ 2484 { \
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 static const char* harmony_function_sent_natives[] = {nullptr}; 3075 static const char* harmony_function_sent_natives[] = {nullptr};
3013 static const char* promise_extra_natives[] = {"native promise-extra.js", 3076 static const char* promise_extra_natives[] = {"native promise-extra.js",
3014 nullptr}; 3077 nullptr};
3015 static const char* harmony_object_values_entries_natives[] = {nullptr}; 3078 static const char* harmony_object_values_entries_natives[] = {nullptr};
3016 static const char* harmony_object_own_property_descriptors_natives[] = { 3079 static const char* harmony_object_own_property_descriptors_natives[] = {
3017 nullptr}; 3080 nullptr};
3018 static const char* harmony_array_prototype_values_natives[] = {nullptr}; 3081 static const char* harmony_array_prototype_values_natives[] = {nullptr};
3019 static const char* harmony_exponentiation_operator_natives[] = {nullptr}; 3082 static const char* harmony_exponentiation_operator_natives[] = {nullptr};
3020 static const char* harmony_string_padding_natives[] = { 3083 static const char* harmony_string_padding_natives[] = {
3021 "native harmony-string-padding.js", nullptr}; 3084 "native harmony-string-padding.js", nullptr};
3022 static const char* harmony_async_await_natives[] = {nullptr}; 3085 static const char* harmony_async_await_natives[] = {
3086 "native harmony-async-await.js", nullptr};
3023 3087
3024 for (int i = ExperimentalNatives::GetDebuggerCount(); 3088 for (int i = ExperimentalNatives::GetDebuggerCount();
3025 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 3089 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
3026 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 3090 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
3027 if (FLAG_##id) { \ 3091 if (FLAG_##id) { \
3028 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 3092 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
3029 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 3093 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
3030 if (strncmp(script_name.start(), id##_natives[j], \ 3094 if (strncmp(script_name.start(), id##_natives[j], \
3031 script_name.length()) == 0) { \ 3095 script_name.length()) == 0) { \
3032 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ 3096 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 HookUpGlobalProxy(global_object, global_proxy); 3671 HookUpGlobalProxy(global_object, global_proxy);
3608 HookUpGlobalObject(global_object); 3672 HookUpGlobalObject(global_object);
3609 3673
3610 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3674 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3611 } else { 3675 } else {
3612 // We get here if there was no context snapshot. 3676 // We get here if there was no context snapshot.
3613 CreateRoots(); 3677 CreateRoots();
3614 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3678 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3615 CreateStrictModeFunctionMaps(empty_function); 3679 CreateStrictModeFunctionMaps(empty_function);
3616 CreateIteratorMaps(empty_function); 3680 CreateIteratorMaps(empty_function);
3681 CreateAsyncFunctionMaps(empty_function);
3617 Handle<JSGlobalObject> global_object = 3682 Handle<JSGlobalObject> global_object =
3618 CreateNewGlobals(global_proxy_template, global_proxy); 3683 CreateNewGlobals(global_proxy_template, global_proxy);
3619 HookUpGlobalProxy(global_object, global_proxy); 3684 HookUpGlobalProxy(global_object, global_proxy);
3620 InitializeGlobal(global_object, empty_function, context_type); 3685 InitializeGlobal(global_object, empty_function, context_type);
3621 InitializeNormalizedMapCaches(); 3686 InitializeNormalizedMapCaches();
3622 3687
3623 if (!InstallNatives(context_type)) return; 3688 if (!InstallNatives(context_type)) return;
3624 3689
3625 MakeFunctionInstancePrototypeWritable(); 3690 MakeFunctionInstancePrototypeWritable();
3626 3691
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3689 } 3754 }
3690 3755
3691 3756
3692 // Called when the top-level V8 mutex is destroyed. 3757 // Called when the top-level V8 mutex is destroyed.
3693 void Bootstrapper::FreeThreadResources() { 3758 void Bootstrapper::FreeThreadResources() {
3694 DCHECK(!IsActive()); 3759 DCHECK(!IsActive());
3695 } 3760 }
3696 3761
3697 } // namespace internal 3762 } // namespace internal
3698 } // namespace v8 3763 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/builtins.h » ('j') | src/compiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698