In the process of updating to JUCE 8 we’ve noticed that all of our keyboard shortcuts have broken which makes the app pretty unusable. We use the JS engine extensively.
I’ve got two issues, one which I have a work around for so I’ll post that separately.
The problem is best described by this failing test:
void runObjectTest()
{
auto createObj = []
{
auto obj = new juce::DynamicObject();
obj->setMethod ("getVal",
[] (const auto&) { return 42; });
return obj;
};
auto createObjGetter = [&]
{
auto objGetter = new juce::DynamicObject();
objGetter->setMethod ("getObj",
[&] (const auto&) { return createObj(); });
return objGetter;
};
auto createEngine = [&]
{
auto engine = std::make_unique<juce::JavascriptEngine>();
engine->registerNativeObject ("Obj", createObj());
engine->registerNativeObject ("ObjGetter", createObjGetter());
return engine;
};
{
auto engine = createEngine();
auto res = juce::Result::fail ("");
auto val = engine->evaluate ("let objGetter = ObjGetter; \
let obj = objGetter.getObj(); \
obj.getVal();",
&res);
jassert (res.wasOk());
jassert (static_cast<int> (val) == 42);
}
}
The problem seems to be that the js calls a C++ function that returns an object that has a function member. It seems like there’s no provision for this when converting from juce::var to choc::value::Value in VariantConverter<choc::value::Value>::fromVar.
I don’t actually think this can be handled by choc so it might need to be a special case in the calling juceToQuickJs function.
The above example looks contrived but it’s a distilled problem we face as we have lots of C++ objects represented in JS that call in to native code exactly like this.
