aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-01-03 14:33:30 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-01-03 14:30:34 +0000
commit604e379338e7c9e17c929063148754a30077988c (patch)
tree72ba38c7174c3f801023e48734e21525039fbc28 /src/qml/qml/v8/qqmlbuiltinfunctions.cpp
parent29c7a1d566f9bbdcf3cadc270f4481e05a71eefb (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>
Diffstat (limited to 'src/qml/qml/v8/qqmlbuiltinfunctions.cpp')
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp23
1 files changed, 22 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());
}