diff --git a/src/main/java/me/topchetoeu/jscript/runtime/InstructionRunner.java b/src/main/java/me/topchetoeu/jscript/runtime/InstructionRunner.java index bb6c23a..7146a5c 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/InstructionRunner.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/InstructionRunner.java @@ -43,7 +43,7 @@ public class InstructionRunner { var callArgs = frame.take(instr.get(0)); var funcObj = frame.pop(); - frame.push(funcObj.construct(env, callArgs)); + frame.push(funcObj.constructNoSelf(env, callArgs)); frame.codePtr++; return null; @@ -222,7 +222,10 @@ public class InstructionRunner { } private static Value execLoadRegEx(Environment env, Instruction instr, Frame frame) { if (env.hasNotNull(Value.REGEX_CONSTR)) { - frame.push(env.get(Value.REGEX_CONSTR).construct(env, instr.get(0), instr.get(1))); + frame.push(env.get(Value.REGEX_CONSTR).constructNoSelf(env, + StringValue.of(instr.get(0)), + StringValue.of(instr.get(1)) + )); } else { throw EngineException.ofSyntax("Regex is not supported"); diff --git a/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java b/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java index 81758e4..d87d916 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/values/Value.java @@ -89,7 +89,7 @@ public abstract class Value { throw EngineException.ofType("Value is not a constructor"); } - public final Value construct(Environment env, Value ...args) { + public final Value constructNoSelf(Environment env, Value ...args) { var res = new ObjectValue(); var proto = getMember(env, StringValue.of("prototype"));