From f929015f55471a9913246b58dddf29dfe410a5d0 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:41:52 +0300 Subject: [PATCH] ammend to prev commit --- .../me/topchetoeu/jscript/compilation/values/ArrayNode.java | 6 +++--- .../topchetoeu/jscript/compilation/values/ObjectNode.java | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/compilation/values/ArrayNode.java b/src/java/me/topchetoeu/jscript/compilation/values/ArrayNode.java index 148a2a4..4cbf300 100644 --- a/src/java/me/topchetoeu/jscript/compilation/values/ArrayNode.java +++ b/src/java/me/topchetoeu/jscript/compilation/values/ArrayNode.java @@ -18,13 +18,13 @@ public class ArrayNode extends Node { @Override public void compile(CompileResult target, boolean pollute) { target.add(Instruction.loadArr(statements.length)); + if (statements.length > 0) target.add(Instruction.dup(statements.length)); + for (var i = 0; i < statements.length; i++) { var el = statements[i]; if (el != null) { - target.add(Instruction.dup()); - target.add(Instruction.pushValue(i)); el.compile(target, true); - target.add(Instruction.storeMember()); + target.add(Instruction.storeMember(i)); } } diff --git a/src/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java b/src/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java index 9382b81..5a5de0e 100644 --- a/src/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java +++ b/src/java/me/topchetoeu/jscript/compilation/values/ObjectNode.java @@ -39,10 +39,9 @@ public class ObjectNode extends Node { for (var el : map.entrySet()) { target.add(Instruction.dup()); - target.add(Instruction.pushValue(el.getKey())); var val = el.getValue(); FunctionNode.compileWithName(val, target, true, el.getKey().toString()); - target.add(Instruction.storeMember()); + target.add(Instruction.storeMember(el.getKey())); } var keys = new ArrayList();