From 4c53689d9ca3fcbccbbca9906cf0c6e53c5736ea Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:19:35 +0200 Subject: [PATCH] feat: some behavioral fixes --- .../jscript/compilation/VariableDeclareNode.java | 15 ++++++++++++++- .../jscript/compilation/values/RegexNode.java | 1 + .../runtime/values/functions/FunctionValue.java | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java b/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java index 450cbc2..6e8ac68 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/VariableDeclareNode.java @@ -30,9 +30,22 @@ public class VariableDeclareNode extends Node { } @Override public void compile(CompileResult target, boolean pollute) { for (var entry : values) { + var index = target.scope.get(entry.var.name, false); + if (entry.value != null) { entry.value.compile(target, true); - target.add(VariableNode.toSet(target, loc(), entry.var.name, false, true)).setLocation(loc()); + } + + if (index == null) { + if (entry.value == null) { + target.add(Instruction.globDef(entry.var.name)); + } + else { + target.add(Instruction.globSet(entry.var.name, false, true)); + } + } + else if (entry.value != null) { + target.add(index.index().toSet(false)); } } diff --git a/src/main/java/me/topchetoeu/jscript/compilation/values/RegexNode.java b/src/main/java/me/topchetoeu/jscript/compilation/values/RegexNode.java index 8c8ccc4..90545a7 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/values/RegexNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/values/RegexNode.java @@ -32,6 +32,7 @@ public class RegexNode extends Node { var inBrackets = false; loop: while (true) { + if (i + n >= src.size()) break; switch (src.at(i + n)) { case '[': inBrackets = true; diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java index 7a0aa67..92701da 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/functions/FunctionValue.java @@ -115,7 +115,7 @@ public abstract class FunctionValue extends ObjectValue { this.length = length; this.name = name; - prototype.defineOwnField(null, "constructor", this); + prototype.defineOwnField(null, "constructor", this, true, false, true); } }