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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | src/builtins.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 05755362ffcd70d3ba5f21978b152daeaeaa3fbb..8461bef082ad6c5d17876e4210bdf63438c5d28e 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -163,6 +163,7 @@ class Genesis BASE_EMBEDDED {
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
void CreateIteratorMaps(Handle<JSFunction> empty);
+ void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
void CreateJSProxyMaps();
// Make the "arguments" and "caller" properties throw a TypeError on access.
@@ -806,6 +807,32 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
*generator_object_prototype_map);
}
+void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
+ // %AsyncFunctionPrototype% intrinsic
+ Handle<JSObject> async_function_prototype =
+ factory()->NewJSObject(isolate()->object_function(), TENURED);
+ SetObjectPrototype(async_function_prototype, empty);
+
+ JSObject::AddProperty(async_function_prototype,
+ factory()->to_string_tag_symbol(),
+ factory()->NewStringFromAsciiChecked("AsyncFunction"),
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
+
+ Handle<Map> strict_function_map(
+ native_context()->strict_function_without_prototype_map());
+ Handle<Map> sloppy_async_function_map =
+ Map::Copy(strict_function_map, "SloppyAsyncFunction");
+ sloppy_async_function_map->set_is_constructor(false);
+ Map::SetPrototype(sloppy_async_function_map, async_function_prototype);
+ native_context()->set_sloppy_async_function_map(*sloppy_async_function_map);
+
+ Handle<Map> strict_async_function_map =
+ Map::Copy(strict_function_map, "StrictAsyncFunction");
+ strict_async_function_map->set_is_constructor(false);
+ Map::SetPrototype(strict_async_function_map, async_function_prototype);
+ native_context()->set_strict_async_function_map(*strict_async_function_map);
+}
+
void Genesis::CreateJSProxyMaps() {
// Allocate the different maps for all Proxy types.
// Next to the default proxy, we need maps indicating callable and
@@ -2411,6 +2438,42 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
script_is_embedder_debug_script, attribs);
script_map->AppendDescriptor(&d);
}
+
+ {
+ PrototypeIterator iter(native_context->sloppy_async_function_map());
+ Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
+
+ static const bool kUseStrictFunctionMap = true;
+ Handle<JSFunction> async_function_constructor = InstallFunction(
+ container, "AsyncFunction", JS_FUNCTION_TYPE, JSFunction::kSize,
+ async_function_prototype, Builtins::kAsyncFunctionConstructor,
+ kUseStrictFunctionMap);
+ async_function_constructor->set_prototype_or_initial_map(
+ native_context->sloppy_async_function_map());
+ async_function_constructor->shared()->DontAdaptArguments();
+ async_function_constructor->shared()->set_construct_stub(
+ *isolate->builtins()->AsyncFunctionConstructor());
+ async_function_constructor->shared()->set_length(1);
+ InstallWithIntrinsicDefaultProto(isolate, async_function_constructor,
+ Context::ASYNC_FUNCTION_FUNCTION_INDEX);
+
+ JSObject::AddProperty(
+ async_function_prototype, factory->constructor_string(),
+ async_function_constructor,
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
+
+ JSFunction::SetPrototype(async_function_constructor,
+ async_function_prototype);
+
+ Handle<JSFunction> async_function_next =
+ SimpleInstallFunction(container, "AsyncFunctionNext",
+ Builtins::kGeneratorPrototypeNext, 2, false);
+ Handle<JSFunction> async_function_throw =
+ SimpleInstallFunction(container, "AsyncFunctionThrow",
+ Builtins::kGeneratorPrototypeThrow, 2, false);
+ async_function_next->shared()->set_native(true);
+ async_function_throw->shared()->set_native(true);
+ }
}
}
@@ -3031,7 +3094,8 @@ bool Genesis::InstallExperimentalNatives() {
static const char* icu_case_mapping_natives[] = {"native icu-case-mapping.js",
nullptr};
#endif
- static const char* harmony_async_await_natives[] = {nullptr};
+ static const char* harmony_async_await_natives[] = {
+ "native harmony-async-await.js", nullptr};
for (int i = ExperimentalNatives::GetDebuggerCount();
i < ExperimentalNatives::GetBuiltinsCount(); i++) {
@@ -3627,6 +3691,7 @@ Genesis::Genesis(Isolate* isolate,
Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
CreateStrictModeFunctionMaps(empty_function);
CreateIteratorMaps(empty_function);
+ CreateAsyncFunctionMaps(empty_function);
Handle<JSGlobalObject> global_object =
CreateNewGlobals(global_proxy_template, global_proxy);
HookUpGlobalProxy(global_object, global_proxy);
« 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