Skip to content

Commit

Permalink
Don't fail validation on a 'for' statement with empty init clause
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Sep 17, 2015
1 parent bbb1676 commit 92d12ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ Vp.doWhileStatement = function doWhileStatement(body, test) {

// (VariableDeclaration | Expression | null, Expression | null, Expression | null, Statement, Loc) -> void
Vp.forStatement = function forStatement(init, test, update, body, loc) {
if (init.type === 'VariableDeclaration')
if (init !== null && init.type === 'VariableDeclaration')
this.fail("illegal variable declaration in for-head", init.loc);
this.optExpression(init);
this.checkSubtype(this.optExpression(test) || ty.Int, ty.Int, "for loop condition", loc);
Expand Down
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,35 @@ exports.testConditionalExpressionDifferentSubtypes = asmAssert.one(
return (1 ? (2 < 3) : 4)|0;
},
{ pass: true });

exports.testForWithoutInit = asmAssert.one(
"for statement without an init clause",
function f() {
var i = 0, j = 0;
for (; i|0 < 10; i = i|0 + 1) {
j = j|0 + i;
}
},
{ pass: true });

exports.testForWithoutTest = asmAssert.one(
"for statement without a test clause",
function f() {
var i = 0, j = 0;
for (i = 0; ; i = i|0 + 1) {
if (i|0 >= 10) break;
j = j|0 + i;
}
},
{ pass: true });

exports.testForWithoutUpdate = asmAssert.one(
"for statement without an update clause",
function f() {
var i = 0, j = 0;
for (i = 0; i|0 < 10;) {
j = j|0 + i;
i = i|0 + 1;
}
},
{ pass: true });

0 comments on commit 92d12ae

Please sign in to comment.