aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-10-14 15:48:12 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-10-14 15:48:12 +0200
commit7063fefe4b5e866b27001bb9b911fc2f68034e40 (patch)
tree1ce35139475d83399572a3265414c2da3443a321 /src/qml/qml/v8
parentf3446071da8357620d0c8593a04e3b4fbba88f21 (diff)
parent4f3379352a265bab00a7265f85ffc38a9ca4ffe4 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp64
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions_p.h3
-rw-r--r--src/qml/qml/v8/qv8engine.cpp5
3 files changed, 45 insertions, 27 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index 5986fdbdfa..89088e5b3e 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -1380,37 +1380,40 @@ static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, CallContext *c
result.append(QLatin1Char(' '));
if (ctx->args()[i].as<ArrayObject>())
- result.append(QStringLiteral("[") + ctx->args()[i].toQStringNoThrow() + QStringLiteral("]"));
+ result.append(QLatin1Char('[') + ctx->args()[i].toQStringNoThrow() + QLatin1Char(']'));
else
result.append(ctx->args()[i].toQStringNoThrow());
}
if (printStack) {
- result.append(QLatin1String("\n"));
+ result.append(QLatin1Char('\n'));
result.append(jsStack(v4));
}
- static QLoggingCategory loggingCategory("qml");
+ static QLoggingCategory qmlLoggingCategory("qml");
+ static QLoggingCategory jsLoggingCategory("js");
+
+ QLoggingCategory *loggingCategory = v4->qmlEngine() ? &qmlLoggingCategory : &jsLoggingCategory;
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
const QByteArray baFunction = frame.function.toUtf8();
- QMessageLogger logger(baSource.constData(), frame.line, baFunction.constData(), loggingCategory.categoryName());
+ QMessageLogger logger(baSource.constData(), frame.line, baFunction.constData(), loggingCategory->categoryName());
switch (logType) {
case Log:
- if (loggingCategory.isDebugEnabled())
+ if (loggingCategory->isDebugEnabled())
logger.debug("%s", result.toUtf8().constData());
break;
case Info:
- if (loggingCategory.isInfoEnabled())
+ if (loggingCategory->isInfoEnabled())
logger.info("%s", result.toUtf8().constData());
break;
case Warn:
- if (loggingCategory.isWarningEnabled())
+ if (loggingCategory->isWarningEnabled())
logger.warning("%s", result.toUtf8().constData());
break;
case Error:
- if (loggingCategory.isCriticalEnabled())
+ if (loggingCategory->isCriticalEnabled())
logger.critical("%s", result.toUtf8().constData());
break;
default:
@@ -1442,6 +1445,9 @@ QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
{
QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ if (!v4->qmlEngine())
+ return QV4::Encode::undefined(); // Not yet implemented for JavaScript.
+
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
const QByteArray baFunction = frame.function.toUtf8();
@@ -1461,6 +1467,9 @@ QV4::ReturnedValue ConsoleObject::method_profileEnd(CallContext *ctx)
{
QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ if (!v4->qmlEngine())
+ return QV4::Encode::undefined(); // Not yet implemented for JavaScript.
+
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
const QByteArray baFunction = frame.function.toUtf8();
@@ -1590,31 +1599,36 @@ QV4::ReturnedValue ConsoleObject::method_exception(CallContext *ctx)
-void QV4::GlobalExtensions::init(QQmlEngine *qmlEngine, Object *globalObject)
+void QV4::GlobalExtensions::init(Object *globalObject, QJSEngine::Extensions extensions)
{
ExecutionEngine *v4 = globalObject->engine();
Scope scope(v4);
-#ifndef QT_NO_TRANSLATION
- globalObject->defineDefaultProperty(QStringLiteral("qsTranslate"), method_qsTranslate);
- globalObject->defineDefaultProperty(QStringLiteral("QT_TRANSLATE_NOOP"), method_qsTranslateNoOp);
- globalObject->defineDefaultProperty(QStringLiteral("qsTr"), method_qsTr);
- globalObject->defineDefaultProperty(QStringLiteral("QT_TR_NOOP"), method_qsTrNoOp);
- globalObject->defineDefaultProperty(QStringLiteral("qsTrId"), method_qsTrId);
- globalObject->defineDefaultProperty(QStringLiteral("QT_TRID_NOOP"), method_qsTrIdNoOp);
-#endif
+ if (extensions.testFlag(QJSEngine::TranslationExtension)) {
+ #ifndef QT_NO_TRANSLATION
+ globalObject->defineDefaultProperty(QStringLiteral("qsTranslate"), QV4::GlobalExtensions::method_qsTranslate);
+ globalObject->defineDefaultProperty(QStringLiteral("QT_TRANSLATE_NOOP"), QV4::GlobalExtensions::method_qsTranslateNoOp);
+ globalObject->defineDefaultProperty(QStringLiteral("qsTr"), QV4::GlobalExtensions::method_qsTr);
+ globalObject->defineDefaultProperty(QStringLiteral("QT_TR_NOOP"), QV4::GlobalExtensions::method_qsTrNoOp);
+ globalObject->defineDefaultProperty(QStringLiteral("qsTrId"), QV4::GlobalExtensions::method_qsTrId);
+ globalObject->defineDefaultProperty(QStringLiteral("QT_TRID_NOOP"), QV4::GlobalExtensions::method_qsTrIdNoOp);
+
+ // string prototype extension
+ scope.engine->stringPrototype()->defineDefaultProperty(QStringLiteral("arg"), QV4::GlobalExtensions::method_string_arg);
+ #endif
+ }
- globalObject->defineDefaultProperty(QStringLiteral("print"), ConsoleObject::method_log);
- globalObject->defineDefaultProperty(QStringLiteral("gc"), method_gc);
+ if (extensions.testFlag(QJSEngine::ConsoleExtension)) {
+ globalObject->defineDefaultProperty(QStringLiteral("print"), QV4::ConsoleObject::method_log);
- ScopedObject console(scope, v4->memoryManager->allocObject<QV4::ConsoleObject>());
- globalObject->defineDefaultProperty(QStringLiteral("console"), console);
- ScopedObject qt(scope, v4->memoryManager->allocObject<QV4::QtObject>(qmlEngine));
- globalObject->defineDefaultProperty(QStringLiteral("Qt"), qt);
+ QV4::ScopedObject console(scope, globalObject->engine()->memoryManager->allocObject<QV4::ConsoleObject>());
+ globalObject->defineDefaultProperty(QStringLiteral("console"), console);
+ }
- // string prototype extension
- v4->stringPrototype()->defineDefaultProperty(QStringLiteral("arg"), method_string_arg);
+ if (extensions.testFlag(QJSEngine::GarbageCollectionExtension)) {
+ globalObject->defineDefaultProperty(QStringLiteral("gc"), QV4::GlobalExtensions::method_gc);
+ }
}
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
index bb05376fc0..d373fb6ee6 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
@@ -47,6 +47,7 @@
#include <private/qqmlglobal_p.h>
#include <private/qv4functionobject_p.h>
+#include <private/qjsengine_p.h>
QT_BEGIN_NAMESPACE
@@ -142,7 +143,7 @@ struct ConsoleObject : Object
};
struct GlobalExtensions {
- static void init(QQmlEngine *qmlEngine, Object *globalObject);
+ static void init(Object *globalObject, QJSEngine::Extensions extensions);
#ifndef QT_NO_TRANSLATION
static ReturnedValue method_qsTranslate(CallContext *ctx);
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index effc37a0eb..dae932e705 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -174,7 +174,10 @@ const QSet<QString> &QV8Engine::illegalNames() const
void QV8Engine::initializeGlobal()
{
QV4::Scope scope(m_v4Engine);
- QV4::GlobalExtensions::init(m_engine, m_v4Engine->globalObject);
+ QV4::GlobalExtensions::init(m_v4Engine->globalObject, QJSEngine::AllExtensions);
+
+ QV4::ScopedObject qt(scope, m_v4Engine->memoryManager->allocObject<QV4::QtObject>(m_engine));
+ m_v4Engine->globalObject->defineDefaultProperty(QStringLiteral("Qt"), qt);
QQmlLocale::registerStringLocaleCompare(m_v4Engine);
QQmlDateExtension::registerExtension(m_v4Engine);