Skip to content

Commit

Permalink
codegen: fix for without test or update crashing
Browse files Browse the repository at this point in the history
test262: 11.23% (+0.06) | πŸ§ͺ 49377 | 🀠 5547 (+34) | ❌ 1265 (+9) | πŸ’€ 8720 (+64) | 🧩 2481 (+3) | πŸ’₯ 1436 (-115) | ⏰ 2 (+1) | πŸ“ 29926 (+4)
  • Loading branch information
CanadaHonk committed Feb 12, 2024
1 parent c671f9c commit fbab1de
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/codeGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2315,17 +2315,18 @@ const generateFor = (scope, decl) => {
out.push([ Opcodes.loop, Blocktype.void ]);
depth.push('for');

out.push(...generate(scope, decl.test));
out.push(Opcodes.i32_to, [ Opcodes.if, Blocktype.void ]);
if (decl.test) out.push(...generate(scope, decl.test), Opcodes.i32_to);
else out.push(...number(1, Valtype.i32));

out.push([ Opcodes.if, Blocktype.void ]);
depth.push('if');

out.push([ Opcodes.block, Blocktype.void ]);
depth.push('block');
out.push(...generate(scope, decl.body));
out.push([ Opcodes.end ]);

out.push(...generate(scope, decl.update));
depth.pop();
if (decl.update) out.push(...generate(scope, decl.update));

out.push([ Opcodes.br, 1 ]);
out.push([ Opcodes.end ], [ Opcodes.end ]);
Expand Down

0 comments on commit fbab1de

Please sign in to comment.