diff options
Diffstat (limited to 'src/qml/jsruntime/qv4include.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4include.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index 29f83da522..be8057e9f5 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -41,8 +41,10 @@ #include "qv4scopedvalue_p.h" #include <QtQml/qjsengine.h> +#if QT_CONFIG(qml_network) #include <QtNetwork/qnetworkrequest.h> #include <QtNetwork/qnetworkreply.h> +#endif #include <QtCore/qfile.h> #include <QtQml/qqmlfile.h> @@ -57,7 +59,10 @@ QT_BEGIN_NAMESPACE QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &callback) - : v4(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0) + : v4(engine), m_url(url) +#if QT_CONFIG(qml_network) + , m_redirectCount(0), m_network(0) , m_reply(0) +#endif { if (qmlContext) m_qmlContext.set(engine, *qmlContext); @@ -66,6 +71,7 @@ QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, m_resultObject.set(v4, resultValue(v4)); +#if QT_CONFIG(qml_network) m_network = engine->v8Engine->networkAccessManager(); QNetworkRequest request; @@ -73,11 +79,17 @@ QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, m_reply = m_network->get(request); QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); +#else + finished(); +#endif } QV4Include::~QV4Include() { - delete m_reply; m_reply = 0; +#if QT_CONFIG(qml_network) + delete m_reply; + m_reply = 0; +#endif } QV4::ReturnedValue QV4Include::resultValue(QV4::ExecutionEngine *v4, Status status) @@ -110,7 +122,7 @@ void QV4Include::callback(const QV4::Value &callback, const QV4::Value &status) QV4::ScopedCallData callData(scope, 1); callData->thisObject = v4->globalObject->asReturnedValue(); callData->args[0] = status; - f->call(callData); + f->call(scope, callData); if (scope.hasException()) scope.engine->catchException(); } @@ -123,6 +135,7 @@ QV4::ReturnedValue QV4Include::result() #define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15 void QV4Include::finished() { +#if QT_CONFIG(qml_network) m_redirectCount++; if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) { @@ -166,6 +179,12 @@ void QV4Include::finished() } else { resultObj->put(status, QV4::ScopedValue(scope, QV4::Primitive::fromInt32(NetworkError))); } +#else + QV4::Scope scope(v4); + QV4::ScopedObject resultObj(scope, m_resultObject.value()); + QV4::ScopedString status(scope, v4->newString(QStringLiteral("status"))); + resultObj->put(status, QV4::ScopedValue(scope, QV4::Primitive::fromInt32(NetworkError))); +#endif // qml_network QV4::ScopedValue cb(scope, m_callbackFunction.value()); callback(cb, resultObj); @@ -188,14 +207,15 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) if (!context || !context->isJSContext) V4THROW_ERROR("Qt.include(): Can only be called from JavaScript files"); - QUrl url(scope.engine->resolvedUrl(ctx->args()[0].toQStringNoThrow())); - if (scope.engine->qmlEngine() && scope.engine->qmlEngine()->urlInterceptor()) - url = scope.engine->qmlEngine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::JavaScriptFile); - QV4::ScopedValue callbackFunction(scope, QV4::Primitive::undefinedValue()); if (ctx->argc() >= 2 && ctx->args()[1].as<QV4::FunctionObject>()) callbackFunction = ctx->args()[1]; +#if QT_CONFIG(qml_network) + QUrl url(scope.engine->resolvedUrl(ctx->args()[0].toQStringNoThrow())); + if (scope.engine->qmlEngine() && scope.engine->qmlEngine()->urlInterceptor()) + url = scope.engine->qmlEngine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::JavaScriptFile); + QString localFile = QQmlFile::urlToLocalFileOrQrc(url); QV4::ScopedValue result(scope); @@ -243,6 +263,12 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) } return result->asReturnedValue(); +#else + QV4::ScopedValue result(scope); + result = resultValue(scope.engine, NetworkError); + callback(callbackFunction, result); + return result->asReturnedValue(); +#endif } QT_END_NAMESPACE |