fix: call regex constructor correctly

This commit is contained in:
TopchetoEU 2024-12-10 00:43:56 +02:00
parent db241919f2
commit 138baebacb
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
2 changed files with 6 additions and 3 deletions

View File

@ -43,7 +43,7 @@ public class InstructionRunner {
var callArgs = frame.take(instr.get(0)); var callArgs = frame.take(instr.get(0));
var funcObj = frame.pop(); var funcObj = frame.pop();
frame.push(funcObj.construct(env, callArgs)); frame.push(funcObj.constructNoSelf(env, callArgs));
frame.codePtr++; frame.codePtr++;
return null; return null;
@ -222,7 +222,10 @@ public class InstructionRunner {
} }
private static Value execLoadRegEx(Environment env, Instruction instr, Frame frame) { private static Value execLoadRegEx(Environment env, Instruction instr, Frame frame) {
if (env.hasNotNull(Value.REGEX_CONSTR)) { 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 { else {
throw EngineException.ofSyntax("Regex is not supported"); throw EngineException.ofSyntax("Regex is not supported");

View File

@ -89,7 +89,7 @@ public abstract class Value {
throw EngineException.ofType("Value is not a constructor"); 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 res = new ObjectValue();
var proto = getMember(env, StringValue.of("prototype")); var proto = getMember(env, StringValue.of("prototype"));