aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8/qv8include.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-24 15:25:20 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-05-24 17:04:01 +0200
commit7d326bd4d1fb61663c72dbf1fc6fd57e639cfb17 (patch)
tree4589949c490017ad01ff77a64cdf0fa2971c27b5 /src/qml/qml/v8/qv8include.cpp
parent876f6d028d3c3934ca644cd369b2329dd613efb5 (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>
Diffstat (limited to 'src/qml/qml/v8/qv8include.cpp')
-rw-r--r--src/qml/qml/v8/qv8include.cpp246
1 files changed, 0 insertions, 246 deletions
diff --git a/src/qml/qml/v8/qv8include.cpp b/src/qml/qml/v8/qv8include.cpp
deleted file mode 100644
index 7a6b241535..0000000000
--- a/src/qml/qml/v8/qv8include.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qv8include_p.h"
-
-#include <QtQml/qjsengine.h>
-#include <QtNetwork/qnetworkrequest.h>
-#include <QtNetwork/qnetworkreply.h>
-#include <QtCore/qfile.h>
-#include <QtQml/qqmlfile.h>
-
-#include <private/qqmlengine_p.h>
-#include <private/qv4engine_p.h>
-#include <private/qv4functionobject_p.h>
-#include <private/qv4script_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)
-{
- m_qmlglobal = qmlglobal->v4Value();
- if (!callback.IsEmpty())
- m_callbackFunction = callback->v4Value();
-
- m_resultObject = resultValue()->v4Value();
-
- m_network = engine->networkAccessManager();
-
- QNetworkRequest request;
- request.setUrl(url);
-
- m_reply = m_network->get(request);
- QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
-}
-
-QV8Include::~QV8Include()
-{
- delete m_reply; m_reply = 0;
-}
-
-v8::Handle<v8::Object> QV8Include::resultValue(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));
-
- result->Set(v8::String::New("status"), QV4::Value::fromInt32(status));
-
- return result;
-}
-
-void QV8Include::callback(QV8Engine *engine, v8::Handle<v8::Function> callback, v8::Handle<v8::Object> status)
-{
- QV4::FunctionObject *f = callback->v4Value().asFunctionObject();
- if (!f)
- return;
-
- QV4::Value args[] = { status->v4Value() };
- QV4::ExecutionContext *ctx = f->engine()->current;
- try {
- f->call(engine->global(), args, 1);
- } catch (QV4::Exception &e) {
- e.accept(ctx);
- }
-}
-
-v8::Handle<v8::Object> QV8Include::result()
-{
- return m_resultObject.value();
-}
-
-#define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15
-void QV8Include::finished()
-{
- m_redirectCount++;
-
- if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) {
- QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
- if (redirect.isValid()) {
- m_url = m_url.resolved(redirect.toUrl());
- delete m_reply;
-
- QNetworkRequest request;
- request.setUrl(m_url);
-
- m_reply = m_network->get(request);
- QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
- return;
- }
- }
-
- if (m_reply->error() == QNetworkReply::NoError) {
- QByteArray data = m_reply->readAll();
-
- QString code = QString::fromUtf8(data);
- QQmlScript::Parser::extractPragmas(code);
-
- QQmlContextData *importContext = new QQmlContextData;
- importContext->isInternal = true;
- importContext->isJSContext = true;
- importContext->url = m_url;
- 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::ExecutionContext *ctx = QV8Engine::getV4(m_engine)->current;
- // ### Only used for debugging info
- //m_engine->contextWrapper()->addSubContext(m_qmlglobal.value(), script, importContext);
- try {
- script.parse();
- script.run();
- v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("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());
- }
- } else {
- v8::Handle<v8::Object>(m_resultObject)->Set(v8::String::New("status"), QV4::Value::fromInt32(NetworkError));
- }
-
- callback(m_engine, m_callbackFunction.value(), m_resultObject.value());
-
- disconnect();
- deleteLater();
-}
-
-/*
- Documented in qv8engine.cpp
-*/
-QV4::Value QV8Include::include(const v8::Arguments &args)
-{
- if (args.Length() == 0)
- return QV4::Value::undefinedValue();
-
- QV8Engine *engine = V8ENGINE();
- QQmlContextData *context = engine->callingContext();
-
- 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]);
-
- QString localFile = QQmlFile::urlToLocalFileOrQrc(url);
-
- v8::Handle<v8::Object> result;
-
- if (localFile.isEmpty()) {
-
- QV8Include *i = new QV8Include(url, engine, context,
- QV4::Value::fromObject(args.GetIsolate()->GetEngine()->qmlContextObject()),
- callbackFunction);
- result = i->result();
-
- } else {
-
- QFile f(localFile);
-
- if (f.open(QIODevice::ReadOnly)) {
- QByteArray data = f.readAll();
- QString code = QString::fromUtf8(data);
- QQmlScript::Parser::extractPragmas(code);
-
- QQmlContextData *importContext = new QQmlContextData;
- importContext->isInternal = true;
- importContext->isJSContext = true;
- importContext->url = url;
- importContext->setParent(context, true);
-
- QV4::Object *qmlglobal = args.GetIsolate()->GetEngine()->qmlContextObject();
- QV4::Script script(QV8Engine::getV4(engine), qmlglobal, code, url.toString());
-
- // ### Only used for debugging info
- // engine->contextWrapper()->addSubContext(qmlglobal, script, importContext);
- QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current;
- try {
- script.parse();
- script.run();
- result = resultValue(Ok);
- } catch (QV4::Exception &e) {
- e.accept(ctx);
- result = resultValue(Exception);
- result->Set(v8::String::New("exception"), e.value());
- }
- } else {
- result = resultValue(NetworkError);
- }
-
- callback(engine, callbackFunction, result);
- }
-
- if (result.IsEmpty())
- return QV4::Value::undefinedValue();
- else
- return result->v4Value();
-}
-
-QT_END_NAMESPACE