Skip to content

Commit

Permalink
[MERGE chakra-core#1483 @aneeshdk] Adding more async function test cases
Browse files Browse the repository at this point in the history
Merge pull request chakra-core#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.
  • Loading branch information
aneeshdk committed Aug 24, 2016
2 parents 760a526 + c9cb744 commit 2db2231
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 108 deletions.
6 changes: 3 additions & 3 deletions lib/Runtime/Base/FunctionBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5401,7 +5401,7 @@ namespace Js

bool FunctionBody::CanFunctionObjectHaveInlineCaches()
{
if (this->DoStackNestedFunc() || this->IsGenerator())
if (this->DoStackNestedFunc() || this->IsCoroutine())
{
return false;
}
Expand Down Expand Up @@ -6712,7 +6712,7 @@ namespace Js
!this->IsInDebugMode() &&
DoInterpreterProfile() &&
(!IsNewSimpleJit() || DoInterpreterAutoProfile()) &&
!IsGenerator(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
!IsCoroutine(); // Generator JIT requires bailout which SimpleJit cannot do since it skips GlobOpt
}

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

bool FunctionBody::DoSimpleJitDynamicProfile() const
Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/Base/FunctionBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ namespace Js
bool IsJitLoopBodyPhaseEnabled() const
{
// Consider: Allow JitLoopBody in generator functions for loops that do not yield.
return !PHASE_OFF(JITLoopBodyPhase, this) && DoFullJit() && !this->IsGenerator();
return !PHASE_OFF(JITLoopBodyPhase, this) && DoFullJit() && !this->IsCoroutine();
}

bool IsJitLoopBodyPhaseForced() const
Expand Down
4 changes: 2 additions & 2 deletions lib/Runtime/ByteCode/ByteCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4163,7 +4163,7 @@ void Bind(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
// VisitFunctionsInScope has already done binding within the declared function. Here, just record the fact
// that the parent function has a local/global declaration in it.
BindFuncSymbol(pnode, byteCodeGenerator);
if (pnode->sxFnc.IsGenerator())
if (pnode->sxFnc.IsCoroutine())
{
// Always assume generator functions escape since tracking them requires tracking
// the resulting generators in addition to the function.
Expand Down Expand Up @@ -4675,7 +4675,7 @@ void AssignRegisters(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
case knopFncDecl:
if (!byteCodeGenerator->TopFuncInfo()->IsGlobalFunction())
{
if (pnode->sxFnc.IsGenerator())
if (pnode->sxFnc.IsCoroutine())
{
// Assume generators always escape; otherwise need to analyze if
// the return value of calls to generator function, the generator
Expand Down
12 changes: 7 additions & 5 deletions lib/Runtime/Language/AsmJs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ namespace Js
AsmJSCompiler::CheckFunctionHead(AsmJsModuleCompiler &m, ParseNode *fn, bool isGlobal /*= true*/)
{
PnFnc fnc = fn->sxFnc;

if (fnc.HasNonSimpleParameterList())
{
return m.Fail(fn, _u("default & rest args not allowed"));
}

if (fnc.IsStaticMember())
{
return m.Fail(fn, _u("static functions are not allowed"));
Expand All @@ -73,6 +75,11 @@ namespace Js
return m.Fail(fn, _u("generator functions are not allowed"));
}

if (fnc.IsAsync())
{
return m.Fail(fn, _u("async functions are not allowed"));
}

if (fnc.IsLambda())
{
return m.Fail(fn, _u("lambda functions are not allowed"));
Expand All @@ -83,11 +90,6 @@ namespace Js
return m.Fail(fn, _u("closure functions are not allowed"));
}

if (fnc.HasDefaultArguments())
{
return m.Fail(fn, _u("default arguments not allowed"));
}

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Runtime/Language/JavascriptStackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace Js
}
else
#endif
if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
{
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
return gen->GetArguments().Values;
Expand Down Expand Up @@ -1016,7 +1016,7 @@ namespace Js
// hidden frame display here?
return (CallInfo const *)&inlinedFrameCallInfo;
}
else if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
else if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
{
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
return &gen->GetArguments().Info;
Expand All @@ -1042,7 +1042,7 @@ namespace Js
Assert(!inlinedFramesBeingWalked);
Assert(this->IsJavascriptFrame());

if (this->GetCurrentFunction()->GetFunctionInfo()->IsGenerator())
if (this->GetCurrentFunction()->GetFunctionInfo()->IsCoroutine())
{
JavascriptGenerator* gen = JavascriptGenerator::FromVar(this->GetCurrentArgv()[JavascriptFunctionArgIndex_This]);
return gen->GetArguments()[0];
Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/Library/GlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ namespace Js
funcBody = funcBody->GetParseableFunctionInfo(); // RegisterFunction may parse and update function body
}

ScriptFunction* pfuncScript = funcBody->IsGenerator() ?
ScriptFunction* pfuncScript = funcBody->IsCoroutine() ?
scriptContext->GetLibrary()->CreateGeneratorVirtualScriptFunction(funcBody) :
scriptContext->GetLibrary()->CreateScriptFunction(funcBody);

Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/Library/JavascriptFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace Js
{
// Get the latest proxy
FunctionProxy * proxy = pfuncBodyCache->GetFunctionProxy();
if (proxy->IsGenerator())
if (proxy->IsCoroutine())
{
pfuncScript = scriptContext->GetLibrary()->CreateGeneratorVirtualScriptFunction(proxy);
}
Expand Down
21 changes: 21 additions & 0 deletions test/es7/asyncawait-functionality.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ Executing test #17 - Async function with formal captured in eval
Executing test #18 - Async function with formal capturing in param scope
Executing test #19 - Async function with formal capturing in param scope with eval in the body
Executing test #20 - Async function with duplicate variable decalration in the body with eval
Executing test #21 - Async function with duplicate variable decalration in the body with child having eval
Executing test #22 - Async function with more than one await
Executing test #23 - Async function with more than one await with branching
Executing test #24 - Async function with an exception in an await expression
Executing test #25 - Async functions throws on an await
Executing test #26 - Awaiting a function with multiple awaits
Executing test #27 - Async function with nested try-catch in the body
Executing test #28 - Async function with try-catch and try-finally in the body
Executing test #29 - Async function and with

Completion Results:
Test #1 - Success lambda expression with no argument called with result = 'true'
Expand Down Expand Up @@ -61,6 +70,11 @@ Test #18 - Success function defined in the param scope captures the param scope
Test #19 - Success inner function decalration captures the body variable with eval in the body
Test #19 - Success function defined in the param scope captures the param scope variable with eval in the body
Test #20 - Success inner variable decalration shadows the formal
Test #21 - Success inner variable decalration shadows the formal with eval in child function
Test #27 - Success Caught the expected exception inside the inner catch in async body
Test #27 - Success Caught the expected exception inside catch in async body
Test #28 - Success Caught the expected exception inside the inner catch in async body
Test #28 - Success finally block is executed in async body
Test #6 - Success await in an async function #1 called with result = '-4'
Test #6 - Success await in an async function #2 called with result = '2'
Test #6 - Success await in an async function catch a rejected Promise in 'err'. Error = 'Error: My Error'
Expand All @@ -69,7 +83,14 @@ Test #7 - Success await keyword with a lambda expressions #1 called with result
Test #7 - Success await keyword with a lambda expressions #1 called with result = '60'
Test #9 - Success resolved promise in an async function #2 called with result = 'resolved'
Test #10 - Success %AsyncFunction% created async function #1 called with result = '0'
Test #23 - Success functions completes the first await call
Test #23 - Success functions completes the second await call
Test #24 - Success caught the expected exception
Test #25 - Success caught the expected exception
Test #8 - Success async function with default arguments's value has been rejected as expected by 'err' #2 called with err = 'expected error'
Test #9 - Success resolved promise in an async function #1 called with result = 'resolved'
Test #9 - Success promise in an async function has been rejected as expected by 'err' #3 called with err = 'rejected'
Test #22 - Success functions completes both await calls
Test #29 - Success functions call inside with returns the right this object
Test #10 - Success %AsyncFunction% created async function #2 called with result = '6'
Test #26 - Success Multiple awaits in the inner function completed
Loading

0 comments on commit 2db2231

Please sign in to comment.