diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-23 04:08:07 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-23 04:08:07 (GMT) |
commit | a8549cfee8b6ec393dcea6314e6ac7d6c102dc07 (patch) | |
tree | a12427d394bae5fc0080923e669a5a30c79c36b3 /src | |
parent | 2d7a9570814891ba4a86ab9472d8c8ee8315b22b (diff) | |
download | Qt-a8549cfee8b6ec393dcea6314e6ac7d6c102dc07.zip Qt-a8549cfee8b6ec393dcea6314e6ac7d6c102dc07.tar.gz Qt-a8549cfee8b6ec393dcea6314e6ac7d6c102dc07.tar.bz2 |
Webkit console.log() compatibility.
This allows avoiding the more non-standard print().
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 27 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 1 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index e292e5c..0a00092 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -145,6 +145,12 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); qtObject.setProperty(QLatin1String("md5"),scriptEngine.newFunction(md5, 1)); + //firebug/webkit compat + QScriptValue consoleObject = scriptEngine.newObject(); + consoleObject.setProperty(QLatin1String("log"),scriptEngine.newFunction(consoleLog, 1)); + consoleObject.setProperty(QLatin1String("debug"),scriptEngine.newFunction(consoleLog, 1)); + scriptEngine.globalObject().setProperty(QLatin1String("console"), consoleObject); + scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"), scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1)); scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), @@ -800,7 +806,7 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } -QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e) +QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *) { QByteArray data; @@ -812,6 +818,25 @@ QScriptValue QmlEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *e) return QScriptValue(QLatin1String(result.toHex())); } +QScriptValue QmlEnginePrivate::consoleLog(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() < 1) + return e->newVariant(QVariant(false)); + + QByteArray msg; + + for (int i=0; i<ctxt->argumentCount(); ++i) { + if (!msg.isEmpty()) msg += ' '; + msg += ctxt->argument(i).toString().toLocal8Bit(); + // does not support firebug "%[a-z]" formatting, since firebug really + // does just ignore the format letter, which makes it pointless. + } + + qDebug("%s",msg.data()); + + return e->newVariant(QVariant(true)); +} + QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) { if(ctxt->argumentCount() < 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 2f41651..c11a399 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -269,6 +269,7 @@ public: static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); static QScriptValue md5(QScriptContext*, QScriptEngine*); + static QScriptValue consoleLog(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); } |