aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp35
-rw-r--r--tests/auto/qml/qqmlconsole/data/logging.qml1
-rw-r--r--tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp11
3 files changed, 30 insertions, 17 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index c8508e7ecd..3f0702e824 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -114,24 +114,35 @@ v8::Handle<v8::Value> console(ConsoleLogTypes logType, const v8::Arguments &args
v8::HandleScope handleScope;
QString result;
+ QV8Engine *engine = V8ENGINE();
for (int i = 0; i < args.Length(); ++i) {
if (i != 0)
result.append(QLatin1Char(' '));
v8::Local<v8::Value> value = args[i];
- //Check for Object Type
- if (value->IsObject() && !value->IsFunction()
- && !value->IsArray() && !value->IsDate()
- && !value->IsRegExp()) {
- result.append(QLatin1String("Object"));
- } else {
- v8::Local<v8::String> jsstr = value->ToString();
- QString tmp = V8ENGINE()->toString(jsstr);
- if (value->IsArray())
- result.append(QString::fromLatin1("[%1]").arg(tmp));
- else
- result.append(tmp);
+
+ v8::TryCatch tryCatch;
+ v8::Local<v8::String> toString = value->ToString();
+ if (tryCatch.HasCaught()) {
+ // toString() threw Exception
+ // Is it possible for value to be anything other than Object?
+ QString str;
+ if (value->IsObject()) {
+ str = QStringLiteral("[object Object]");
+ } else {
+ toString = tryCatch.Exception()->ToString();
+ str = QStringLiteral("toString() threw exception: %1")
+ .arg(engine->toString(toString));
+ }
+ result.append(str);
+ continue;
}
+
+ QString tmp = engine->toString(toString);
+ if (value->IsArray())
+ result.append(QStringLiteral("[%1]").arg(tmp));
+ else
+ result.append(tmp);
}
if (printStack) {
diff --git a/tests/auto/qml/qqmlconsole/data/logging.qml b/tests/auto/qml/qqmlconsole/data/logging.qml
index 44009b5db9..11f11f492c 100644
--- a/tests/auto/qml/qqmlconsole/data/logging.qml
+++ b/tests/auto/qml/qqmlconsole/data/logging.qml
@@ -62,6 +62,7 @@ QtObject {
var a = [1, 2];
var b = {a: "hello", d: 1 };
+ b.toString = function() { return JSON.stringify(b) }
var c
var d = 12;
var e = function() { return 5;};
diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
index d96da678e2..1f17113d4a 100644
--- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
+++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp
@@ -77,15 +77,16 @@ void tst_qqmlconsole::logging()
QTest::ignoreMessage(QtDebugMsg, ": 2");
QTest::ignoreMessage(QtDebugMsg, "[1,2]");
- QTest::ignoreMessage(QtDebugMsg, "Object");
+ QTest::ignoreMessage(QtDebugMsg, "{\"a\":\"hello\",\"d\":1}");
QTest::ignoreMessage(QtDebugMsg, "undefined");
QTest::ignoreMessage(QtDebugMsg, "12");
QTest::ignoreMessage(QtDebugMsg, "function () { return 5;}");
QTest::ignoreMessage(QtDebugMsg, "true");
- QTest::ignoreMessage(QtDebugMsg, "Object");
- QTest::ignoreMessage(QtDebugMsg, "Object");
- QTest::ignoreMessage(QtDebugMsg, "1 pong! Object");
- QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] Object 2");
+ // Printing QML object prints out the class/type of QML object with the memory address
+// QTest::ignoreMessage(QtDebugMsg, "QtObject_QML_0(0xABCD..)");
+ QTest::ignoreMessage(QtDebugMsg, "[object Object]");
+ QTest::ignoreMessage(QtDebugMsg, "1 pong! [object Object]");
+ QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] [object Object] 2");
QQmlComponent component(&engine, testUrl);
QObject *object = component.create();