diff --git a/src/me/topchetoeu/jscript/compilation/VariableDeclareStatement.java b/src/me/topchetoeu/jscript/compilation/VariableDeclareStatement.java index c3b43a8..111f95b 100644 --- a/src/me/topchetoeu/jscript/compilation/VariableDeclareStatement.java +++ b/src/me/topchetoeu/jscript/compilation/VariableDeclareStatement.java @@ -7,7 +7,15 @@ import me.topchetoeu.jscript.compilation.values.FunctionStatement; import me.topchetoeu.jscript.engine.scope.ScopeRecord; public class VariableDeclareStatement extends Statement { - public static record Pair(String name, Statement value) {} + public static class Pair { + public final String name; + public final Statement value; + + public Pair(String name, Statement value) { + this.name = name; + this.value = value; + } + } public final List values; @@ -16,22 +24,22 @@ public class VariableDeclareStatement extends Statement { @Override public void declare(ScopeRecord varsScope) { for (var key : values) { - varsScope.define(key.name()); + varsScope.define(key.name); } } @Override public void compile(List target, ScopeRecord scope) { for (var entry : values) { - if (entry.name() == null) continue; - var key = scope.getKey(entry.name()); + if (entry.name == null) continue; + var key = scope.getKey(entry.name); if (key instanceof String) target.add(Instruction.makeVar((String)key).locate(loc())); - if (entry.value() instanceof FunctionStatement) { - ((FunctionStatement)entry.value()).compile(target, scope, entry.name(), false); + if (entry.value instanceof FunctionStatement) { + ((FunctionStatement)entry.value).compile(target, scope, entry.name, false); target.add(Instruction.storeVar(key).locate(loc())); } - else if (entry.value() != null) { - entry.value().compileWithPollution(target, scope); + else if (entry.value != null) { + entry.value.compileWithPollution(target, scope); target.add(Instruction.storeVar(key).locate(loc())); } } diff --git a/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java b/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java index fd344c7..8e6b521 100644 --- a/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java +++ b/src/me/topchetoeu/jscript/compilation/control/SwitchStatement.java @@ -11,7 +11,15 @@ import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.engine.scope.ScopeRecord; public class SwitchStatement extends Statement { - public static record SwitchCase(Statement value, int statementI) {} + public static class SwitchCase { + public final Statement value; + public final int statementI; + + public SwitchCase(Statement value, int statementI) { + this.value = value; + this.statementI = statementI; + } + } @Override public boolean pollutesStack() { return false; } diff --git a/src/me/topchetoeu/jscript/engine/BreakpointData.java b/src/me/topchetoeu/jscript/engine/BreakpointData.java index e126e72..5e68ec1 100644 --- a/src/me/topchetoeu/jscript/engine/BreakpointData.java +++ b/src/me/topchetoeu/jscript/engine/BreakpointData.java @@ -2,4 +2,12 @@ package me.topchetoeu.jscript.engine; import me.topchetoeu.jscript.Location; -public record BreakpointData(Location loc, CallContext ctx) { } \ No newline at end of file +public class BreakpointData { + public final Location loc; + public final CallContext ctx; + + public BreakpointData(Location loc, CallContext ctx) { + this.loc = loc; + this.ctx = ctx; + } +} \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/engine/Engine.java b/src/me/topchetoeu/jscript/engine/Engine.java index 58f63b8..cb21212 100644 --- a/src/me/topchetoeu/jscript/engine/Engine.java +++ b/src/me/topchetoeu/jscript/engine/Engine.java @@ -18,7 +18,18 @@ import me.topchetoeu.jscript.interop.NativeTypeRegister; import me.topchetoeu.jscript.parsing.Parsing; public class Engine { - private static record RawFunction(GlobalScope scope, String filename, String raw) { } + private static class RawFunction { + public final GlobalScope scope; + public final String filename; + public final String raw; + + public RawFunction(GlobalScope scope, String filename, String raw) { + this.scope = scope; + this.filename = filename; + this.raw = raw; + } + } + private static class Task { public final Object func; public final Object thisArg; diff --git a/src/me/topchetoeu/jscript/engine/debug/DebugServer.java b/src/me/topchetoeu/jscript/engine/debug/DebugServer.java index 225a73f..b5e6730 100644 --- a/src/me/topchetoeu/jscript/engine/debug/DebugServer.java +++ b/src/me/topchetoeu/jscript/engine/debug/DebugServer.java @@ -64,7 +64,7 @@ public class DebugServer { } } private void onWsConnect(HttpRequest req, Socket socket) throws IOException { - var key = req.headers().get("sec-websocket-key"); + var key = req.headers.get("sec-websocket-key"); if (key == null) { Http.writeResponse( @@ -112,7 +112,7 @@ public class DebugServer { var socket = server.accept(); var req = Http.readRequest(socket.getInputStream()); - switch (req.path()) { + switch (req.path) { case "/json/version": send(socket, "{\"Browser\":\"" + browserDisplayName + "\",\"Protocol-Version\":\"1.2\"}"); break; @@ -133,7 +133,7 @@ public class DebugServer { ); break; default: - if (req.path().equals("/devtools/page/" + targetName)) onWsConnect(req, socket); + if (req.path.equals("/devtools/page/" + targetName)) onWsConnect(req, socket); else { Http.writeResponse( socket.getOutputStream(), diff --git a/src/me/topchetoeu/jscript/engine/debug/HttpRequest.java b/src/me/topchetoeu/jscript/engine/debug/HttpRequest.java index a45fe0e..e4a1ae6 100644 --- a/src/me/topchetoeu/jscript/engine/debug/HttpRequest.java +++ b/src/me/topchetoeu/jscript/engine/debug/HttpRequest.java @@ -2,5 +2,15 @@ package me.topchetoeu.jscript.engine.debug; import java.util.Map; -public record HttpRequest(String method, String path, Map headers) {} +public class HttpRequest { + public final String method; + public final String path; + public final Map headers; + + public HttpRequest(String method, String path, Map headers) { + this.method = method; + this.path = path; + this.headers = headers; + } +} diff --git a/src/me/topchetoeu/jscript/engine/values/ObjectValue.java b/src/me/topchetoeu/jscript/engine/values/ObjectValue.java index 2daf6c5..de84126 100644 --- a/src/me/topchetoeu/jscript/engine/values/ObjectValue.java +++ b/src/me/topchetoeu/jscript/engine/values/ObjectValue.java @@ -26,7 +26,15 @@ public class ObjectValue { FROZEN, } - public static record Property(FunctionValue getter, FunctionValue setter) {} + public static class Property { + public final FunctionValue getter; + public final FunctionValue setter; + + public Property(FunctionValue getter, FunctionValue setter) { + this.getter = getter; + this.setter = setter; + } + } private static final Object OBJ_PROTO = new Object(); private static final Object ARR_PROTO = new Object(); diff --git a/src/me/topchetoeu/jscript/interop/NativeTypeRegister.java b/src/me/topchetoeu/jscript/interop/NativeTypeRegister.java index c83e44a..c1ed7ea 100644 --- a/src/me/topchetoeu/jscript/interop/NativeTypeRegister.java +++ b/src/me/topchetoeu/jscript/interop/NativeTypeRegister.java @@ -34,9 +34,9 @@ public class NativeTypeRegister { var name = get.value(); var prop = target.properties.get(name); OverloadFunction getter = null; - var setter = prop == null ? null : prop.setter(); + var setter = prop == null ? null : prop.setter; - if (prop != null && prop.getter() instanceof OverloadFunction) getter = (OverloadFunction)prop.getter(); + if (prop != null && prop.getter instanceof OverloadFunction) getter = (OverloadFunction)prop.getter; else getter = new OverloadFunction("get " + name); getter.overloads.add(Overload.fromMethod(method)); @@ -45,10 +45,10 @@ public class NativeTypeRegister { if (set != null) { var name = set.value(); var prop = target.properties.get(name); - var getter = prop == null ? null : prop.getter(); + var getter = prop == null ? null : prop.getter; OverloadFunction setter = null; - if (prop != null && prop.setter() instanceof OverloadFunction) setter = (OverloadFunction)prop.setter(); + if (prop != null && prop.setter instanceof OverloadFunction) setter = (OverloadFunction)prop.setter; else setter = new OverloadFunction("set " + name); setter.overloads.add(Overload.fromMethod(method)); diff --git a/src/me/topchetoeu/jscript/parsing/Parsing.java b/src/me/topchetoeu/jscript/parsing/Parsing.java index dde815b..2c2b0ca 100644 --- a/src/me/topchetoeu/jscript/parsing/Parsing.java +++ b/src/me/topchetoeu/jscript/parsing/Parsing.java @@ -27,7 +27,18 @@ public class Parsing { ParseRes parse(String filename, List tokens, int i); } - private static record ObjProp(Object name, String access, FunctionStatement func) {} + private static class ObjProp { + public final Object name; + public final String access; + public final FunctionStatement func; + + public ObjProp(Object name, String access, FunctionStatement func) { + this.name = name; + this.access = access; + this.func = func; + } + } + private static final HashSet reserved = new HashSet(); static { reserved.add("true"); diff --git a/src/me/topchetoeu/jscript/polyfills/Promise.java b/src/me/topchetoeu/jscript/polyfills/Promise.java index 2795de1..91f36ed 100644 --- a/src/me/topchetoeu/jscript/polyfills/Promise.java +++ b/src/me/topchetoeu/jscript/polyfills/Promise.java @@ -14,7 +14,17 @@ import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.interop.Native; public class Promise { - private static record Handle(CallContext ctx, FunctionValue fulfilled, FunctionValue rejected) {} + private static class Handle { + public final CallContext ctx; + public final FunctionValue fulfilled; + public final FunctionValue rejected; + + public Handle(CallContext ctx, FunctionValue fulfilled, FunctionValue rejected) { + this.ctx = ctx; + this.fulfilled = fulfilled; + this.rejected = rejected; + } + } @Native("resolve") public static Promise ofResolved(CallContext engine, Object val) { @@ -194,7 +204,7 @@ public class Promise { this.state = STATE_FULFILLED; this.val = val; - for (var el : handles) el.ctx().engine().pushMsg(true, el.fulfilled, el.ctx().data(), null, val); + for (var el : handles) el.ctx.engine().pushMsg(true, el.fulfilled, el.ctx.data(), null, val); handles = null; } /** @@ -222,7 +232,7 @@ public class Promise { this.state = STATE_REJECTED; this.val = val; - for (var el : handles) el.ctx().engine().pushMsg(true, el.rejected, el.ctx().data(), null, val); + for (var el : handles) el.ctx.engine().pushMsg(true, el.rejected, el.ctx.data(), null, val); handles = null; } /**