An ES5 interpreter for Java
Go to file
2023-09-18 10:31:50 +03:00
.github/workflows feat: some cleanup 2023-09-09 18:55:20 +03:00
lib feat: Create filesystem interface and a physical filesystem 2023-09-18 10:31:50 +03:00
src/me/topchetoeu/jscript feat: Create filesystem interface and a physical filesystem 2023-09-18 10:31:50 +03:00
.gitignore feat: some cleanup 2023-09-09 18:55:20 +03:00
build.js feat: some cleanup 2023-09-09 18:55:20 +03:00
LICENSE bruh 2023-08-26 12:19:26 +03:00
package-lock.json major changes in preparations for environments 2023-09-04 14:30:57 +03:00
package.json major changes in preparations for environments 2023-09-04 14:30:57 +03:00
README.md initial commit 2023-08-05 18:37:18 +03:00

JScript

NOTE: This had nothing to do with Microsoft's dialect of EcmaScript

WARNING: Currently, this code is mostly undocumented. Proceed with caution and a psychiatrist.

JScript is an engine, capable of running EcmaScript 5, written entirely in Java. This engine has been developed with the goal of being easy to integrate with your preexisting codebase, THE GOAL OF THIS ENGINE IS NOT PERFORMANCE. My crude experiments show that this engine is 50x-100x slower than V8, which, although bad, is acceptable for most simple scripting purposes.

Example

The following will create a REPL using the engine as a backend. Not that this won't properly log errors. I recommend checking out the implementation in Main.main:

var engine = new PolyfillEngine(new File("."));
var in = new BufferedReader(new InputStreamReader(System.in));
engine.start();

while (true) {
    try {
        var raw = in.readLine();

        var res = engine.pushMsg(false, engine.global(), Map.of(), "<stdio>", raw, null).await();
        Values.printValue(engine.context(), res);
        System.out.println();
    }
    catch (EngineException e) {
        try {
            System.out.println("Uncaught " + e.toString(engine.context()));
        }
        catch (InterruptedException _e) {  return; }
    }
    catch (IOException | InterruptedException e) { return; }
}