From 26591d663164bddca8747f5927f0ce63d0d2b351 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 5 Nov 2023 19:44:08 +0200 Subject: [PATCH] fix: lazy operators incorrectly pop values from stack --- .../topchetoeu/jscript/compilation/values/LazyAndStatement.java | 2 +- .../topchetoeu/jscript/compilation/values/LazyOrStatement.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/me/topchetoeu/jscript/compilation/values/LazyAndStatement.java b/src/me/topchetoeu/jscript/compilation/values/LazyAndStatement.java index d71ab81..fea8de5 100644 --- a/src/me/topchetoeu/jscript/compilation/values/LazyAndStatement.java +++ b/src/me/topchetoeu/jscript/compilation/values/LazyAndStatement.java @@ -29,7 +29,7 @@ public class LazyAndStatement extends Statement { if (pollute) target.add(Instruction.dup().locate(loc())); int start = target.size(); target.add(Instruction.nop()); - target.add(Instruction.discard().locate(loc())); + if (pollute) target.add(Instruction.discard().locate(loc())); second.compile(target, scope, pollute); target.set(start, Instruction.jmpIfNot(target.size() - start).locate(loc())); } diff --git a/src/me/topchetoeu/jscript/compilation/values/LazyOrStatement.java b/src/me/topchetoeu/jscript/compilation/values/LazyOrStatement.java index 476a546..3e896dd 100644 --- a/src/me/topchetoeu/jscript/compilation/values/LazyOrStatement.java +++ b/src/me/topchetoeu/jscript/compilation/values/LazyOrStatement.java @@ -29,7 +29,7 @@ public class LazyOrStatement extends Statement { if (pollute) target.add(Instruction.dup().locate(loc())); int start = target.size(); target.add(Instruction.nop()); - target.add(Instruction.discard().locate(loc())); + if (pollute) target.add(Instruction.discard().locate(loc())); second.compile(target, scope, pollute); target.set(start, Instruction.jmpIf(target.size() - start).locate(loc())); }