An ES5 interpreter for Java
Go to file
marregui 313b20a3b3
Add first test (#23)
* Add the first test and upgrade build.gradle to modern standards

1. gradle wrapper
2. ./gradlew run
3. manifest will look like
    Manifest-Version: 1.0
    Main-Class: me.topchetoeu.jscript.runtime.SimpleRepl
    Build-Timestamp: 2024-09-04T10:44:35.990+0200
    Build-Branch: ma/add-first-tests
    Build-Revision: 412edc0ebc
    Build-Jdk: 21.0.3 (Oracle Corporation 21.0.3+7-LTS-152)
    Build-Author: TopchetoEU
4. build/distributions contains a zip and a jar which contain jscript-0.9.41-beta.jar
5. unnecessary libs have been removed
6. gradle has been updated to 8.10
7. first test has been added

* fix: revert removal of Jabel (for support of Java 11)

---------

Co-authored-by: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com>
2024-09-04 15:29:17 +03:00
.github/workflows fix: buildline expects tag to start with 'v' 2024-03-09 00:45:00 +02:00
gradle/wrapper Add first test (#23) 2024-09-04 15:29:17 +03:00
src Add first test (#23) 2024-09-04 15:29:17 +03:00
.gitattributes fix: some config files cleanup 2023-12-24 14:31:33 +02:00
.gitignore build: improve build scripts 2024-01-12 09:48:20 +02:00
build.gradle Add first test (#23) 2024-09-04 15:29:17 +03:00
gradle.properties Add first test (#23) 2024-09-04 15:29:17 +03:00
LICENSE bruh 2023-08-26 12:19:26 +03:00
README.md Update README.md 2024-03-10 02:17:18 +02:00
settings.gradle Add first test (#23) 2024-09-04 15:29:17 +03:00

JScript

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

WARNING: Currently, this code is 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. Note that although the codebase has a Main class, this isn't meant to be a standalone program, but instead a library for running JavaScript code.

Example

The following is going to execute a simple javascript statement:

var engine = new Engine();
// Initialize a standard environment, with implementations of most basic standard libraries (Object, Array, Symbol, etc.)
var env = Internals.apply(new Environment());

// Queue code to load internal libraries and start engine
var awaitable = engine.pushMsg(false, env, new Filename("tmp", "eval"), "10 + Math.sqrt(5 / 3)", null);
// Run the engine on the same thread, until the event loop runs empty
engine.run(true);

// Get our result
System.out.println(awaitable.await());