From d7b24639a40706f75071640eefa11adf5902e0ed Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 14 Aug 2009 16:43:09 +0200 Subject: More polishing on the backtrace change the coding style of function from foo (arg=text) to foo(arg = 'text') --- src/script/api/qscriptcontext.cpp | 10 +++++-- tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 36 ++++++++++++------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index 01ccb6d..689ad66 100644 --- a/src/script/api/qscriptcontext.cpp +++ b/src/script/api/qscriptcontext.cpp @@ -631,17 +631,21 @@ QString QScriptContext::toString() const } QStringList parameterNames = info.functionParameterNames(); - result.append(QLatin1String(" (")); + result.append(QLatin1Char('(')); for (int i = 0; i < argumentCount(); ++i) { if (i > 0) result.append(QLatin1String(", ")); if (i < parameterNames.count()) { result.append(parameterNames.at(i)); - result.append(QLatin1Char('=')); + result.append(QLatin1String(" = ")); } QScriptValue arg = argument(i); -// result.append(safeValueToString(arg)); ### + if (arg.isString()) + result.append(QLatin1Char('\'')); result.append(arg.toString()); + if (arg.isString()) + result.append(QLatin1Char('\'')); + } result.append(QLatin1Char(')')); diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index 43938b6..c72594c 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -563,9 +563,9 @@ void tst_QScriptContext::backtrace_data() { QStringList expected; - expected << " (123) at -1" - << "foo ([object Object], [object global]) at testfile:2" //### object instead of 'hello' - << " () at testfile:4"; + expected << "(123) at -1" + << "foo([object Object], [object global]) at testfile:2" //### object instead of 'hello' + << "() at testfile:4"; QString source( "function foo() {\n" @@ -585,10 +585,10 @@ void tst_QScriptContext::backtrace_data() "foo('hello', 456)" ).arg("\\n \\n bt('hey'); \\n"); - expected << " (hey) at -1" - << " () at 3" //### should be - << "foo (arg1=hello, arg2=456) at testfile:-1" //### line number should be 2 - << " () at testfile:4"; + expected << "('hey') at -1" + << "() at 3" //### should be + << "foo(arg1 = 'hello', arg2 = 456) at testfile:-1" //### line number should be 2 + << "() at testfile:4"; QTest::newRow("eval") << source << expected; } @@ -607,12 +607,12 @@ void tst_QScriptContext::backtrace_data() ).arg(eval_code); QStringList expected; - expected << " (m) at -1" - << "bar (a=b) at eval.js:2" - << " () at eval.js:4" //### should be - << QString(" (%1, eval.js) at -1").arg(eval_code.replace("\\n", "\n")) - << "foo () at testfile:2" - << " () at testfile:4"; + expected << "('m') at -1" + << "bar(a = 'b') at eval.js:2" + << "() at eval.js:4" //### should be + << QString("('%1', 'eval.js') at -1").arg(eval_code.replace("\\n", "\n")) + << "foo() at testfile:2" + << "() at testfile:4"; QTest::newRow("custom_eval") << source << expected; } @@ -626,10 +626,10 @@ void tst_QScriptContext::backtrace_data() ).arg(f); QStringList expected; - expected << " (b) at -1" - << " (a=b) at testfile:5" - << QString("foo (f=%1) at testfile:2").arg(f) - << " () at testfile:6"; + expected << "('b') at -1" + << "(a = 'b') at testfile:5" + << QString("foo(f = %1) at testfile:2").arg(f) + << "() at testfile:6"; QTest::newRow("closure") << source << expected; } @@ -870,7 +870,7 @@ void tst_QScriptContext::toString() " return parentContextToString();\n" "}; foo(1, 2, 3)", "script.qs"); QVERIFY(ret.isString()); - QCOMPARE(ret.toString(), QString::fromLatin1("foo (first=1, second=2, third=3) at script.qs:2")); + QCOMPARE(ret.toString(), QString::fromLatin1("foo(first = 1, second = 2, third = 3) at script.qs:2")); } static QScriptValue storeCalledAsConstructor(QScriptContext *ctx, QScriptEngine *eng) -- cgit v0.12