summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-05-14 04:00:21 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-05-14 04:00:21 (GMT)
commit17a5c63a499b10036dc14135457ec22c89270f9a (patch)
tree38d3606d447631f3c0a861c25a128088c9b0c4be
parent677d06cecb44c482c72d1e987e3f923a73fcedd2 (diff)
downloadQt-17a5c63a499b10036dc14135457ec22c89270f9a.zip
Qt-17a5c63a499b10036dc14135457ec22c89270f9a.tar.gz
Qt-17a5c63a499b10036dc14135457ec22c89270f9a.tar.bz2
Missing files from 645b9ee9dd6e0576542cc61872ecedb408ca8a89
Grrr
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass.cpp46
-rw-r--r--src/declarative/qml/qdeclarativecontextscriptclass_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass_p.h1
-rw-r--r--src/declarative/qml/qdeclarativeinclude.cpp10
-rw-r--r--src/declarative/qml/qdeclarativeinclude_p.h3
-rw-r--r--src/declarative/qml/qml.pri2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp111
10 files changed, 182 insertions, 12 deletions
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index b61b8cb..6a13f15 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -659,7 +659,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
if (iter == enginePriv->m_sharedScriptImports.end()) {
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- scriptContext->pushScope(enginePriv->contextClass->newContext(0, 0));
+ scriptContext->pushScope(enginePriv->contextClass->newUrlContext(url));
scriptContext->pushScope(enginePriv->globalClass->globalObject());
QScriptValue scope = scriptEngine->newObject();
@@ -685,7 +685,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
- scriptContext->pushScope(enginePriv->contextClass->newContext(this, 0));
+ scriptContext->pushScope(enginePriv->contextClass->newUrlContext(this, 0, url));
scriptContext->pushScope(enginePriv->globalClass->globalObject());
QScriptValue scope = scriptEngine->newObject();
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
index 1336a1a..1ebedbb 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
@@ -51,11 +51,13 @@ QT_BEGIN_NAMESPACE
struct ContextData : public QScriptDeclarativeClass::Object {
ContextData() : overrideObject(0), isSharedContext(true) {}
- ContextData(QDeclarativeContextData *c, QObject *o) : context(c), scopeObject(o), overrideObject(0), isSharedContext(false) {}
+ ContextData(QDeclarativeContextData *c, QObject *o)
+ : context(c), scopeObject(o), overrideObject(0), isSharedContext(false), isUrlContext(false) {}
QDeclarativeGuardedContextData context;
QDeclarativeGuard<QObject> scopeObject;
QObject *overrideObject;
- bool isSharedContext;
+ bool isSharedContext:1;
+ bool isUrlContext:1;
QDeclarativeContextData *getContext(QDeclarativeEngine *engine) {
if (isSharedContext) {
@@ -74,6 +76,18 @@ struct ContextData : public QScriptDeclarativeClass::Object {
}
};
+struct UrlContextData : public ContextData {
+ UrlContextData(QDeclarativeContextData *c, QObject *o, const QString &u)
+ : ContextData(c, o), url(u) {
+ isUrlContext = true;
+ }
+ UrlContextData(const QString &u)
+ : ContextData(0, 0), url(u) {
+ isUrlContext = true;
+ }
+ QString url;
+};
+
/*
The QDeclarativeContextScriptClass handles property access for a QDeclarativeContext
via QtScript.
@@ -95,6 +109,21 @@ QScriptValue QDeclarativeContextScriptClass::newContext(QDeclarativeContextData
return newObject(scriptEngine, this, new ContextData(context, scopeObject));
}
+QScriptValue QDeclarativeContextScriptClass::newUrlContext(QDeclarativeContextData *context, QObject *scopeObject,
+ const QString &url)
+{
+ QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+
+ return newObject(scriptEngine, this, new UrlContextData(context, scopeObject, url));
+}
+
+QScriptValue QDeclarativeContextScriptClass::newUrlContext(const QString &url)
+{
+ QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+
+ return newObject(scriptEngine, this, new UrlContextData(url));
+}
+
QScriptValue QDeclarativeContextScriptClass::newSharedContext()
{
QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
@@ -111,6 +140,19 @@ QDeclarativeContextData *QDeclarativeContextScriptClass::contextFromValue(const
return data->getContext(engine);
}
+QUrl QDeclarativeContextScriptClass::urlFromValue(const QScriptValue &v)
+{
+ if (scriptClass(v) != this)
+ return QUrl();
+
+ ContextData *data = (ContextData *)object(v);
+ if (data->isUrlContext) {
+ return QUrl(static_cast<UrlContextData *>(data)->url);
+ } else {
+ return QUrl();
+ }
+}
+
QObject *QDeclarativeContextScriptClass::setOverrideObject(QScriptValue &v, QObject *override)
{
if (scriptClass(v) != this)
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
index 1936d38..1215b00 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
@@ -68,9 +68,13 @@ public:
~QDeclarativeContextScriptClass();
QScriptValue newContext(QDeclarativeContextData *, QObject * = 0);
+ QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &);
+ QScriptValue newUrlContext(const QString &);
QScriptValue newSharedContext();
QDeclarativeContextData *contextFromValue(const QScriptValue &);
+ QUrl urlFromValue(const QScriptValue &);
+
QObject *setOverrideObject(QScriptValue &, QObject *);
protected:
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 94e6771..5cb59da 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -67,6 +67,7 @@
#include "qdeclarativeextensioninterface.h"
#include "private/qdeclarativelist_p.h"
#include "private/qdeclarativetypenamecache_p.h"
+#include "private/qdeclarativeinclude_p.h"
#include <QtCore/qmetaobject.h>
#include <QScriptClass>
@@ -204,6 +205,7 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
// XXX used to add Qt.Sound class.
//types
+ qtObject.setProperty(QLatin1String("include"), newFunction(QDeclarativeInclude::include, 2));
qtObject.setProperty(QLatin1String("isQtObject"), newFunction(QDeclarativeEnginePrivate::isQtObject, 1));
qtObject.setProperty(QLatin1String("rgba"), newFunction(QDeclarativeEnginePrivate::rgba, 4));
qtObject.setProperty(QLatin1String("hsla"), newFunction(QDeclarativeEnginePrivate::hsla, 4));
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
index 1b34aee..7690edd 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
@@ -76,6 +76,7 @@ public:
void explicitSetProperty(const QString &, const QScriptValue &);
const QScriptValue &globalObject() const { return m_globalObject; }
+
const QSet<QString> &illegalNames() const { return m_illegalNames; }
private:
diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp
index 97af5b5..b886935 100644
--- a/src/declarative/qml/qdeclarativeinclude.cpp
+++ b/src/declarative/qml/qdeclarativeinclude.cpp
@@ -76,8 +76,7 @@ QDeclarativeInclude::QDeclarativeInclude(const QUrl &url,
QDeclarativeInclude::~QDeclarativeInclude()
{
- if (m_reply)
- delete m_reply;
+ delete m_reply;
}
QScriptValue QDeclarativeInclude::resultValue(QScriptEngine *engine, Status status)
@@ -116,7 +115,7 @@ void QDeclarativeInclude::finished()
QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
m_url = m_url.resolved(redirect.toUrl());
- delete m_reply;
+ delete m_reply;
QNetworkRequest request;
request.setUrl(m_url);
@@ -149,6 +148,7 @@ void QDeclarativeInclude::finished()
if (m_scriptEngine->hasUncaughtException()) {
m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Exception));
m_result.setProperty(QLatin1String("exception"), m_scriptEngine->uncaughtException());
+ m_scriptEngine->clearExceptions();
} else {
m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Ok));
}
@@ -158,7 +158,8 @@ void QDeclarativeInclude::finished()
callback(m_scriptEngine, m_callback, m_result);
- delete this;
+ disconnect();
+ deleteLater();
}
void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback, QScriptValue &status)
@@ -237,6 +238,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e
if (engine->hasUncaughtException()) {
result = resultValue(engine, Exception);
result.setProperty(QLatin1String("exception"), engine->uncaughtException());
+ engine->clearExceptions();
} else {
result = resultValue(engine, Ok);
}
diff --git a/src/declarative/qml/qdeclarativeinclude_p.h b/src/declarative/qml/qdeclarativeinclude_p.h
index 28c49ea..9678e42 100644
--- a/src/declarative/qml/qdeclarativeinclude_p.h
+++ b/src/declarative/qml/qdeclarativeinclude_p.h
@@ -58,6 +58,7 @@
#include <QtScript/qscriptvalue.h>
#include <private/qdeclarativecontext_p.h>
+#include <private/qdeclarativeguard_p.h>
QT_BEGIN_NAMESPACE
@@ -96,7 +97,7 @@ private:
QDeclarativeEngine *m_engine;
QScriptEngine *m_scriptEngine;
QNetworkAccessManager *m_network;
- QNetworkReply *m_reply;
+ QDeclarativeGuard<QNetworkReply> m_reply;
QUrl m_url;
int m_redirectCount;
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index dab9767..12f9794 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -9,6 +9,7 @@ SOURCES += \
$$PWD/qdeclarativeproperty.cpp \
$$PWD/qdeclarativecomponent.cpp \
$$PWD/qdeclarativecontext.cpp \
+ $$PWD/qdeclarativeinclude.cpp \
$$PWD/qdeclarativecustomparser.cpp \
$$PWD/qdeclarativepropertyvaluesource.cpp \
$$PWD/qdeclarativepropertyvalueinterceptor.cpp \
@@ -92,6 +93,7 @@ HEADERS += \
$$PWD/qdeclarativeinfo.h \
$$PWD/qdeclarativeproperty_p.h \
$$PWD/qdeclarativecontext_p.h \
+ $$PWD/qdeclarativeinclude_p.h \
$$PWD/qdeclarativecompositetypedata_p.h \
$$PWD/qdeclarativecompositetypemanager_p.h \
$$PWD/qdeclarativelist.h \
diff --git a/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro b/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
index eabed26..c907be5 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
+++ b/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
@@ -1,13 +1,18 @@
load(qttest_p4)
-contains(QT_CONFIG,declarative): QT += declarative script
+contains(QT_CONFIG,declarative): QT += declarative script network
macx:CONFIG -= app_bundle
SOURCES += tst_qdeclarativeecmascript.cpp \
- testtypes.cpp
-HEADERS += testtypes.h
+ testtypes.cpp \
+ ../shared/testhttpserver.cpp
+HEADERS += testtypes.h \
+ ../shared/testhttpserver.h
+INCLUDEPATH += ../shared
# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage
# LIBS += -lgcov
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
CONFIG += parallel_test
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 8c9290f..b8faa7c 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -51,6 +51,7 @@
#include <private/qdeclarativeengine_p.h>
#include <private/qdeclarativeglobalscriptclass_p.h>
#include "testtypes.h"
+#include "testhttpserver.h"
/*
This test covers evaluation of ECMAScript expressions and bindings from within
@@ -149,6 +150,8 @@ private slots:
void eval();
void function();
+ void include();
+
void callQtInvokables();
private:
QDeclarativeEngine engine;
@@ -2361,6 +2364,114 @@ void tst_qdeclarativeecmascript::function()
delete o;
}
+#define TRY_WAIT(expr) \
+ do { \
+ for (int ii = 0; ii < 6; ++ii) { \
+ if ((expr)) break; \
+ QTest::qWait(50); \
+ } \
+ QVERIFY((expr)); \
+ } while (false)
+
+// Test the "Qt.include" method
+void tst_qdeclarativeecmascript::include()
+{
+ // Non-library relative include
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("include.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ QCOMPARE(o->property("test0").toInt(), 99);
+ QCOMPARE(o->property("test1").toBool(), true);
+ QCOMPARE(o->property("test2").toBool(), true);
+ QCOMPARE(o->property("test2_1").toBool(), true);
+ QCOMPARE(o->property("test3").toBool(), true);
+ QCOMPARE(o->property("test3_1").toBool(), true);
+
+ delete o;
+ }
+
+ // Library relative include
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("include_shared.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ QCOMPARE(o->property("test0").toInt(), 99);
+ QCOMPARE(o->property("test1").toBool(), true);
+ QCOMPARE(o->property("test2").toBool(), true);
+ QCOMPARE(o->property("test2_1").toBool(), true);
+ QCOMPARE(o->property("test3").toBool(), true);
+ QCOMPARE(o->property("test3_1").toBool(), true);
+
+ delete o;
+ }
+
+ // Callback
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("include_callback.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ QCOMPARE(o->property("test1").toBool(), true);
+ QCOMPARE(o->property("test2").toBool(), true);
+ QCOMPARE(o->property("test3").toBool(), true);
+ QCOMPARE(o->property("test4").toBool(), true);
+ QCOMPARE(o->property("test5").toBool(), true);
+ QCOMPARE(o->property("test6").toBool(), true);
+
+ delete o;
+ }
+
+ // Remote - success
+ {
+ TestHTTPServer server(8111);
+ QVERIFY(server.isValid());
+ server.serveDirectory(SRCDIR "/data");
+
+ QDeclarativeComponent component(&engine, TEST_FILE("include_remote.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ TRY_WAIT(o->property("done").toBool() == true);
+ TRY_WAIT(o->property("done2").toBool() == true);
+
+ QCOMPARE(o->property("test1").toBool(), true);
+ QCOMPARE(o->property("test2").toBool(), true);
+ QCOMPARE(o->property("test3").toBool(), true);
+ QCOMPARE(o->property("test4").toBool(), true);
+ QCOMPARE(o->property("test5").toBool(), true);
+
+ QCOMPARE(o->property("test6").toBool(), true);
+ QCOMPARE(o->property("test7").toBool(), true);
+ QCOMPARE(o->property("test8").toBool(), true);
+ QCOMPARE(o->property("test9").toBool(), true);
+ QCOMPARE(o->property("test10").toBool(), true);
+
+ delete o;
+ }
+
+ // Remote - error
+ {
+ TestHTTPServer server(8111);
+ QVERIFY(server.isValid());
+ server.serveDirectory(SRCDIR "/data");
+
+ QDeclarativeComponent component(&engine, TEST_FILE("include_remote_missing.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ TRY_WAIT(o->property("done").toBool() == true);
+
+ QCOMPARE(o->property("test1").toBool(), true);
+ QCOMPARE(o->property("test2").toBool(), true);
+ QCOMPARE(o->property("test3").toBool(), true);
+
+ delete o;
+ }
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"