diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-04-23 14:14:56 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-05-23 08:28:53 +0000 |
commit | 20b376b64a11b4bda18aa1abda543586f04688e8 (patch) | |
tree | 21760aed4cd4dde56718b2403d46032eef00105f /src | |
parent | 7c0a9a08f7b078285411269dc740922e06625901 (diff) | |
download | qtdeclarative-20b376b64a11b4bda18aa1abda543586f04688e8.tar.gz |
Print function identifier when calling toString() on a function
Task-number: QTBUG-50669
Change-Id: Ia0e9491b12ca1db1da2bfa8eb5ca8bbe4658f699
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 8a70715728..1eb56b9c2a 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -311,7 +311,19 @@ ReturnedValue FunctionPrototype::method_toString(const FunctionObject *b, const if (!fun) return v4->throwTypeError(); - return Encode(v4->newString(QStringLiteral("function() { [code] }"))); + const Scope scope(fun->engine()); + const ScopedString scopedFunctionName(scope, fun->name()); + const QString functionName(scopedFunctionName ? scopedFunctionName->toQString() : QString()); + QString functionAsString = QStringLiteral("function"); + + // If fun->name() is empty, then there is no function name + // to append because the function is anonymous. + if (!functionName.isEmpty()) + functionAsString.append(QLatin1Char(' ') + functionName); + + functionAsString.append(QStringLiteral("() { [code] }")); + + return Encode(v4->newString(functionAsString)); } ReturnedValue FunctionPrototype::method_apply(const QV4::FunctionObject *b, const Value *thisObject, const Value *argv, int argc) |