Skip to content

Commit d46b695

Browse files
committed
Merge pull request #115 from gasman/fix/allow-for-with-empty-init
Don't fail validation on a 'for' statement with empty init clause
2 parents bbb1676 + 92d12ae commit d46b695

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

lib/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ Vp.doWhileStatement = function doWhileStatement(body, test) {
745745

746746
// (VariableDeclaration | Expression | null, Expression | null, Expression | null, Statement, Loc) -> void
747747
Vp.forStatement = function forStatement(init, test, update, body, loc) {
748-
if (init.type === 'VariableDeclaration')
748+
if (init !== null && init.type === 'VariableDeclaration')
749749
this.fail("illegal variable declaration in for-head", init.loc);
750750
this.optExpression(init);
751751
this.checkSubtype(this.optExpression(test) || ty.Int, ty.Int, "for loop condition", loc);

test/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,35 @@ exports.testConditionalExpressionDifferentSubtypes = asmAssert.one(
322322
return (1 ? (2 < 3) : 4)|0;
323323
},
324324
{ pass: true });
325+
326+
exports.testForWithoutInit = asmAssert.one(
327+
"for statement without an init clause",
328+
function f() {
329+
var i = 0, j = 0;
330+
for (; i|0 < 10; i = i|0 + 1) {
331+
j = j|0 + i;
332+
}
333+
},
334+
{ pass: true });
335+
336+
exports.testForWithoutTest = asmAssert.one(
337+
"for statement without a test clause",
338+
function f() {
339+
var i = 0, j = 0;
340+
for (i = 0; ; i = i|0 + 1) {
341+
if (i|0 >= 10) break;
342+
j = j|0 + i;
343+
}
344+
},
345+
{ pass: true });
346+
347+
exports.testForWithoutUpdate = asmAssert.one(
348+
"for statement without an update clause",
349+
function f() {
350+
var i = 0, j = 0;
351+
for (i = 0; i|0 < 10;) {
352+
j = j|0 + i;
353+
i = i|0 + 1;
354+
}
355+
},
356+
{ pass: true });

0 commit comments

Comments
 (0)