Skip to content

Commit

Permalink
Fix for async iteration when the body contains a break statement (closes
Browse files Browse the repository at this point in the history
 #40)
  • Loading branch information
rpetrich committed Oct 19, 2019
1 parent ec822ef commit 656f905
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helpers.js
Expand Up @@ -233,7 +233,7 @@ export function _forAwaitOf(target, body, check) {
iterator.next().then(_resumeAfterNext).then(void 0, _reject);
return pact;
function _resumeAfterBody(result) {
if (check && !check()) {
if (check && check()) {
return _settle(pact, 1, iterator.return ? iterator.return().then(function() { return result; }) : result);
}
iterator.next().then(_resumeAfterNext).then(void 0, _reject);
Expand Down
11 changes: 11 additions & 0 deletions tests/for await of in body with break/case-async-iterator.js
@@ -0,0 +1,11 @@
expect((await f({
[Symbol.asyncIterator]() {
const arr = [1, 10, 4];
let i = 0;
return {
async next() {
return {value: arr[i], done: ++i === arr.length};
}
};
}
}))).toBe(11);

0 comments on commit 656f905

Please sign in to comment.