From 3343262e724db3941be3abc3d7480d1048fccef8 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:16:21 +0200 Subject: [PATCH] fix: main now uses new env API --- src/me/topchetoeu/jscript/Main.java | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/me/topchetoeu/jscript/Main.java b/src/me/topchetoeu/jscript/Main.java index 399f5aa..7d12cac 100644 --- a/src/me/topchetoeu/jscript/Main.java +++ b/src/me/topchetoeu/jscript/Main.java @@ -18,11 +18,15 @@ import me.topchetoeu.jscript.events.Observer; import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.exceptions.InterruptException; import me.topchetoeu.jscript.exceptions.SyntaxException; +import me.topchetoeu.jscript.filesystem.Filesystem; import me.topchetoeu.jscript.filesystem.MemoryFilesystem; import me.topchetoeu.jscript.filesystem.Mode; import me.topchetoeu.jscript.filesystem.PhysicalFilesystem; +import me.topchetoeu.jscript.filesystem.RootFilesystem; import me.topchetoeu.jscript.lib.Internals; import me.topchetoeu.jscript.modules.ModuleRepo; +import me.topchetoeu.jscript.permissions.PermissionsManager; +import me.topchetoeu.jscript.permissions.PermissionsProvider; public class Main { public static class Printer implements Observer { @@ -43,7 +47,7 @@ public class Main { static Thread engineTask, debugTask; static Engine engine = new Engine(true); static DebugServer debugServer = new DebugServer(); - static Environment environment = new Environment(null, null, null); + static Environment environment = new Environment(); static int j = 0; static boolean exited = false; @@ -119,9 +123,13 @@ public class Main { } })); - environment.filesystem.protocols.put("temp", new MemoryFilesystem(Mode.READ_WRITE)); - environment.filesystem.protocols.put("file", new PhysicalFilesystem(".")); - environment.modules.repos.put("file", ModuleRepo.ofFilesystem(environment.filesystem)); + var fs = new RootFilesystem(PermissionsProvider.get(environment)); + fs.protocols.put("temp", new MemoryFilesystem(Mode.READ_WRITE)); + fs.protocols.put("file", new PhysicalFilesystem(".")); + + environment.add(PermissionsProvider.ENV_KEY, PermissionsManager.ALL_PERMS); + environment.add(Filesystem.ENV_KEY, fs); + environment.add(ModuleRepo.ENV_KEY, ModuleRepo.ofFilesystem(fs)); } private static void initEngine() { debugServer.targets.put("target", (ws, req) -> new SimpleDebugger(ws, engine)); @@ -130,11 +138,11 @@ public class Main { } private static void initTypescript() { try { - var tsEnv = Internals.apply(new Environment(null, null, null)); - tsEnv.stackHidden = false; + var tsEnv = Internals.apply(new Environment()); + tsEnv.add(Environment.HIDE_STACK, true); tsEnv.global.define(null, "module", false, new ObjectValue()); - var bsEnv = Internals.apply(new Environment(null, null, null)); - bsEnv.stackHidden = false; + var bsEnv = Internals.apply(new Environment()); + bsEnv.add(Environment.HIDE_STACK, true); engine.pushMsg( false, tsEnv,