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

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 more bugs 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
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 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 } 2457 }
2431 2458
2432 Handle<AccessorInfo> script_is_embedder_debug_script = 2459 Handle<AccessorInfo> script_is_embedder_debug_script =
2433 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs); 2460 Accessors::ScriptIsEmbedderDebugScriptInfo(isolate, attribs);
2434 { 2461 {
2435 AccessorConstantDescriptor d( 2462 AccessorConstantDescriptor d(
2436 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())), 2463 Handle<Name>(Name::cast(script_is_embedder_debug_script->name())),
2437 script_is_embedder_debug_script, attribs); 2464 script_is_embedder_debug_script, attribs);
2438 script_map->AppendDescriptor(&d); 2465 script_map->AppendDescriptor(&d);
2439 } 2466 }
2467
2468 {
2469 PrototypeIterator iter(native_context->sloppy_async_function_map());
2470 Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
2471
2472 static const bool kUseStrictFunctionMap = true;
2473 Handle<JSFunction> async_function_constructor = InstallFunction(
2474 container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
2475 async_function_prototype, Builtins::kAsyncFunctionConstructor,
2476 kUseStrictFunctionMap);
2477 async_function_constructor->set_prototype_or_initial_map(
2478 native_context->sloppy_async_function_map());
2479 async_function_constructor->shared()->DontAdaptArguments();
2480 async_function_constructor->shared()->set_construct_stub(
2481 *isolate->builtins()->GeneratorFunctionConstructor());
2482 async_function_constructor->shared()->set_length(1);
2483 InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
2484 Context::ASYNC_FUNCTION_FUNCTION_INDEX);
2485
2486 JSObject::AddProperty(
2487 async_function_prototype, factory->constructor_string(),
2488 async_function_constructor,
2489 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
2490
2491 JSFunction::SetPrototype(async_function_constructor,
2492 async_function_prototype);
2493
2494 Handle<JSFunction> async_function_next =
2495 SimpleInstallFunction(container, "AsyncFunctionNext",
2496 Builtins::kAsyncFunctionNext, 2, false);
2497 Handle<JSFunction> async_function_throw =
2498 SimpleInstallFunction(container, "AsyncFunctionThrow",
2499 Builtins::kAsyncFunctionThrow, 2, false);
2500 async_function_next->shared()->set_native(true);
2501 async_function_throw->shared()->set_native(true);
2502 }
2440 } 2503 }
2441 } 2504 }
2442 2505
2443 2506
2444 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 2507 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
2445 Handle<JSObject> container) { 2508 Handle<JSObject> container) {
2446 HandleScope scope(isolate); 2509 HandleScope scope(isolate);
2447 2510
2448 #define INITIALIZE_FLAG(FLAG) \ 2511 #define INITIALIZE_FLAG(FLAG) \
2449 { \ 2512 { \
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3040 static const char* harmony_function_sent_natives[] = {nullptr}; 3103 static const char* harmony_function_sent_natives[] = {nullptr};
3041 static const char* promise_extra_natives[] = {"native promise-extra.js", 3104 static const char* promise_extra_natives[] = {"native promise-extra.js",
3042 nullptr}; 3105 nullptr};
3043 static const char* harmony_object_values_entries_natives[] = {nullptr}; 3106 static const char* harmony_object_values_entries_natives[] = {nullptr};
3044 static const char* harmony_object_own_property_descriptors_natives[] = { 3107 static const char* harmony_object_own_property_descriptors_natives[] = {
3045 nullptr}; 3108 nullptr};
3046 static const char* harmony_array_prototype_values_natives[] = {nullptr}; 3109 static const char* harmony_array_prototype_values_natives[] = {nullptr};
3047 static const char* harmony_exponentiation_operator_natives[] = {nullptr}; 3110 static const char* harmony_exponentiation_operator_natives[] = {nullptr};
3048 static const char* harmony_string_padding_natives[] = { 3111 static const char* harmony_string_padding_natives[] = {
3049 "native harmony-string-padding.js", nullptr}; 3112 "native harmony-string-padding.js", nullptr};
3050 static const char* harmony_async_await_natives[] = {nullptr}; 3113 static const char* harmony_async_await_natives[] = {
3114 "native harmony-async-await.js", nullptr};
3051 3115
3052 for (int i = ExperimentalNatives::GetDebuggerCount(); 3116 for (int i = ExperimentalNatives::GetDebuggerCount();
3053 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 3117 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
3054 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 3118 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
3055 if (FLAG_##id) { \ 3119 if (FLAG_##id) { \
3056 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 3120 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
3057 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 3121 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
3058 if (strncmp(script_name.start(), id##_natives[j], \ 3122 if (strncmp(script_name.start(), id##_natives[j], \
3059 script_name.length()) == 0) { \ 3123 script_name.length()) == 0) { \
3060 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ 3124 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 HookUpGlobalProxy(global_object, global_proxy); 3699 HookUpGlobalProxy(global_object, global_proxy);
3636 HookUpGlobalObject(global_object); 3700 HookUpGlobalObject(global_object);
3637 3701
3638 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3702 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3639 } else { 3703 } else {
3640 // We get here if there was no context snapshot. 3704 // We get here if there was no context snapshot.
3641 CreateRoots(); 3705 CreateRoots();
3642 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3706 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3643 CreateStrictModeFunctionMaps(empty_function); 3707 CreateStrictModeFunctionMaps(empty_function);
3644 CreateIteratorMaps(empty_function); 3708 CreateIteratorMaps(empty_function);
3709 CreateAsyncFunctionMaps(empty_function);
3645 Handle<JSGlobalObject> global_object = 3710 Handle<JSGlobalObject> global_object =
3646 CreateNewGlobals(global_proxy_template, global_proxy); 3711 CreateNewGlobals(global_proxy_template, global_proxy);
3647 HookUpGlobalProxy(global_object, global_proxy); 3712 HookUpGlobalProxy(global_object, global_proxy);
3648 InitializeGlobal(global_object, empty_function, context_type); 3713 InitializeGlobal(global_object, empty_function, context_type);
3649 InitializeNormalizedMapCaches(); 3714 InitializeNormalizedMapCaches();
3650 3715
3651 if (!InstallNatives(context_type)) return; 3716 if (!InstallNatives(context_type)) return;
3652 3717
3653 MakeFunctionInstancePrototypeWritable(); 3718 MakeFunctionInstancePrototypeWritable();
3654 3719
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 } 3782 }
3718 3783
3719 3784
3720 // Called when the top-level V8 mutex is destroyed. 3785 // Called when the top-level V8 mutex is destroyed.
3721 void Bootstrapper::FreeThreadResources() { 3786 void Bootstrapper::FreeThreadResources() {
3722 DCHECK(!IsActive()); 3787 DCHECK(!IsActive());
3723 } 3788 }
3724 3789
3725 } // namespace internal 3790 } // namespace internal
3726 } // namespace v8 3791 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/builtins.h » ('j') | test/mjsunit/harmony/async-arrow-lexical-super.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698