From 546d6634664d2347bf7c778b37e635b0bb07960e Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:42:21 +0300 Subject: [PATCH] feat: add this arg capture --- .../me/topchetoeu/jscript/compilation/CompileResult.java | 5 ++--- .../jscript/runtime/values/functions/CodeFunction.java | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/compilation/CompileResult.java b/src/java/me/topchetoeu/jscript/compilation/CompileResult.java index 0a78253..1c3d619 100644 --- a/src/java/me/topchetoeu/jscript/compilation/CompileResult.java +++ b/src/java/me/topchetoeu/jscript/compilation/CompileResult.java @@ -20,7 +20,7 @@ public final class CompileResult { public final List children; public final FunctionMapBuilder map; public final Environment env; - public int length, assignN; + public int length; public final Scope scope; public int temp() { @@ -101,8 +101,7 @@ public final class CompileResult { return new FunctionBody( scope.localsCount() + scope.allocCount(), scope.capturesCount(), - length, assignN, - instrRes, builtChildren + length, instrRes, builtChildren ); } diff --git a/src/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java b/src/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java index 6eb5aa6..d26db0d 100644 --- a/src/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java +++ b/src/java/me/topchetoeu/jscript/runtime/values/functions/CodeFunction.java @@ -8,6 +8,7 @@ import me.topchetoeu.jscript.runtime.values.Value; public final class CodeFunction extends FunctionValue { public final FunctionBody body; public final Value[][] captures; + public Value self; public Environment env; private Value onCall(Frame frame) { @@ -25,8 +26,8 @@ public final class CodeFunction extends FunctionValue { } @Override public Value onCall(Environment env, boolean isNew, String name, Value thisArg, Value ...args) { - var frame = new Frame(env, isNew, thisArg, args, this); - return onCall(frame); + if (self != null) return onCall(new Frame(env, isNew, self, args, this)); + else return onCall(new Frame(env, isNew, thisArg, args, this)); } public CodeFunction(Environment env, String name, FunctionBody body, Value[][] captures) {