> Scripting support and some minor bug fixes

Scripting support and some minor bug fixes

24-05-2025

Oh my god, it's been awhile since I even touched this project. And here I am, I'm back to work on it... for another 2 or 3 days until I other things take my attention away from it.

JS Support

I've added JS support, although currently it's very basic and very unsecure.

In keeping with my love of ancient greek stuff, the JS integration module has been named "Hephaestus", as the smith that's going to make these menus actually functional. I'll show off a small bit of it functioning later, but first, I'll talk about how I got it to start working.

I knew that I wanted to use either Lua or JS for the scripting language, but, after looking for Lua interpreters in Java I realized they're all either abandoned or... very close the original C implementation (low level and difficult to work with), I gave that up.

For JavaScript, I basically only had 1 option: GraalVM's Polyglot engine. As far as I'm aware, all of GraalVM is currently on an open source license so its use is allowed. (Which was not the case some years ago).

There was also Mozilla's Rhino engine which I used when writing a scripting engine for a server me and my friends were making (ArcadiusMC), so I had expirience with it, but I also knew its limits. The most major limit, or flaw, rather, is that it's stuck on ECMAScript version 5, which was released 10 years ago now. Graal's is upto date, as far as I'm aware and supports a majority of the JS standard library (console.log lol)

Working with Graal's polyglot, I do miss the layered scopes that Rhino had, which broke down the data script's had access to into stacks, like, you know, how every language does. Graal doesn't have that, Graal has one (kinda 2) scopes: the global scope. Not too big of an issue and it does make sense for the projet I'm working on, where all scripts loaded by a page should run in the same scope and context anyway.

Implementing GraalVM wasn't that time consuming, just add the depedencies, and write another DomSystem... and then change about 50 other things to add script support, make the loading of JS files easier and actually add the system to the document instances. It works though, and here it is, in action:

As the video shows, you can use JS in both the <script> element's content, or link to a .js file with the src attribute.

And it works!! It runs! It actually does its job and you're able to use Java objects, like the DOM and DocumentView with it.

Granted, it's a very basic setup, and I want to curtail the access JS has to the host VM, or maybe I don't?? I don't know yet. I want it to be powerful, but I'm also worried it will be abused.

For now, the only stdlib (yes, I'm calling it that) function available is command(args...) that lets you execute a console command, example:

1
2
3
4
5
6
7
// Simple command example
command(`tellraw @a "Hello, world"`)

// You can also use multiple arguments, they will be concatened
const player = server.getPlayer("JulieWoolie");
const amount = parseInt(view.getPath().getQuery("amount")) ?? 1
command("give", player.getName(), "minecraft_stick", amount)

Devtools Development

I worked on the Devtools a bit, not a lot, but a bit. I'll be adding in another tab: "Actions", which will allow you to perform some actions on the menu, such as:

Ontop of that, I also fixed some bugs that were ocurring as a result of the devtools and changed a few small things around. Namely:

Minor changes

Future plans