aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2012-01-17 14:38:06 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-24 14:11:52 +0100
commitb77ecde410ace1545ac6fdad7466e64e4fc635da (patch)
tree791e9501a6f40a97879afa3a70e4b54bffb2663b
parentb514fecbeae6a4fed9e593ea6405dbeec7fe7883 (diff)
Console API: Add console.exception
console.exception writes a message to the console and prints the JavaScript stack trace at the point where it is called. Change-Id: Idd2ff5982826accae0895db44c7ecf6130338cc7 Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
-rw-r--r--doc/src/declarative/qdeclarativedebugging.qdoc5
-rw-r--r--src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp10
-rw-r--r--src/declarative/qml/v8/qdeclarativebuiltinfunctions_p.h1
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativeconsole/data/exception.qml58
-rw-r--r--tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp21
6 files changed, 96 insertions, 0 deletions
diff --git a/doc/src/declarative/qdeclarativedebugging.qdoc b/doc/src/declarative/qdeclarativedebugging.qdoc
index 49fe224a8c..ab64b9122a 100644
--- a/doc/src/declarative/qdeclarativedebugging.qdoc
+++ b/doc/src/declarative/qdeclarativedebugging.qdoc
@@ -117,6 +117,11 @@ function f() {
}
\endqml
+\section2 Exception
+
+\c console.exception prints an error message together with the stack trace of JavaScript
+execution at the point where it is called.
+
\section1 Debugging Transitions
When a transition doesn't look quite right, it can be helpful to view it in slow
diff --git a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp
index 5f0b3ff509..830b521027 100644
--- a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp
+++ b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp
@@ -299,6 +299,16 @@ v8::Handle<v8::Value> consoleAssert(const v8::Arguments &args)
return v8::Undefined();
}
+v8::Handle<v8::Value> consoleException(const v8::Arguments &args)
+{
+ if (args.Length() == 0)
+ V8THROW_ERROR("console.exception(): Missing argument");
+ console(Error, args);
+ printStack();
+
+ return v8::Undefined();
+}
+
v8::Handle<v8::Value> stringArg(const v8::Arguments &args)
{
QString value = V8ENGINE()->toString(args.This()->ToString());
diff --git a/src/declarative/qml/v8/qdeclarativebuiltinfunctions_p.h b/src/declarative/qml/v8/qdeclarativebuiltinfunctions_p.h
index cdb31b60a8..62dcffb367 100644
--- a/src/declarative/qml/v8/qdeclarativebuiltinfunctions_p.h
+++ b/src/declarative/qml/v8/qdeclarativebuiltinfunctions_p.h
@@ -71,6 +71,7 @@ v8::Handle<v8::Value> consoleCount(const v8::Arguments &args);
v8::Handle<v8::Value> consoleTrace(const v8::Arguments &args);
v8::Handle<v8::Value> consoleWarn(const v8::Arguments &args);
v8::Handle<v8::Value> consoleAssert(const v8::Arguments &args);
+v8::Handle<v8::Value> consoleException(const v8::Arguments &args);
v8::Handle<v8::Value> isQtObject(const v8::Arguments &args);
v8::Handle<v8::Value> rgba(const v8::Arguments &args);
v8::Handle<v8::Value> hsla(const v8::Arguments &args);
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index fa35533be3..e7fe2c713d 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -538,6 +538,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
console->Set(v8::String::New("time"), V8FUNCTION(consoleTime, this));
console->Set(v8::String::New("timeEnd"), V8FUNCTION(consoleTimeEnd, this));
console->Set(v8::String::New("trace"), V8FUNCTION(consoleTrace, this));
+ console->Set(v8::String::New("exception"), V8FUNCTION(consoleException, this));
v8::Local<v8::Object> qt = v8::Object::New();
diff --git a/tests/auto/declarative/qdeclarativeconsole/data/exception.qml b/tests/auto/declarative/qdeclarativeconsole/data/exception.qml
new file mode 100644
index 0000000000..d1a32be6bc
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeconsole/data/exception.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+QtObject {
+ function exceptionFail() {
+ console.exception("Exception 2")
+ }
+
+ Component.onCompleted: {
+ try {
+ console.exception("Exception 1")
+ } catch (e) {
+ console.log(e);
+ }
+
+ exceptionFail();
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp b/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp
index 9a4a39fa6d..34b0f6582f 100644
--- a/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp
+++ b/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp
@@ -55,6 +55,7 @@ private slots:
void tracing();
void profiling();
void assert();
+ void exception();
private:
QDeclarativeEngine engine;
@@ -141,6 +142,26 @@ void tst_qdeclarativeconsole::assert()
delete object;
}
+void tst_qdeclarativeconsole::exception()
+{
+ QUrl testUrl = testFileUrl("exception.qml");
+
+ // exception()
+ QTest::ignoreMessage(QtCriticalMsg, "Exception 1");
+ QTest::ignoreMessage(QtCriticalMsg, "Exception 2");
+ QString trace1 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(51).arg(21);
+ QString trace2 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(56).arg(9);
+ QString trace3 = QString::fromLatin1("exceptionFail (%1:%2:%3)\n").arg(testUrl.toString()).arg(46).arg(17);
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(trace1));
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(trace2));
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(trace3));
+
+ QDeclarativeComponent component(&engine, testUrl);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeconsole)
#include "tst_qdeclarativeconsole.moc"