You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In current prototype of the Async/Await downlevel support, we found a bug causes an erroneous exception to occur in code that should otherwise work.
Repro:
The gist of the issue is that having a “return” statement inside of a for loop in a function that has an await in it causes an error.
Run this code an you’ll see that whenever the “num” is > .5 (and the “return true” statement gets evaluated), you get the following error that comes from within the __generator code: “TypeError: Unable to get property '0' of undefined or null reference”
The problem is caused by the “return” statement within the loop. If I had modified itemExists() to set a local variable, for example, and then break out of the loop via a “break” statement, the code would work:
// With workaround (NOT short-circuiting the loop)
async functionitemExists(): Q.Promise<boolean>{var numTries =3;varresult=false;for(vari=0;i<numTries;i++){varnum=awaitQ.fcall(function(){returnMath.random()});console.log(num);if(num>.5){result=true;break;}}returnresult;}
A quick analysis of the issue seems to be in the generated code. The exception is throw in here:
But the actual culprit seems to be in the fact that there is an inconsistency in the generated return and break statement (so far as I can tell). Namely, 3 looks like sometime a “break” and sometimes a “return”.
This should no longer be an issue as of 4685646, which is the new version of these downlevel transformations for async functions we are targeting for our 2.1 release.
In current prototype of the Async/Await downlevel support, we found a bug causes an erroneous exception to occur in code that should otherwise work.
Repro:
The gist of the issue is that having a “return” statement inside of a for loop in a function that has an await in it causes an error.
Run this code an you’ll see that whenever the “num” is > .5 (and the “return true” statement gets evaluated), you get the following error that comes from within the __generator code: “TypeError: Unable to get property '0' of undefined or null reference”
Analysis:
The problem is caused by the “return” statement within the loop. If I had modified itemExists() to set a local variable, for example, and then break out of the loop via a “break” statement, the code would work:
A quick analysis of the issue seems to be in the generated code. The exception is throw in here:
But the actual culprit seems to be in the fact that there is an inconsistency in the generated return and break statement (so far as I can tell). Namely, 3 looks like sometime a “break” and sometimes a “return”.
The text was updated successfully, but these errors were encountered: