Bug JavaScript bugs

ikzann

Member
This is a tracking thread for early JavaScript bugs, since I expect there to be quite a few.
  • Error messages when a value is missing on one of the globals are garbage.
  • Translate record types for e.g. maximize return value.
  • jsref command like ashref.
  • Wiki documentation. (first stab here)
  • Rhino copyright info for Credits.
  • Better ways to interrupt running JS code (currently only interrupts when going into ASH)
  • Equality does not work correctly on enumerated types.
  • there are still some things broken with require...
  • Lib.write does not work in relay scripts
  • Arguments are inverted for a bunch of the item movement functions.
  • Issue with object tracking and nested JS execution (e.g. script calls adventure which calls consult script)
Features:
  • Consult script support
  • Lifecycle script support
  • XML() object support (this already works)
  • require() support, for both ASH and JS
  • Relay script support (both override + menu)
 
Last edited:
jsref command like ashref

wiki documentation. It can be a stub to start with, but there should be something.
 
Fairly critical bug that breaks the Ezandora choice override script arrangement. Fixed in this patch.

Parent ash interpreters weren't being passed down to children run via cli_execute, so the children could not access the relay request. This patch rewires that together. This was an error in my refactoring of the Interpreter code.
 

Attachments

This is a big patch to set up consult scripts, "lifecycle" scripts (choiceAdventureScript, betweenBattleScript, etc.), and combat filter functions. I think this mostly completes the refactoring to pull all the non-ASH-specific stuff apart from the ASH code, but it's still a little bit messy. I've attached tests for filter functions (just run the script), consult scripts (need to make a CCS to match), and choiceAdventureScript (need to set the pref).
 

Attachments

Here is another patch to implement require() for both ASH + JS scripts. Can be tested with require("zlib.ash").getvar("verbosity") and require("test-require.js").main(0, Monster.get("zobmie"), "") with the below version of test-require.js installed.
 

Attachments

This is a big patch to set up consult scripts, "lifecycle" scripts (choiceAdventureScript, betweenBattleScript, etc.), and combat filter functions. I think this mostly completes the refactoring to pull all the non-ASH-specific stuff apart from the ASH code, but it's still a little bit messy. I've attached tests for filter functions (just run the script), consult scripts (need to make a CCS to match), and choiceAdventureScript (need to set the pref).
Thank you ikzann, r20520
 
Last edited:
Here is another patch to implement require() for both ASH + JS scripts. Can be tested with require("zlib.ash").getvar("verbosity") and require("test-require.js").main(0, Monster.get("zobmie"), "") with the below version of test-require.js installed.
And this has landed in r20521!
 
This patch should handle relay scripts correctly, both override scripts and those from the menu. Notably, in order to avoid breaking backwards compatibility with e.g. Guide, I've added a new GET argument to the relay menu scripts that triggers execution of any relay_x.js script vs simply returning it as a JS file. Guide calls its main JS file "relay_Guide.js."
 

Attachments

And a fix for several require bugs. You can test with svn checkout https://github.com/phulin/bean-daily/branches/main/build and test-require.

Incidentally, the project I stuck this in is an example of how you can set up modern JS tooling for relay script stuff. Everything is written in TypeScript and transpiled down to the version of JS that rhino supports, so you can get all the new fancy features.
 

Attachments

All of these are lightly tested and merged by r20525
 
Fixes some bugs with argument inversion on library functions, and some type conversion issues. It also reworks some of the proxy record code to work in a more consistent way.
 

Attachments

The previous patch fixes some pretty breaking bugs, so would love to get it merged whenever possible.

Here's another (applies only against the previous patch) that moves the standard library onto require("kolmafia") instead of a global. It also fixes some of the interrupt problems.
 

Attachments

The previous patch fixes some pretty breaking bugs, so would love to get it merged whenever possible.

Here's another (applies only against the previous patch) that moves the standard library onto require("kolmafia") instead of a global. It also fixes some of the interrupt problems.

I've been writing a TypeScript type definition that injected `Lib` and `Item` as globals...but thank you, your work is awesome.

By the way, I'm interested in helping out if anyone is working on type definitions.

----

Also, here's a tentative list of supported ES2015 features I gathered through running es-checker in r20527:

Supported
  • let and const (does not support block-level scoping or temporal dead zones; for (const a in obj) { ... } is a syntax error)
  • Array/object destructuring (but rest (...) isn't supported)
  • for..of loop, arrow functions, iterators/generators, Symbol
  • Set, Map, WeakSet, WeakMap
  • Octal and binary literals
  • New methods in Array, Math, Number, Object, String
  • TypedArray: can be constructed but common methods are unavailable
Unsupported
  • Spread and rest (...)
  • Template string literals: not a syntax error, but backtick strings are treated as plain strings
  • Classes (class), default function parameters, computed property names
  • Promise, Proxy, Reflect
(This isn't a bug report; I understand it's a limitation with Rhino itself.)

Edit: I tested ES2016-2020 and the only things available from them are:
  • Array.prototype.includes
  • String.prototype.padStart/padEnd/trimStart/trimEnd
  • Trailing commas in argument lists of function calls (trailing commas are not supported in parameter lists of function definitions)
 
Last edited:
You may want to coordinate with gausie, who is also working on type definitions here. I have an example of a fully-working TS project with webpack and babel up here: https://github.com/phulin/bean-daily. My plan was to leave the types as global, like JS's built-in types. Gausie also made the extremely-useful libram, which has $item and $monster tagged template literals that look just like ASH.

Thanks for checking all those features! I'm honestly not sure that it is even super important what Rhino supports, since we can just put it all on top of babel. I'm planning on writing a script outside of Mafia that will live-transpile modern JS you type on the command line, which I think would fill in the last gap.
 
@ikzann thank you for the two patches above! They are all merged as of r20528

@philmasterplus Yes! I'm very far into creating a set of type defs. At the repo @ikzann linked I have the full typing as well as a tool that generates those types from a combination of the output of running javadoc on mafia and running jsref in the CLI. In the future I would like that tool to automate downloading the latest mafia source and then running those two processes but for now it takes CLI args for the paths to them.

The absolute number one help that can be lent to the type defs is improving the source from which they are generated.
  • Adding javadocs to the field getters in ProxyRecordValues.java (take example from Item which I have mostly done, though I want to change some of the formatting
  • Add javadocs to the RuntimeLibrary.java functions. If we get more of these I'll be able to add inline documentation to the type def file! It'll be cool
  • Giving the args in RuntimeLibrary.java better names
 
Back
Top