diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-03 14:33:30 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-03 14:30:34 +0000 |
commit | 604e379338e7c9e17c929063148754a30077988c (patch) | |
tree | 72ba38c7174c3f801023e48734e21525039fbc28 | |
parent | 29c7a1d566f9bbdcf3cadc270f4481e05a71eefb (diff) |
Improve logging of nested arrays
Nested arrays should be printed with nested '[' and ']', rather than
flattened.
[ChangeLog][QML] Nested arrays are not flattened anymore when printed
through console.log() and friends.
Change-Id: Ic27e58047fd78bc146e1179585fd0cb2c60a1144
Fixes: QTBUG-71931
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 23 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconsole/data/logging.qml | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp | 1 |
3 files changed, 24 insertions, 1 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index f713efb289..64dc581a56 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1527,6 +1527,27 @@ static QString jsStack(QV4::ExecutionEngine *engine) { return stack; } +static QString serializeArray(Object *array, ExecutionEngine *v4) { + Scope scope(v4); + ScopedValue val(scope); + QString result; + + result += QLatin1Char('['); + const uint length = array->getLength(); + for (uint i = 0; i < length; ++i) { + if (i != 0) + result += QLatin1Char(','); + val = array->get(i); + if (val->isManaged() && val->managed()->isArrayLike()) + result += serializeArray(val->objectValue(), v4); + else + result += val->toQStringNoThrow(); + } + result += QLatin1Char(']'); + + return result; +}; + static ReturnedValue writeToConsole(const FunctionObject *b, const Value *, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack = false) { @@ -1554,7 +1575,7 @@ static ReturnedValue writeToConsole(const FunctionObject *b, const Value *, cons result.append(QLatin1Char(' ')); if (argv[i].isManaged() && argv[i].managed()->isArrayLike()) - result += QLatin1Char('[') + argv[i].toQStringNoThrow() + QLatin1Char(']'); + result.append(serializeArray(argv[i].objectValue(), v4)); else result.append(argv[i].toQStringNoThrow()); } diff --git a/tests/auto/qml/qqmlconsole/data/logging.qml b/tests/auto/qml/qqmlconsole/data/logging.qml index 8ed2dd73a1..1f929d311b 100644 --- a/tests/auto/qml/qqmlconsole/data/logging.qml +++ b/tests/auto/qml/qqmlconsole/data/logging.qml @@ -69,6 +69,7 @@ QtObject { console.log(contextStringListProperty); console.log(customObject); + console.log([[1,2,3,[2,2,2,2],4],[5,6,7,8]]); try { console.log(exception); diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp index f26eaa0817..b157314071 100644 --- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp +++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp @@ -93,6 +93,7 @@ void tst_qqmlconsole::logging() QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] [object Object] 2"); QTest::ignoreMessage(QtDebugMsg, "[Hello,World]"); QTest::ignoreMessage(QtDebugMsg, "QVariant(CustomObject, MY OBJECT)"); + QTest::ignoreMessage(QtDebugMsg, "[[1,2,3,[2,2,2,2],4],[5,6,7,8]]"); QScopedPointer<QQmlContext> loggingContext(new QQmlContext(engine.rootContext())); QStringList stringList; stringList << QStringLiteral("Hello") << QStringLiteral("World"); |