Fix diagnostic error message when put fails because of a read-only property
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 13 Jun 2013 05:46:26 +0000 (07:46 +0200)
committerLars Knoll <lars.knoll@digia.com>
Thu, 13 Jun 2013 06:54:04 +0000 (08:54 +0200)
Change-Id: I9310c160386e9610d76ae0a8b3228b22757d5a02
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/qv4object.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index e8cf23d..7394c1f 100644 (file)
@@ -720,8 +720,12 @@ void Object::internalPut(ExecutionContext *ctx, String *name, const Value &value
     }
 
   reject:
-    if (ctx->strictMode)
-        ctx->throwTypeError();
+    if (ctx->strictMode) {
+        QString message = QStringLiteral("Cannot assign to read-only property \"");
+        message += name->toQString();
+        message += QLatin1Char('\"');
+        ctx->throwTypeError(message);
+    }
 }
 
 void Object::internalPutIndexed(ExecutionContext *ctx, uint index, const Value &value)
index a9a63d5..cdf46c4 100644 (file)
@@ -3618,7 +3618,8 @@ void tst_qqmlecmascript::singletonType_data()
     QTest::newRow("qobject, writing + readonly constraints")
             << testFileUrl("singletontype/qobjectSingletonTypeWriting.qml")
             << QString()
-            << (QStringList() << QString(testFileUrl("singletontype/qobjectSingletonTypeWriting.qml").toString() + QLatin1String(":15: Error: Cannot assign to read-only property \"qobjectTestProperty\"")))
+            << (QStringList() <<
+                    QString(testFileUrl("singletontype/qobjectSingletonTypeWriting.qml").toString() + QLatin1String(":15: Error: Cannot assign to read-only property \"qobjectTestProperty\"")))
             << (QStringList() << "readOnlyProperty" << "writableProperty" << "writableFinalProperty")
             << (QVariantList() << 20 << 50 << 10)
             << (QStringList() << "firstProperty" << "secondProperty")
@@ -3629,7 +3630,8 @@ void tst_qqmlecmascript::singletonType_data()
     QTest::newRow("script, writing + readonly constraints")
             << testFileUrl("singletontype/scriptSingletonTypeWriting.qml")
             << QString()
-            << (QStringList() << QString(testFileUrl("singletontype/scriptSingletonTypeWriting.qml").toString() + QLatin1String(":21: Error: Cannot assign to read-only property \"scriptTestProperty\"")))
+            << (QStringList() <<
+                    QString(testFileUrl("singletontype/scriptSingletonTypeWriting.qml").toString() + QLatin1String(":21: TypeError: Cannot assign to read-only property \"scriptTestProperty\"")))
             << (QStringList() << "readBack" << "unchanged")
             << (QVariantList() << 15 << 42)
             << (QStringList() << "firstProperty" << "secondProperty")