1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added support for accessing the properties of a javascript object via the subscript operator

This commit is contained in:
hogliux 2016-09-08 10:49:31 +01:00
parent 913a868d8d
commit 1f2eaeb47f

View file

@ -412,9 +412,16 @@ struct JavascriptEngine::RootObject : public DynamicObject
var getResult (const Scope& s) const override
{
var arrayVar (object->getResult (s)); // must stay alive for the scope of this method
var key = index->getResult (s);
if (const Array<var>* array = arrayVar.getArray())
return (*array) [static_cast<int> (index->getResult (s))];
if (key.isInt() || key.isInt64() || key.isDouble())
return (*array) [static_cast<int> (key)];
if (DynamicObject* o = arrayVar.getDynamicObject())
if (key.isString())
if (const var* v = getPropertyPointer (o, Identifier (key)))
return *v;
return var::undefined();
}
@ -422,15 +429,28 @@ struct JavascriptEngine::RootObject : public DynamicObject
void assign (const Scope& s, const var& newValue) const override
{
var arrayVar (object->getResult (s)); // must stay alive for the scope of this method
var key = index->getResult (s);
if (Array<var>* array = arrayVar.getArray())
{
const int i = index->getResult (s);
while (array->size() < i)
array->add (var::undefined());
if (key.isInt() || key.isInt64() || key.isDouble())
{
const int i = key;
while (array->size() < i)
array->add (var::undefined());
array->set (i, newValue);
return;
array->set (i, newValue);
return;
}
}
if (DynamicObject* o = arrayVar.getDynamicObject())
{
if (key.isString())
{
o->setProperty (Identifier (key), newValue);
return;
}
}
Expression::assign (s, newValue);