Anyone for Javascript?


#1

Javascript: the language we all love to hate!

Well, unfortunately its gradual creep towards world-domination has now seeped into juce, and I've added a JS interpreter as an integral part of the juce_core module!

Background: I needed some scripting for a side-project (and javascript was a more suitable choice than alternatives like Lua), so I had a look around at embeddable JS interpreters. The mainstream browser engines are huge feats of engineering, and way too large and complex to be embedded, but I found a project called TinyJS, which is a minimal implementation in less than 3000 lines of code. TinyJS was no use to me directly because it was far too slow, and lacked a lot of really fundamental stuff (e.g. 'break' and 'continue' statements!), but the fact that it was possible for a complete parser and runtime to fit into only 3000 lines made me wonder whether I could do better..

So... the juce implementation is only 1600 lines of code (including the core JS libraries!) It has almost no overheads, parses and executes about as fast as a non-JITed interpreter could do, and supports most of the basic language syntax. It's also tightly integrated with the 'var' class, which was always designed as a javascript-compatible container, and this makes it really easy to interchange native and interpreted classes via the DynamicObject class.

It's extremely "beta" at the moment, so I'd be keen to get feedback! I've no ambitions for it to become a standards-compliant challenger to the big boys, but it's so lightweight that I figured it might as well be included in the juce_core module alongside the JSON parsing functions.

Enjoy!