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

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: Add AsyncFunction constructor 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 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 JSObject::SetOwnPropertyIgnoreAttributes(
Dan Ehrenberg 2016/05/06 16:19:25 JSFunction::SetPrototype?
caitp (gmail) 2016/05/06 18:45:26 Done.
2464 async_function_constructor, factory->prototype_string(),
2465 async_function_prototype,
2466 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY | DONT_DELETE))
2467 .Check();
2468
2469 Handle<JSFunction> async_function_next =
2470 SimpleInstallFunction(container, "AsyncFunctionNext",
2471 Builtins::kAsyncFunctionNext, 2, false);
2472 Handle<JSFunction> async_function_throw =
2473 SimpleInstallFunction(container, "AsyncFunctionThrow",
2474 Builtins::kAsyncFunctionThrow, 2, false);
2475 async_function_next->shared()->set_native(true);
2476 async_function_throw->shared()->set_native(true);
2477 }
2412 } 2478 }
2413 } 2479 }
2414 2480
2415 2481
2416 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate, 2482 void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
2417 Handle<JSObject> container) { 2483 Handle<JSObject> container) {
2418 HandleScope scope(isolate); 2484 HandleScope scope(isolate);
2419 2485
2420 #define INITIALIZE_FLAG(FLAG) \ 2486 #define INITIALIZE_FLAG(FLAG) \
2421 { \ 2487 { \
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 Handle<JSFunction> cons = factory->NewFunction(name); 2560 Handle<JSFunction> cons = factory->NewFunction(name);
2495 JSFunction::SetInstancePrototype( 2561 JSFunction::SetInstancePrototype(
2496 cons, 2562 cons,
2497 Handle<Object>(native_context()->initial_object_prototype(), isolate)); 2563 Handle<Object>(native_context()->initial_object_prototype(), isolate));
2498 Handle<JSObject> atomics_object = factory->NewJSObject(cons, TENURED); 2564 Handle<JSObject> atomics_object = factory->NewJSObject(cons, TENURED);
2499 DCHECK(atomics_object->IsJSObject()); 2565 DCHECK(atomics_object->IsJSObject());
2500 JSObject::AddProperty(global, name, atomics_object, DONT_ENUM); 2566 JSObject::AddProperty(global, name, atomics_object, DONT_ENUM);
2501 2567
2502 SimpleInstallFunction(atomics_object, factory->InternalizeUtf8String("load"), 2568 SimpleInstallFunction(atomics_object, factory->InternalizeUtf8String("load"),
2503 Builtins::kAtomicsLoad, 2, true); 2569 Builtins::kAtomicsLoad, 2, true);
2504 SimpleInstallFunction(atomics_object, factory->InternalizeUtf8String("store"),
2505 Builtins::kAtomicsStore, 3, true);
Dan Ehrenberg 2016/05/06 16:19:25 Looks like a bad rebase conflict resolution
caitp (gmail) 2016/05/06 18:45:26 I'm not sure, I haven't rebased over that new comm
2506 } 2570 }
2507 2571
2508 2572
2509 void Genesis::InitializeGlobal_harmony_simd() { 2573 void Genesis::InitializeGlobal_harmony_simd() {
2510 if (!FLAG_harmony_simd) return; 2574 if (!FLAG_harmony_simd) return;
2511 2575
2512 Handle<JSGlobalObject> global( 2576 Handle<JSGlobalObject> global(
2513 JSGlobalObject::cast(native_context()->global_object())); 2577 JSGlobalObject::cast(native_context()->global_object()));
2514 Isolate* isolate = global->GetIsolate(); 2578 Isolate* isolate = global->GetIsolate();
2515 Factory* factory = isolate->factory(); 2579 Factory* factory = isolate->factory();
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 static const char* harmony_function_sent_natives[] = {nullptr}; 3076 static const char* harmony_function_sent_natives[] = {nullptr};
3013 static const char* promise_extra_natives[] = {"native promise-extra.js", 3077 static const char* promise_extra_natives[] = {"native promise-extra.js",
3014 nullptr}; 3078 nullptr};
3015 static const char* harmony_object_values_entries_natives[] = {nullptr}; 3079 static const char* harmony_object_values_entries_natives[] = {nullptr};
3016 static const char* harmony_object_own_property_descriptors_natives[] = { 3080 static const char* harmony_object_own_property_descriptors_natives[] = {
3017 nullptr}; 3081 nullptr};
3018 static const char* harmony_array_prototype_values_natives[] = {nullptr}; 3082 static const char* harmony_array_prototype_values_natives[] = {nullptr};
3019 static const char* harmony_exponentiation_operator_natives[] = {nullptr}; 3083 static const char* harmony_exponentiation_operator_natives[] = {nullptr};
3020 static const char* harmony_string_padding_natives[] = { 3084 static const char* harmony_string_padding_natives[] = {
3021 "native harmony-string-padding.js", nullptr}; 3085 "native harmony-string-padding.js", nullptr};
3022 static const char* harmony_async_await_natives[] = {nullptr}; 3086 static const char* harmony_async_await_natives[] = {
3087 "native harmony-async-await.js", nullptr};
3023 3088
3024 for (int i = ExperimentalNatives::GetDebuggerCount(); 3089 for (int i = ExperimentalNatives::GetDebuggerCount();
3025 i < ExperimentalNatives::GetBuiltinsCount(); i++) { 3090 i < ExperimentalNatives::GetBuiltinsCount(); i++) {
3026 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ 3091 #define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \
3027 if (FLAG_##id) { \ 3092 if (FLAG_##id) { \
3028 for (size_t j = 0; id##_natives[j] != NULL; j++) { \ 3093 for (size_t j = 0; id##_natives[j] != NULL; j++) { \
3029 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \ 3094 Vector<const char> script_name = ExperimentalNatives::GetScriptName(i); \
3030 if (strncmp(script_name.start(), id##_natives[j], \ 3095 if (strncmp(script_name.start(), id##_natives[j], \
3031 script_name.length()) == 0) { \ 3096 script_name.length()) == 0) { \
3032 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \ 3097 if (!Bootstrapper::CompileExperimentalBuiltin(isolate(), i)) { \
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 HookUpGlobalProxy(global_object, global_proxy); 3672 HookUpGlobalProxy(global_object, global_proxy);
3608 HookUpGlobalObject(global_object); 3673 HookUpGlobalObject(global_object);
3609 3674
3610 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3675 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3611 } else { 3676 } else {
3612 // We get here if there was no context snapshot. 3677 // We get here if there was no context snapshot.
3613 CreateRoots(); 3678 CreateRoots();
3614 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3679 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3615 CreateStrictModeFunctionMaps(empty_function); 3680 CreateStrictModeFunctionMaps(empty_function);
3616 CreateIteratorMaps(empty_function); 3681 CreateIteratorMaps(empty_function);
3682 CreateAsyncFunctionMaps(empty_function);
3617 Handle<JSGlobalObject> global_object = 3683 Handle<JSGlobalObject> global_object =
3618 CreateNewGlobals(global_proxy_template, global_proxy); 3684 CreateNewGlobals(global_proxy_template, global_proxy);
3619 HookUpGlobalProxy(global_object, global_proxy); 3685 HookUpGlobalProxy(global_object, global_proxy);
3620 InitializeGlobal(global_object, empty_function, context_type); 3686 InitializeGlobal(global_object, empty_function, context_type);
3621 InitializeNormalizedMapCaches(); 3687 InitializeNormalizedMapCaches();
3622 3688
3623 if (!InstallNatives(context_type)) return; 3689 if (!InstallNatives(context_type)) return;
3624 3690
3625 MakeFunctionInstancePrototypeWritable(); 3691 MakeFunctionInstancePrototypeWritable();
3626 3692
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3689 } 3755 }
3690 3756
3691 3757
3692 // Called when the top-level V8 mutex is destroyed. 3758 // Called when the top-level V8 mutex is destroyed.
3693 void Bootstrapper::FreeThreadResources() { 3759 void Bootstrapper::FreeThreadResources() {
3694 DCHECK(!IsActive()); 3760 DCHECK(!IsActive());
3695 } 3761 }
3696 3762
3697 } // namespace internal 3763 } // namespace internal
3698 } // namespace v8 3764 } // 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