Javascript listeners in JUCE javascript

Can we use javascript event listeners in JUCE using the juce_javascript and JavaScript Engine?

My guess that it would be pretty hard to do this. Event listeners in Javascript are difficult to implement in general, and juce::JavascriptEngine is also a pretty limited framework. Some of the JSEngine functions return juce::var, and you might be able to construct a juce::Value listener around those, but my guess is that it wouldn’t really work, because it probably returns a fresh var every time.

If you’re willing to modify the source code, juce::JavascriptEngine is pretty easy to hack, and if you can get access to the root object (which is a juce::var) then you can go to town on it. But this isn’t a great approach, for obvious reasons.

From the sense I have on this forum, not many people end up using juce::JavascriptEngine, because of its limitations. Also, let’s be honest, the scripting language you get isn’t really Javascript. When the documentation says that it “isn’t fully standards compliant”, they mean that you get the absolute bare minimum: var and function declarations, basic operators, and nothing else.

(Edit: Also, the fact that everything’s reference counted will absolutely bite you even if you don’t think it will. Writing Javascript without circular references just isn’t realistic, and you’ll end up leaking memory all over the place).

Jules has a new a new embedding of Ducktape in his Choc library, which might be helpful to you. It doesn’t use juce modules, but I’m guessing it wouldn’t be difficult to port. I have a lot of experience working with Juce and Spidermonkey, and I’m happy to help if you decide to go down that path.