diff options
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 27 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index f2716e4..92c987c 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1738,7 +1738,7 @@ QScriptValue QScriptValue::property(quint32 arrayIndex, void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value, const PropertyFlags &flags) { - Q_D(const QScriptValue); + Q_D(QScriptValue); if (!d || !d->isObject()) return; if (value.engine() && (value.engine() != engine())) { @@ -1752,7 +1752,9 @@ void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value, JSC::asObject(d->jscValue)->deleteProperty(exec, arrayIndex, /*checkDontDelete=*/false); } else { if ((flags & QScriptValue::PropertyGetter) || (flags & QScriptValue::PropertySetter)) { - Q_ASSERT_X(false, Q_FUNC_INFO, "property getters and setters not implemented"); + // fall back to string-based setProperty(), since there is no + // JSC::JSObject::defineGetter(unsigned) + d->setProperty(JSC::Identifier::from(exec, arrayIndex), value, flags); } else { if (flags != QScriptValue::KeepExistingFlags) { // if (JSC::asObject(d->jscValue)->hasOwnProperty(exec, arrayIndex)) diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 6b64e76..5636c54 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -87,6 +87,7 @@ private slots: void getSetPrototype(); void getSetScope(); void getSetProperty(); + void arrayElementGetterSetter(); void getSetData(); void getSetScriptClass(); void call(); @@ -2115,6 +2116,32 @@ void tst_QScriptValue::getSetProperty() QVERIFY(object.propertyFlags(foo) == 0); } +void tst_QScriptValue::arrayElementGetterSetter() +{ + QScriptEngine eng; + QScriptValue obj = eng.newObject(); + obj.setProperty(1, eng.newFunction(getterSetter), QScriptValue::PropertyGetter|QScriptValue::PropertySetter); + { + QScriptValue num(123); + obj.setProperty("x", num); + QScriptValue ret = obj.property(1); + QVERIFY(ret.isValid()); + QVERIFY(ret.equals(num)); + } + { + QScriptValue num(456); + obj.setProperty(1, num); + QScriptValue ret = obj.property(1); + QVERIFY(ret.isValid()); + QVERIFY(ret.equals(num)); + QVERIFY(ret.equals(obj.property("1"))); + } + QCOMPARE(obj.propertyFlags("1"), QScriptValue::PropertyGetter|QScriptValue::PropertySetter); + + obj.setProperty(1, QScriptValue(), QScriptValue::PropertyGetter|QScriptValue::PropertySetter); + QVERIFY(obj.propertyFlags("1") == 0); +} + void tst_QScriptValue::getSetPrototype() { QScriptEngine eng; |