This here is a basic Javascript interactive shell that I knocked up in a week or so. It allows you to enter Javascript commands using the Kindle's keypad and screen via a crude but serviceable terminal emulator.

The interpreter used is Rhino, which is written in Java. Unfortunately the Kindle's security model means we don't get any nice stuff like the Rhino Javascript-to-Java JIT, but do still get Rhino's excellent Java integration: it's possible to directly access any Java class from Rhino as if it were Javascript. As such this makes KJS a great way to explore the Kindle's APIs.

There's also a very basic shell which allows external commands to be loaded and run (all in Javascript, of course). This doesn't do much but might be useful in the feature. (Got any handy scripts you think should be distributed with KJS? Let me know!)

Warning: The Kindle's not actually robust enough to run arbitrary code, and it's very easy to crash your device by doing the wrong thing --- e.g. while (true); will do it. (Can't break out of infinite loops.) So be careful, and when you device crashes and loses all your data, don't say I didn't warn you. 663 kB

The binary package, consisting of the KJS.azw2 file and a set of my developer public keys (which you will need to install to run the program).

If you want to hack it, get the source code. Some things you might want to pull out of it include:

  • Retroweaver integration, allowing Java 1.5 language features (generics! autoboxing! foreach loops!) on the Kindle's 1.4 JVM.
  • com.cowlark.eventbus, a port of GWT's excellent event bus system, and a wrapper around the Kindle lifecycle APIs so that we don't need to worry about what thread they're calling into our application from.
  • com.cowlark.kterm, a slightly-complete VT52 terminal emulator with crude but serviceable custom inputmethods allowing actual code to be written in it... although with four shift keys it does feel a bit like a ZX Spectrum. 1 MB

The source code.

Previous page