diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-29 16:25:26 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-06-04 13:02:12 +0000 |
commit | adb58fe81e2f79d5ba10eda3ed6187349fda40de (patch) | |
tree | cbb77ab97b03d7bcc56723320bd889309cc3e1e1 /src/qml/jsruntime/qv4object.cpp | |
parent | 8e23235181eb25faf99324e136412da23dc8386f (diff) |
Fix Object::defineAccessorProperty
Create setter and getter functions with proper names and make
the property configurable to be compliant with the ES7 spec.
Change-Id: I13b24f540fdd3261cf29b660aa3393d661acacfd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index cf988f093a..0d8fd799e6 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -189,9 +189,22 @@ void Object::defineAccessorProperty(StringOrSymbol *name, jsCallFunction getter, ExecutionEngine *v4 = engine(); QV4::Scope scope(v4); ScopedProperty p(scope); - p->setGetter(ScopedFunctionObject(scope, (getter ? FunctionObject::createBuiltinFunction(v4, name, getter, 0) : nullptr))); - p->setSetter(ScopedFunctionObject(scope, (setter ? FunctionObject::createBuiltinFunction(v4, name, setter, 1) : nullptr))); - insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); + QString n = name->toQString(); + if (n.at(0) == QLatin1Char('@')) + n = QChar::fromLatin1('[') + n.midRef(1) + QChar::fromLatin1(']'); + if (getter) { + ScopedString getName(scope, v4->newString(QString::fromLatin1("get ") + n)); + p->setGetter(ScopedFunctionObject(scope, FunctionObject::createBuiltinFunction(v4, getName, getter, 0))); + } else { + p->setGetter(nullptr); + } + if (setter) { + ScopedString setName(scope, v4->newString(QString::fromLatin1("set ") + n)); + p->setSetter(ScopedFunctionObject(scope, FunctionObject::createBuiltinFunction(v4, setName, setter, 0))); + } else { + p->setSetter(nullptr); + } + insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable); } |