@@ -430,6 +430,7 @@ namespace Js
430430 generatorFunctionPrototype = nullptr ;
431431 generatorPrototype = nullptr ;
432432 iteratorPrototype = nullptr ;
433+ asyncFunctionPrototype = nullptr ;
433434
434435 if (scriptContext->GetConfig ()->IsES6SymbolEnabled ())
435436 {
@@ -520,6 +521,13 @@ namespace Js
520521 DynamicType::New (scriptContext, TypeIds_Object, proto, nullptr ,
521522 DeferredTypeHandler<InitializeGeneratorPrototype>::GetDefaultInstance ()));
522523 }
524+
525+ if (scriptContext->GetConfig ()->IsES7AsyncAndAwaitEnabled ())
526+ {
527+ asyncFunctionPrototype = DynamicObject::New (recycler,
528+ DynamicType::New (scriptContext, TypeIds_Object, functionPrototype, nullptr ,
529+ DeferredTypeHandler<InitializeAsyncFunctionPrototype>::GetDefaultInstance ()));
530+ }
523531 }
524532
525533 void JavascriptLibrary::InitializeTypes ()
@@ -975,19 +983,21 @@ namespace Js
975983 return functionTypeHandler;
976984 }
977985
978- DynamicTypeHandler * JavascriptLibrary::ScriptFunctionTypeHandler (bool hasPrototype , bool isAnonymousFunction)
986+ DynamicTypeHandler * JavascriptLibrary::ScriptFunctionTypeHandler (bool noPrototypeProperty , bool isAnonymousFunction)
979987 {
980988 DynamicTypeHandler * scriptFunctionTypeHandler = nullptr ;
981989
982- if (hasPrototype )
990+ if (noPrototypeProperty )
983991 {
984992 scriptFunctionTypeHandler = isAnonymousFunction ?
985- this ->GetDeferredAnonymousFunctionTypeHandler () : this ->GetDeferredFunctionTypeHandler ();
993+ this ->GetDeferredAnonymousFunctionTypeHandler () :
994+ this ->GetDeferredFunctionTypeHandler ();
986995 }
987996 else
988997 {
989998 scriptFunctionTypeHandler = isAnonymousFunction ?
990- JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler () : JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler (scriptContext);
999+ JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler () :
1000+ JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler (scriptContext);
9911001 }
9921002 return scriptFunctionTypeHandler;
9931003 }
@@ -1474,6 +1484,7 @@ namespace Js
14741484 weakMapConstructor = nullptr ;
14751485 weakSetConstructor = nullptr ;
14761486 generatorFunctionConstructor = nullptr ;
1487+ asyncFunctionConstructor = nullptr ;
14771488
14781489 if (scriptContext->GetConfig ()->IsES6MapEnabled ())
14791490 {
@@ -1511,6 +1522,14 @@ namespace Js
15111522 // GeneratorFunction is not a global property by ES6 spec so don't add it to the global object
15121523 }
15131524
1525+ if (scriptContext->GetConfig ()->IsES7AsyncAndAwaitEnabled ())
1526+ {
1527+ asyncFunctionConstructor = CreateBuiltinConstructor (&JavascriptFunction::EntryInfo::NewAsyncFunctionInstance,
1528+ DeferredTypeHandler<InitializeAsyncFunctionConstructor>::GetDefaultInstance (),
1529+ functionConstructor);
1530+ // AsyncFunction is not a global property by ES7 spec so don't add it to the global object
1531+ }
1532+
15141533 errorConstructor = CreateBuiltinConstructor (&JavascriptError::EntryInfo::NewErrorInstance,
15151534 DeferredTypeHandler<InitializeErrorConstructor>::GetDefaultInstance ());
15161535 AddFunction (globalObject, PropertyIds::Error, errorConstructor);
@@ -2260,8 +2279,6 @@ namespace Js
22602279 void JavascriptLibrary::InitializeGeneratorFunctionConstructor (DynamicObject* generatorFunctionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
22612280 {
22622281 typeHandler->Convert (generatorFunctionConstructor, mode, 3 );
2263- // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGeneratorFunction
2264- // so that the update is in sync with profiler
22652282 JavascriptLibrary* library = generatorFunctionConstructor->GetLibrary ();
22662283 ScriptContext* scriptContext = generatorFunctionConstructor->GetScriptContext ();
22672284 library->AddMember (generatorFunctionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked (1 ), PropertyConfigurable);
@@ -2276,8 +2293,6 @@ namespace Js
22762293 void JavascriptLibrary::InitializeGeneratorFunctionPrototype (DynamicObject* generatorFunctionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
22772294 {
22782295 typeHandler->Convert (generatorFunctionPrototype, mode, 3 );
2279- // Note: Any new function addition/deletion/modification should also be updated in JavascriptLibrary::ProfilerRegisterGeneratorFunction
2280- // so that the update is in sync with profiler
22812296 JavascriptLibrary* library = generatorFunctionPrototype->GetLibrary ();
22822297 ScriptContext* scriptContext = library->GetScriptContext ();
22832298
@@ -2310,6 +2325,34 @@ namespace Js
23102325 generatorPrototype->SetHasNoEnumerableProperties (true );
23112326 }
23122327
2328+ void JavascriptLibrary::InitializeAsyncFunctionConstructor (DynamicObject* asyncFunctionConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
2329+ {
2330+ typeHandler->Convert (asyncFunctionConstructor, mode, 3 );
2331+ JavascriptLibrary* library = asyncFunctionConstructor->GetLibrary ();
2332+ ScriptContext* scriptContext = asyncFunctionConstructor->GetScriptContext ();
2333+ library->AddMember (asyncFunctionConstructor, PropertyIds::length, TaggedInt::ToVarUnchecked (1 ), PropertyConfigurable);
2334+ library->AddMember (asyncFunctionConstructor, PropertyIds::prototype, library->asyncFunctionPrototype , PropertyNone);
2335+ if (scriptContext->GetConfig ()->IsES6FunctionNameEnabled ())
2336+ {
2337+ library->AddMember (asyncFunctionConstructor, PropertyIds::name, library->CreateStringFromCppLiteral (L" AsyncFunction" ), PropertyConfigurable);
2338+ }
2339+ asyncFunctionConstructor->SetHasNoEnumerableProperties (true );
2340+ }
2341+
2342+ void JavascriptLibrary::InitializeAsyncFunctionPrototype (DynamicObject* asyncFunctionPrototype, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
2343+ {
2344+ typeHandler->Convert (asyncFunctionPrototype, mode, 2 );
2345+ JavascriptLibrary* library = asyncFunctionPrototype->GetLibrary ();
2346+ ScriptContext* scriptContext = library->GetScriptContext ();
2347+
2348+ library->AddMember (asyncFunctionPrototype, PropertyIds::constructor, library->asyncFunctionConstructor , PropertyConfigurable);
2349+ if (scriptContext->GetConfig ()->IsES6ToStringTagEnabled ())
2350+ {
2351+ library->AddMember (asyncFunctionPrototype, PropertyIds::_symbolToStringTag, library->CreateStringFromCppLiteral (L" AsyncFunction" ), PropertyConfigurable);
2352+ }
2353+ asyncFunctionPrototype->SetHasNoEnumerableProperties (true );
2354+ }
2355+
23132356 void JavascriptLibrary::InitializeProxyConstructor (DynamicObject* proxyConstructor, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
23142357 {
23152358 typeHandler->Convert (proxyConstructor, mode, 4 );
@@ -3075,6 +3118,7 @@ namespace Js
30753118 this ->promiseConstructor ,
30763119 this ->proxyConstructor ,
30773120 this ->generatorFunctionConstructor ,
3121+ this ->asyncFunctionConstructor ,
30783122 this ->errorConstructor ,
30793123 this ->evalErrorConstructor ,
30803124 this ->rangeErrorConstructor ,
0 commit comments