diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-03-31 12:12:21 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-03-31 12:12:21 +0200 |
commit | 6f2f46187fc6947ca63356f735552feebd80d4a9 (patch) | |
tree | 5e359ce347d8dfdb4a2493b739f19f83a082841b /src/lparser.js | |
parent | dbcb965525833d167370fdade4ff8da7126be8a6 (diff) | |
download | fengari-6f2f46187fc6947ca63356f735552feebd80d4a9.tar.gz fengari-6f2f46187fc6947ca63356f735552feebd80d4a9.tar.bz2 fengari-6f2f46187fc6947ca63356f735552feebd80d4a9.zip |
Fixed infinite loop on 'else'
Diffstat (limited to 'src/lparser.js')
-rw-r--r-- | src/lparser.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lparser.js b/src/lparser.js index 73caf70..bdaa160 100644 --- a/src/lparser.js +++ b/src/lparser.js @@ -1128,11 +1128,11 @@ const assignment = function(ls, lh, nvars) { const cond = function(ls) { /* cond -> exp */ - let v = expdesc(); + let v = new expdesc(); expr(ls, v); /* read condition */ if (v.k === expkind.VNIL) v.k = expkind.VFALSE; /* 'falses' are all equal here */ lcode.luaK_goiftrue(ls.fs, v); - return v; + return v.f; }; const gotostat = function(ls, pc) { @@ -1341,15 +1341,17 @@ const test_then_block = function(ls, escapelist) { if (ls.t.token === R.TK_ELSE || ls.t.token === R.TK_ELSEIF) /* followed by 'else'/'elseif'? */ escapelist = lcode.luaK_concat(fs, escapelist, lcode.luaK_jump(fs)); /* must jump over it */ lcode.luaK_patchtohere(fs, jf); + + return escapelist }; const ifstat = function(ls, line) { /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ let fs = ls.fs; let escapelist = lcode.NO_JUMP; /* exit list for finished parts */ - test_then_block(ls, escapelist); /* IF cond THEN block */ + escapelist = test_then_block(ls, escapelist); /* IF cond THEN block */ while (ls.t.token === R.TK_ELSEIF) - test_then_block(ls, escapelist); /* ELSEIF cond THEN block */ + escapelist = test_then_block(ls, escapelist); /* ELSEIF cond THEN block */ if (testnext(ls, R.TK_ELSE)) block(ls); /* 'else' part */ check_match(ls, R.TK_END, R.TK_IF, line); |