diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-24 15:25:20 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-24 17:04:01 +0200 |
commit | 7d326bd4d1fb61663c72dbf1fc6fd57e639cfb17 (patch) | |
tree | 4589949c490017ad01ff77a64cdf0fa2971c27b5 | |
parent | 876f6d028d3c3934ca644cd369b2329dd613efb5 (diff) |
Port Qt.include() over to v4
Still doesn't quite work as it should, but that's no regression to
before neither. The reason is that the context handling is still v8
based and needs to be rewritten.
Change-Id: I51216f93d6db4ba26f8adddaeb39d8a8c62df7ee
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4include.cpp (renamed from src/qml/qml/v8/qv8include.cpp) | 109 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4include_p.h (renamed from src/qml/qml/v8/qv8include_p.h) | 24 | ||||
-rw-r--r-- | src/qml/qml/v4/v4.pri | 6 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/v8.pri | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/include.js | 2 |
8 files changed, 75 insertions, 75 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 78fd7a1452..40503de179 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -59,7 +59,6 @@ #include <private/qqmljavascriptexpression_p.h> #include <private/qv8engine_p.h> -#include <private/qv8include_p.h> #include <private/qv4functionobject_p.h> #include <private/qv4script_p.h> diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 40d38a4cae..192afe2049 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -501,7 +501,7 @@ The \c status property will be updated as the operation progresses. If provided, \a callback is invoked when the operation completes. The callback is passed the same object as is returned from the Qt.include() call. */ -// Qt.include() is implemented in qv8include.cpp +// Qt.include() is implemented in qv4include.cpp QQmlEnginePrivate::QQmlEnginePrivate(QQmlEngine *e) diff --git a/src/qml/qml/v8/qv8include.cpp b/src/qml/qml/v4/qv4include.cpp index 7a6b241535..8354277563 100644 --- a/src/qml/qml/v8/qv8include.cpp +++ b/src/qml/qml/v4/qv4include.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qv8include_p.h" +#include "qv4include_p.h" #include <QtQml/qjsengine.h> #include <QtNetwork/qnetworkrequest.h> @@ -51,18 +51,19 @@ #include <private/qv4engine_p.h> #include <private/qv4functionobject_p.h> #include <private/qv4script_p.h> +#include <private/qv4context_p.h> QT_BEGIN_NAMESPACE -QV8Include::QV8Include(const QUrl &url, QV8Engine *engine, QQmlContextData *context, - v8::Handle<v8::Object> qmlglobal, v8::Handle<v8::Function> callback) -: m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0), m_context(context) +QV4Include::QV4Include(const QUrl &url, QV8Engine *engine, QQmlContextData *context, + const QV4::Value &qmlglobal, const QV4::Value &callback) + : v4(QV8Engine::getV4(engine)), m_network(0), m_reply(0), m_url(url), m_redirectCount(0), m_context(context) { - m_qmlglobal = qmlglobal->v4Value(); - if (!callback.IsEmpty()) - m_callbackFunction = callback->v4Value(); + m_qmlglobal = qmlglobal; + if (callback.asFunctionObject()) + m_callbackFunction = callback; - m_resultObject = resultValue()->v4Value(); + m_resultObject = resultValue(v4); m_network = engine->networkAccessManager(); @@ -73,47 +74,48 @@ QV8Include::QV8Include(const QUrl &url, QV8Engine *engine, QQmlContextData *cont QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); } -QV8Include::~QV8Include() +QV4Include::~QV4Include() { delete m_reply; m_reply = 0; } -v8::Handle<v8::Object> QV8Include::resultValue(Status status) +QV4::Value QV4Include::resultValue(QV4::ExecutionEngine *v4, Status status) { + // XXX It seems inefficient to create this object from scratch each time. - v8::Handle<v8::Object> result = v8::Object::New(); - result->Set(v8::String::New("OK"), QV4::Value::fromInt32(Ok)); - result->Set(v8::String::New("LOADING"), QV4::Value::fromInt32(Loading)); - result->Set(v8::String::New("NETWORK_ERROR"), QV4::Value::fromInt32(NetworkError)); - result->Set(v8::String::New("EXCEPTION"), QV4::Value::fromInt32(Exception)); + QV4::Object *o = v4->newObject(); + o->put(v4->newString("OK"), QV4::Value::fromInt32(Ok)); + o->put(v4->newString("LOADING"), QV4::Value::fromInt32(Loading)); + o->put(v4->newString("NETWORK_ERROR"), QV4::Value::fromInt32(NetworkError)); + o->put(v4->newString("EXCEPTION"), QV4::Value::fromInt32(Exception)); - result->Set(v8::String::New("status"), QV4::Value::fromInt32(status)); + o->put(v4->newString("status"), QV4::Value::fromInt32(status)); - return result; + return QV4::Value::fromObject(o); } -void QV8Include::callback(QV8Engine *engine, v8::Handle<v8::Function> callback, v8::Handle<v8::Object> status) +void QV4Include::callback(const QV4::Value &callback, const QV4::Value &status) { - QV4::FunctionObject *f = callback->v4Value().asFunctionObject(); + QV4::FunctionObject *f = callback.asFunctionObject(); if (!f) return; - QV4::Value args[] = { status->v4Value() }; + QV4::Value args[] = { status }; QV4::ExecutionContext *ctx = f->engine()->current; try { - f->call(engine->global(), args, 1); + f->call(QV4::Value::fromObject(f->engine()->globalObject), args, 1); } catch (QV4::Exception &e) { e.accept(ctx); } } -v8::Handle<v8::Object> QV8Include::result() +QV4::Value QV4Include::result() { return m_resultObject.value(); } #define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15 -void QV8Include::finished() +void QV4Include::finished() { m_redirectCount++; @@ -145,25 +147,26 @@ void QV8Include::finished() importContext->isPragmaLibraryContext = m_context->isPragmaLibraryContext; importContext->setParent(m_context, true); - QV4::Script script(QV8Engine::getV4(m_engine), m_qmlglobal.value().asObject(), code, m_url.toString()); + QV4::Script script(v4, m_qmlglobal.value().asObject(), code, m_url.toString()); - QV4::ExecutionContext *ctx = QV8Engine::getV4(m_engine)->current; + QV4::ExecutionContext *ctx = v4->current; // ### Only used for debugging info //m_engine->contextWrapper()->addSubContext(m_qmlglobal.value(), script, importContext); + QV4::Object *o = m_resultObject.value().asObject(); try { script.parse(); script.run(); - v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("status"), QV4::Value::fromInt32(Ok)); + o->put(v4->newString("status"), QV4::Value::fromInt32(Ok)); } catch (QV4::Exception &e) { e.accept(ctx); - v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("status"), QV4::Value::fromInt32(Exception)); - v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("exception"), e.value()); + o->put(v4->newString("status"), QV4::Value::fromInt32(Exception)); + o->put(v4->newString("exception"), e.value()); } } else { - v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("status"), QV4::Value::fromInt32(NetworkError)); + m_resultObject.value().asObject()->put(v4->newString("status"), QV4::Value::fromInt32(NetworkError)); } - callback(m_engine, m_callbackFunction.value(), m_resultObject.value()); + callback(m_callbackFunction.value(), m_resultObject.value()); disconnect(); deleteLater(); @@ -172,31 +175,32 @@ void QV8Include::finished() /* Documented in qv8engine.cpp */ -QV4::Value QV8Include::include(const v8::Arguments &args) +QV4::Value QV4Include::include(QV4::SimpleCallContext *ctx) { - if (args.Length() == 0) + if (!ctx->argumentCount) return QV4::Value::undefinedValue(); - QV8Engine *engine = V8ENGINE(); + QV4::ExecutionEngine *v4 = ctx->engine; + QV8Engine *engine = v4->publicEngine->handle(); QQmlContextData *context = engine->callingContext(); - if (!context || !context->isJSContext) + if (!context || !context->isJSContext) V4THROW_ERROR("Qt.include(): Can only be called from JavaScript files"); - QUrl url(context->resolvedUrl(QUrl(args[0]->v4Value().toQString()))); - - v8::Handle<v8::Function> callbackFunction; - if (args.Length() >= 2 && args[1]->IsFunction()) - callbackFunction = v8::Handle<v8::Function>::Cast(args[1]); + QUrl url(context->resolvedUrl(QUrl(ctx->arguments[0].toQString()))); + + QV4::Value callbackFunction; + if (ctx->argumentCount >= 2 && ctx->arguments[1].asFunctionObject()) + callbackFunction = ctx->arguments[1]; QString localFile = QQmlFile::urlToLocalFileOrQrc(url); - v8::Handle<v8::Object> result; + QV4::Value result = QV4::Value::undefinedValue(); if (localFile.isEmpty()) { - QV8Include *i = new QV8Include(url, engine, context, - QV4::Value::fromObject(args.GetIsolate()->GetEngine()->qmlContextObject()), + QV4Include *i = new QV4Include(url, engine, context, + QV4::Value::fromObject(v4->qmlContextObject()), callbackFunction); result = i->result(); @@ -215,32 +219,29 @@ QV4::Value QV8Include::include(const v8::Arguments &args) importContext->url = url; importContext->setParent(context, true); - QV4::Object *qmlglobal = args.GetIsolate()->GetEngine()->qmlContextObject(); - QV4::Script script(QV8Engine::getV4(engine), qmlglobal, code, url.toString()); + QV4::Object *qmlglobal = v4->qmlContextObject(); + QV4::Script script(v4, qmlglobal, code, url.toString()); // ### Only used for debugging info // engine->contextWrapper()->addSubContext(qmlglobal, script, importContext); - QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current; + QV4::ExecutionContext *ctx = v4->current; try { script.parse(); script.run(); - result = resultValue(Ok); + result = resultValue(v4, Ok); } catch (QV4::Exception &e) { e.accept(ctx); - result = resultValue(Exception); - result->Set(v8::String::New("exception"), e.value()); + result = resultValue(v4, Exception); + result.asObject()->put(v4->newString("exception"), e.value()); } } else { - result = resultValue(NetworkError); + result = resultValue(v4, NetworkError); } - callback(engine, callbackFunction, result); + callback(callbackFunction, result); } - if (result.IsEmpty()) - return QV4::Value::undefinedValue(); - else - return result->v4Value(); + return result; } QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qv8include_p.h b/src/qml/qml/v4/qv4include_p.h index c7118c22ff..518f22b3cb 100644 --- a/src/qml/qml/v8/qv8include_p.h +++ b/src/qml/qml/v4/qv4include_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QV8INCLUDE_P_H -#define QV8INCLUDE_P_H +#ifndef QV4INCLUDE_P_H +#define QV4INCLUDE_P_H // // W A R N I N G @@ -69,7 +69,7 @@ class QQmlEngine; class QNetworkAccessManager; class QNetworkReply; class QV8Engine; -class QV8Include : public QObject +class QV4Include : public QObject { Q_OBJECT public: @@ -80,22 +80,22 @@ public: Exception = 3 }; - static QV4::Value include(const v8::Arguments &args); + static QV4::Value include(QV4::SimpleCallContext *ctx); private slots: void finished(); private: - QV8Include(const QUrl &, QV8Engine *, QQmlContextData *, - v8::Handle<v8::Object>, v8::Handle<v8::Function>); - ~QV8Include(); + QV4Include(const QUrl &url, QV8Engine *engine, QQmlContextData *context, + const QV4::Value &qmlglobal, const QV4::Value &callback); + ~QV4Include(); - v8::Handle<v8::Object> result(); + QV4::Value result(); - static v8::Handle<v8::Object> resultValue(Status status = Loading); - static void callback(QV8Engine *engine, v8::Handle<v8::Function> callback, v8::Handle<v8::Object> status); + static QV4::Value resultValue(QV4::ExecutionEngine *v4, Status status = Loading); + static void callback(const QV4::Value &callback, const QV4::Value &status); - QV8Engine *m_engine; + QV4::ExecutionEngine *v4; QNetworkAccessManager *m_network; QQmlGuard<QNetworkReply> m_reply; @@ -111,5 +111,5 @@ private: QT_END_NAMESPACE -#endif // QV8INCLUDE_P_H +#endif diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index b6f27c540f..0d1a55c229 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -51,7 +51,8 @@ SOURCES += \ $$PWD/qv4script.cpp \ $$PWD/qv4v8.cpp \ $$PWD/qv4executableallocator.cpp \ - $$PWD/qv4sequenceobject.cpp + $$PWD/qv4sequenceobject.cpp \ + $$PWD/qv4include.cpp HEADERS += \ $$PWD/qv4global_p.h \ @@ -101,7 +102,8 @@ HEADERS += \ $$PWD/qv4v8_p.h \ $$PWD/qv4util_p.h \ $$PWD/qv4executableallocator_p.h \ - $$PWD/qv4sequenceobject_p.h + $$PWD/qv4sequenceobject_p.h \ + $$PWD/qv4include_p.h OTHER_FILES += \ $$PWD/v4classgen diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 8244d02600..907b385996 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -44,7 +44,6 @@ #include "qv8contextwrapper_p.h" #include "qv8valuetypewrapper_p.h" #include "qv4sequenceobject_p.h" -#include "qv8include_p.h" #include "qjsengine_p.h" #include <private/qqmlbuiltinfunctions_p.h> @@ -74,6 +73,7 @@ #include <private/qv4regexpobject_p.h> #include <private/qv4variantobject_p.h> #include <private/qv4script_p.h> +#include <private/qv4include_p.h> Q_DECLARE_METATYPE(QList<int>) @@ -531,7 +531,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global) qt->Set(v8::String::New("Asynchronous"), QV4::Value::fromInt32(0)); qt->Set(v8::String::New("Synchronous"), QV4::Value::fromInt32(1)); - qt->Set(v8::String::New("include"), V8FUNCTION(QV8Include::include, this)); + qt->v4Value().asObject()->defineDefaultProperty(m_v4Engine, QStringLiteral("include"), QV4Include::include); qt->Set(v8::String::New("isQtObject"), V8FUNCTION(isQtObject, this)); qt->Set(v8::String::New("rgba"), V8FUNCTION(rgba, this)); qt->Set(v8::String::New("hsla"), V8FUNCTION(hsla, this)); diff --git a/src/qml/qml/v8/v8.pri b/src/qml/qml/v8/v8.pri index 80e158dc76..21e5623eed 100644 --- a/src/qml/qml/v8/v8.pri +++ b/src/qml/qml/v8/v8.pri @@ -11,7 +11,6 @@ HEADERS += \ $$PWD/qv8listwrapper_p.h \ $$PWD/qv8valuetypewrapper_p.h \ $$PWD/qv4jsonwrapper_p.h \ - $$PWD/qv8include_p.h \ $$PWD/qv4domerrors_p.h \ $$PWD/qv4sqlerrors_p.h \ $$PWD/qqmlbuiltinfunctions_p.h \ @@ -25,7 +24,6 @@ SOURCES += \ $$PWD/qv8listwrapper.cpp \ $$PWD/qv8valuetypewrapper.cpp \ $$PWD/qv4jsonwrapper.cpp \ - $$PWD/qv8include.cpp \ $$PWD/qv4domerrors.cpp \ $$PWD/qv4sqlerrors.cpp \ $$PWD/qqmlbuiltinfunctions.cpp diff --git a/tests/auto/qml/qqmlecmascript/data/include.js b/tests/auto/qml/qqmlecmascript/data/include.js index 232fd808f8..489e322ef0 100644 --- a/tests/auto/qml/qqmlecmascript/data/include.js +++ b/tests/auto/qml/qqmlecmascript/data/include.js @@ -3,6 +3,6 @@ var test2 = false var test3 = false function go() { - Qt.include("js/include2.js"); + console.log(Qt.include("js/include2.js").status); } |