# JavaScriptEngine/DynamicObject::getProperty not called

**URL:** <https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280>\
**Category:** General JUCE discussion\
**Created:** [August 10, 2015, 12:08pm UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280 "2015-08-10T12:08:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [August 10, 2015, 12:08pm UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/1 "2015-08-10T12:08:05Z")

</div>

All of the involved code would be too messy to post here but I hope this&nbsp;is enough...In the following DynamicObject implementation, getProperty is never called with the "windowtitle" property name :

```
class OSCJSObject : public DynamicObject
{
public:
    // constructor etc omitted here
    bool hasProperty(const Identifier& id) const
    {
        if (id == Identifier("windowtitle"))
            return true;
        return DynamicObject::hasProperty(id);
    }
    
    const var& getProperty(const Identifier& id) const
    {
        if (id == Identifier("windowtitle"))
        {
            return m_component->getParentComponent()->getName();
        }
        
        return DynamicObject::getProperty(id);
    }
    
};
```

Most curiously and annoyingly, setProperty DOES work as expected. So JavaScript code like :

app.windowtitle="test title"; works.

But code like :

app.print(app.windowtitle); does not. "undefined" is printed out. (The print method has been tested to work.)

My first suspicion was that I got the getProperty signature wrong in some subtle way. However, the function IS&nbsp;called by Juce sometimes, it is looking for a property "prototype" (or some such) many times. If I put a breakpoint at the&nbsp;

return m\_component-\>getParentComponent()-\>getName(); line, it is never triggered. Using Visual Studio 2015 Community Edition on Windows 7 64 bit here.

&nbsp;

-

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 11, 2015, 2:13pm UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/2 "2015-08-11T14:13:08Z")

</div>

Yeah, for a lot of the JS parser, it'll use the DynamicObject's NamedValueSet directly, instead of going via the getProperty virtual method - this is mainly done for speed and simplicity, but does make it hard to create active properties that perform some sort of actual task.&nbsp;

The "fix" would be to actually use the NamedValueSet to store this value, and update it when it changes, or to implement it as a function rather than a property.

I've thought about changing DynamicObject and replacing the two property accessors with a single method that returns a var\*, and that would be a breaking change for people's code.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [August 11, 2015, 8:02pm UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/3 "2015-08-11T20:02:52Z")

</div>

OK, thanks. I'll reconsider how I will deal with this stuff.&nbsp;

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [August 13, 2015, 11:56am UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/4 "2015-08-13T11:56:00Z")

</div>

It's a shame we can't use overload getProperty and hasProperty when using the JavaScript engine. This would make the scripting a lot more flexible. I can understand you use the NamedValueSet directly to improve speed but you don't state it anywhere that you can't properly overload the DynamicObject&nbsp;methods, so these questions will keep popping up because right now the implementation is not clear. I would argue that it's ok to make changes that break people's code as i think just a few percent of the&nbsp;JUCE user base is actually using your scripting engine atm. I think there is still a lot to improve on the scripting part and at least making sure the use of DynamicObjects is correct will make it easier for us to build on it.&nbsp;  
I really like the fact that you've added the Javascript features and i would really like to see it to mature it even more. It's easy to use just because of the DynamicObject approach.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 13, 2015, 12:00pm UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/5 "2015-08-13T12:00:10Z")

</div>

Agreed! Will think about this. Like I said above, the ideal way to do this would be to change the way that&nbsp;DynamicObject works, so it's a question of deciding whether this is important enough to justify&nbsp;breaking&nbsp;people's existing code.

---

<div class="post-metadata">

**Author:** ![rebbur](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@rebbur](https://forum.juce.com/u/rebbur)\
**Post date:** [August 14, 2015, 10:05am UTC](https://forum.juce.com/t/javascriptengine-dynamicobject-getproperty-not-called/15280/6 "2015-08-14T10:05:29Z")

</div>

Cool, good to hear you want to pick this up. I'll see what you guys come up with.
