diff options
author | Aurindam Jana <aurindam.jana@nokia.com> | 2011-11-18 16:41:08 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-24 11:40:07 +0100 |
commit | 43b2d685fbbefd7eb89e4e84af02bc4a4aea86e0 (patch) | |
tree | faac8b3a6ad548626a99a7430b4d2e8d958c1e6a /src/declarative | |
parent | 5aad0f5da641d778958a4127f33cbd9943e6a6c5 (diff) |
ConsoleAPI: Use environment variable
Show detailed information, such as file and line number, for
console.log, console.debug and print when the environment variable
QML_CONSOLE_EXTENDED is set.
Change-Id: I8f660f58d0fd08971ce9706b4a418ed60f312980
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp index a822eb84ec..8613ae44af 100644 --- a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp +++ b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp @@ -65,6 +65,9 @@ QT_BEGIN_NAMESPACE +// send more information such as file, line etc for console APIs +DEFINE_BOOL_CONFIG_OPTION(qmlConsoleExtended, QML_CONSOLE_EXTENDED) + namespace QDeclarativeBuiltinFunctions { enum ConsoleLogTypes { @@ -75,19 +78,8 @@ enum ConsoleLogTypes { v8::Handle<v8::Value> console(ConsoleLogTypes logType, const v8::Arguments &args) { - int line = -1; - QString scriptName; v8::HandleScope handleScope; - { - v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(1); - if (stackTrace->GetFrameCount()) { - v8::Local<v8::StackFrame> currentStackFrame = stackTrace->GetFrame(0); - line = currentStackFrame->GetLineNumber(); - scriptName = V8ENGINE()->toString(currentStackFrame->GetScriptName()); - } - } - QString result; for (int i = 0; i < args.Length(); ++i) { if (i != 0) @@ -109,17 +101,29 @@ v8::Handle<v8::Value> console(ConsoleLogTypes logType, const v8::Arguments &args } } - QString log = QString(QLatin1String("%1 (%2:%3)")).arg(result).arg(scriptName).arg(line); + if (qmlConsoleExtended()) { + int line = -1; + QString scriptName; + //get only current frame + v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(1); + if (stackTrace->GetFrameCount()) { + v8::Local<v8::StackFrame> currentStackFrame = stackTrace->GetFrame(0); + line = currentStackFrame->GetLineNumber(); + scriptName = V8ENGINE()->toString(currentStackFrame->GetScriptName()); + } + + result = QString(QLatin1String("%1 (%2:%3)")).arg(result).arg(scriptName).arg(line); + } switch (logType) { case Log: - qDebug("%s", qPrintable(log)); + qDebug("%s", qPrintable(result)); break; case Warn: - qWarning("%s", qPrintable(log)); + qWarning("%s", qPrintable(result)); break; case Error: - qCritical("%s", qPrintable(log)); + qCritical("%s", qPrintable(result)); break; default: break; |