Skip to content

Commit 2db2231

Browse files
committed
[MERGE #1483 @aneeshdk] Adding more async function test cases
Merge pull request #1483 from aneeshdk:AsyncTests Missed updating the stack walker to treat async functions also similar to generator functions. Added more test cases. Removed the catch class from the functionality tests as they are not relevant for async functions.
2 parents 760a526 + c9cb744 commit 2db2231

File tree

9 files changed

+294
-108
lines changed

9 files changed

+294
-108
lines changed

lib/Runtime/Base/FunctionBody.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5401,7 +5401,7 @@ namespace Js
54015401

54025402
bool FunctionBody::CanFunctionObjectHaveInlineCaches()
54035403
{
5404-
if (this->DoStackNestedFunc() || this->IsGenerator())
5404+
if (this->DoStackNestedFunc() || this->IsCoroutine())
54055405
{
54065406
return false;
54075407
}
@@ -6712,7 +6712,7 @@ namespace Js
67126712
!this->IsInDebugMode() &&
67136713
DoInterpreterProfile() &&
67146714
(!IsNewSimpleJit() || DoInterpreterAutoProfile()) &&
6715-
!IsGenerator(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
6715+
!IsCoroutine(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
67166716
}
67176717

67186718
bool FunctionBody::DoSimpleJitWithLock() const
@@ -6723,7 +6723,7 @@ namespace Js
67236723
!this->IsInDebugMode() &&
67246724
DoInterpreterProfileWithLock() &&
67256725
(!IsNewSimpleJit() || DoInterpreterAutoProfile()) &&
6726-
!IsGenerator(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
6726+
!IsCoroutine(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
67276727
}
67286728

67296729
bool FunctionBody::DoSimpleJitDynamicProfile() const

lib/Runtime/Base/FunctionBody.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ namespace Js
13461346
bool IsJitLoopBodyPhaseEnabled() const
13471347
{
13481348
// Consider: Allow JitLoopBody in generator functions for loops that do not yield.
1349-
return !PHASE_OFF(JITLoopBodyPhase, this) && DoFullJit() && !this->IsGenerator();
1349+
return !PHASE_OFF(JITLoopBodyPhase, this) && DoFullJit() && !this->IsCoroutine();
13501350
}
13511351

13521352
bool IsJitLoopBodyPhaseForced() const

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,7 @@ void Bind(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
41634163
// VisitFunctionsInScope has already done binding within the declared function. Here, just record the fact
41644164
// that the parent function has a local/global declaration in it.
41654165
BindFuncSymbol(pnode, byteCodeGenerator);
4166-
if (pnode->sxFnc.IsGenerator())
4166+
if (pnode->sxFnc.IsCoroutine())
41674167
{
41684168
// Always assume generator functions escape since tracking them requires tracking
41694169
// the resulting generators in addition to the function.
@@ -4675,7 +4675,7 @@ void AssignRegisters(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
46754675
case knopFncDecl:
46764676
if (!byteCodeGenerator->TopFuncInfo()->IsGlobalFunction())
46774677
{
4678-
if (pnode->sxFnc.IsGenerator())
4678+
if (pnode->sxFnc.IsCoroutine())
46794679
{
46804680
// Assume generators always escape; otherwise need to analyze if
46814681
// the return value of calls to generator function, the generator

lib/Runtime/Language/AsmJs.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ namespace Js
5959
AsmJSCompiler::CheckFunctionHead(AsmJsModuleCompiler &m, ParseNode *fn, bool isGlobal /*= true*/)
6060
{
6161
PnFnc fnc = fn->sxFnc;
62+
6263
if (fnc.HasNonSimpleParameterList())
6364
{
6465
return m.Fail(fn, _u("default & rest args not allowed"));
6566
}
67+
6668
if (fnc.IsStaticMember())
6769
{
6870
return m.Fail(fn, _u("static functions are not allowed"));
@@ -73,6 +75,11 @@ namespace Js
7375
return m.Fail(fn, _u("generator functions are not allowed"));
7476
}
7577

78+
if (fnc.IsAsync())
79+
{
80+
return m.Fail(fn, _u("async functions are not allowed"));
81+
}
82+
7683
if (fnc.IsLambda())
7784
{
7885
return m.Fail(fn, _u("lambda functions are not allowed"));
@@ -83,11 +90,6 @@ namespace Js
8390
return m.Fail(fn, _u("closure functions are not allowed"));
8491
}
8592

86-
if (fnc.HasDefaultArguments())
87-
{
88-
return m.Fail(fn, _u("default arguments not allowed"));
89-
}
90-
9193
return true;
9294
}
9395

lib/Runtime/Language/JavascriptStackWalker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ namespace Js
269269
}
270270
else
271271
#endif
272-
if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
272+
if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
273273
{
274274
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
275275
return gen->GetArguments().Values;
@@ -1016,7 +1016,7 @@ namespace Js
10161016
// hidden frame display here?
10171017
return (CallInfo const *)&inlinedFrameCallInfo;
10181018
}
1019-
else if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
1019+
else if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
10201020
{
10211021
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
10221022
return &gen->GetArguments().Info;
@@ -1042,7 +1042,7 @@ namespace Js
10421042
Assert(!inlinedFramesBeingWalked);
10431043
Assert(this->IsJavascriptFrame());
10441044

1045-
if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
1045+
if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
10461046
{
10471047
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
10481048
return gen->GetArguments()[0];

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ namespace Js
995995
funcBody = funcBody->GetParseableFunctionInfo(); // RegisterFunction may parse and update function body
996996
}
997997

998-
ScriptFunction* pfuncScript = funcBody->IsGenerator() ?
998+
ScriptFunction* pfuncScript = funcBody->IsCoroutine() ?
999999
scriptContext->GetLibrary()->CreateGeneratorVirtualScriptFunction(funcBody) :
10001000
scriptContext->GetLibrary()->CreateScriptFunction(funcBody);
10011001

lib/Runtime/Library/JavascriptFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace Js
243243
{
244244
// Get the latest proxy
245245
FunctionProxy * proxy = pfuncBodyCache->GetFunctionProxy();
246-
if (proxy->IsGenerator())
246+
if (proxy->IsCoroutine())
247247
{
248248
pfuncScript = scriptContext->GetLibrary()->CreateGeneratorVirtualScriptFunction(proxy);
249249
}

test/es7/asyncawait-functionality.baseline

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ Executing test #17 - Async function with formal captured in eval
2323
Executing test #18 - Async function with formal capturing in param scope
2424
Executing test #19 - Async function with formal capturing in param scope with eval in the body
2525
Executing test #20 - Async function with duplicate variable decalration in the body with eval
26+
Executing test #21 - Async function with duplicate variable decalration in the body with child having eval
27+
Executing test #22 - Async function with more than one await
28+
Executing test #23 - Async function with more than one await with branching
29+
Executing test #24 - Async function with an exception in an await expression
30+
Executing test #25 - Async functions throws on an await
31+
Executing test #26 - Awaiting a function with multiple awaits
32+
Executing test #27 - Async function with nested try-catch in the body
33+
Executing test #28 - Async function with try-catch and try-finally in the body
34+
Executing test #29 - Async function and with
2635

2736
Completion Results:
2837
Test #1 - Success lambda expression with no argument called with result = 'true'
@@ -61,6 +70,11 @@ Test #18 - Success function defined in the param scope captures the param scope
6170
Test #19 - Success inner function decalration captures the body variable with eval in the body
6271
Test #19 - Success function defined in the param scope captures the param scope variable with eval in the body
6372
Test #20 - Success inner variable decalration shadows the formal
73+
Test #21 - Success inner variable decalration shadows the formal with eval in child function
74+
Test #27 - Success Caught the expected exception inside the inner catch in async body
75+
Test #27 - Success Caught the expected exception inside catch in async body
76+
Test #28 - Success Caught the expected exception inside the inner catch in async body
77+
Test #28 - Success finally block is executed in async body
6478
Test #6 - Success await in an async function #1 called with result = '-4'
6579
Test #6 - Success await in an async function #2 called with result = '2'
6680
Test #6 - Success await in an async function catch a rejected Promise in 'err'. Error = 'Error: My Error'
@@ -69,7 +83,14 @@ Test #7 - Success await keyword with a lambda expressions #1 called with result
6983
Test #7 - Success await keyword with a lambda expressions #1 called with result = '60'
7084
Test #9 - Success resolved promise in an async function #2 called with result = 'resolved'
7185
Test #10 - Success %AsyncFunction% created async function #1 called with result = '0'
86+
Test #23 - Success functions completes the first await call
87+
Test #23 - Success functions completes the second await call
88+
Test #24 - Success caught the expected exception
89+
Test #25 - Success caught the expected exception
7290
Test #8 - Success async function with default arguments's value has been rejected as expected by 'err' #2 called with err = 'expected error'
7391
Test #9 - Success resolved promise in an async function #1 called with result = 'resolved'
7492
Test #9 - Success promise in an async function has been rejected as expected by 'err' #3 called with err = 'rejected'
93+
Test #22 - Success functions completes both await calls
94+
Test #29 - Success functions call inside with returns the right this object
7595
Test #10 - Success %AsyncFunction% created async function #2 called with result = '6'
96+
Test #26 - Success Multiple awaits in the inner function completed

0 commit comments

Comments
 (0)