Hello,
I have a problem using the JavaScriptEngine class in combination with a DynamicObject descendant. For example, this is my class:
class TestObject : public DynamicObject {
public:
bool hasMethod(const Identifier &methodName) const override final
{
if (methodName.toString().toStdString() == "do")
return true;
else
return DynamicObject::hasMethod(methodName);
}
juce::var invokeMethod (Identifier methodName, const var::NativeFunctionArgs &args) override final
{
if (methodName.toString().toStdString() == "do")
return var(10);
else
return DynamicObject::invokeMethod(methodName, args);
}
private:
};
and then I run this code:
JavascriptEngine javaScriptEngine;
TestObject::Ptr object(new TestObject);
TestObject::Ptr nestedObject(new TestObject);
object->setProperty("nested", var(nestedObject));
nestedObject->setProperty("x", var(10));
javaScriptEngine.registerNativeObject("object", object);
cout << javaScriptEngine.evaluate("object.nested.x").toString().toStdString() << endl; // this works: outputs 10
cout << javaScriptEngine.evaluate("object.do()").toString().toStdString() << endl; // this doesnt work: outputs undefined
cout << javaScriptEngine.evaluate("object.nested.do()").toString().toStdString() << endl; // doesnt work either
TestObject::hasMethod and TestObject::invokeMethod are never called during the evaluate() calls. Is this a bug or am I doing something wrong?
Thanks in advance!