return;
}
+ PropertyAttributes attrs;
+ Property *pd = wrapper->__getOwnProperty__(name, &attrs);
+ if (pd) {
+ wrapper->putValue(pd, attrs, value);
+ return;
+ }
+
if (wrapper->isNullWrapper) {
if (wrapper && wrapper->readOnly) {
QString error = QLatin1String("Invalid write to global property \"") + name->toQString() +
return;
}
- PropertyAttributes attrs;
- Property *pd = wrapper->__getOwnProperty__(name, &attrs);
- if (pd) {
- wrapper->putValue(pd, attrs, value);
- return;
- }
-
// Its possible we could delay the calculation of the "actual" context (in the case
// of sub contexts) until it is definately needed.
QQmlContextData *context = wrapper->getContext();
void script_included();
void scriptError_onLoad();
void scriptError_onCall();
+ void script_function();
+ void script_var();
+ void script_global();
void stressDispose();
private:
waitForEchoMessage(worker);
const QMetaObject *mo = worker->metaObject();
- QEXPECT_FAIL("", "It is not possible to write to the global object right now", Continue);
QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).toString(), value + " World");
qApp->processEvents();
delete worker;
}
+void tst_QQuickWorkerScript::script_function()
+{
+ QQmlComponent component(&m_engine, testFileUrl("worker_function.qml"));
+ QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QString value("Hello");
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+
+ const QMetaObject *mo = worker->metaObject();
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).toString(), value + " World");
+
+ qApp->processEvents();
+ delete worker;
+}
+
+void tst_QQuickWorkerScript::script_var()
+{
+ QQmlComponent component(&m_engine, testFileUrl("worker_var.qml"));
+ QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QString value("Hello");
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+ waitForEchoMessage(worker);
+
+ const QMetaObject *mo = worker->metaObject();
+ QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).toString(), value + " World");
+
+ qApp->processEvents();
+ delete worker;
+}
+
+void tst_QQuickWorkerScript::script_global()
+{
+ {
+ QQmlComponent component(&m_engine, testFileUrl("worker_global.qml"));
+ QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QString value("Hello");
+
+ QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler);
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+
+ QTRY_COMPARE(qquickworkerscript_lastWarning,
+ testFileUrl("script_global.js").toString() + QLatin1String(":2: Invalid write to global property \"world\""));
+
+ qInstallMessageHandler(previousMsgHandler);
+
+ qApp->processEvents();
+ delete worker;
+ }
+
+ {
+ QQmlComponent component(&m_engine, testFileUrl("worker_global2.qml"));
+ QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
+ QVERIFY(worker != 0);
+
+ QString value("Hello");
+
+ QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler);
+
+ QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
+
+ QTRY_COMPARE(qquickworkerscript_lastWarning,
+ testFileUrl("script_global.js").toString() + QLatin1String(":2: Invalid write to global property \"world\""));
+
+ qInstallMessageHandler(previousMsgHandler);
+
+ qApp->processEvents();
+ delete worker;
+ }
+}
+
// Rapidly create and destroy worker scripts to test resources are being disposed
// in the correct isolate
void tst_QQuickWorkerScript::stressDispose()