summaryrefslogtreecommitdiff
path: root/src/lib/corelib/language/scriptengine.cpp
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@theqtcompany.com>2015-09-12 22:15:50 -0700
committerJake Petroules <jake.petroules@theqtcompany.com>2015-09-15 16:40:35 +0000
commitc5dd63416836bbdb87961ddfee972a7db810912d (patch)
treed9f763bbb10d788d7ba18cf169ecda0fbbdfec81 /src/lib/corelib/language/scriptengine.cpp
parent3b2dcf0b1cf1ff51d05ae6955e25a25d967ac0d7 (diff)
downloadqbs-c5dd63416836bbdb87961ddfee972a7db810912d.tar.gz
Implement some of the non-standard yet common Console API.
This solves the problems with print() going to unredictable streams on some platforms due to possible QtScript bugs. It also provides logging integration with IDEs, and stylizes error and warning output with "ERROR: " and "WARNING: " prefixes and colors in color-capable terminals. Refactor autotests to accommodate. Task-number: QBS-548 Change-Id: I11767d51d3c2e7a97ca2b67e54377350aec2458d Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/lib/corelib/language/scriptengine.cpp')
-rw-r--r--src/lib/corelib/language/scriptengine.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/corelib/language/scriptengine.cpp b/src/lib/corelib/language/scriptengine.cpp
index d7cd4868c..cea8f9dd5 100644
--- a/src/lib/corelib/language/scriptengine.cpp
+++ b/src/lib/corelib/language/scriptengine.cpp
@@ -530,6 +530,23 @@ void ScriptEngine::installQbsBuiltins()
EvaluatorScriptClass::js_getHash);
installQbsFunction(QLatin1String("shellQuote"),
EvaluatorScriptClass::js_shellQuote);
+
+ globalObject().setProperty(QLatin1String("console"), m_consoleObject = newObject());
+ installConsoleFunction(QLatin1String("debug"),
+ reinterpret_cast<FunctionWithArgSignature>(
+ EvaluatorScriptClass::js_consoleDebug));
+ installConsoleFunction(QLatin1String("error"),
+ reinterpret_cast<FunctionWithArgSignature>(
+ EvaluatorScriptClass::js_consoleError));
+ installConsoleFunction(QLatin1String("info"),
+ reinterpret_cast<FunctionWithArgSignature>(
+ EvaluatorScriptClass::js_consoleInfo));
+ installConsoleFunction(QLatin1String("log"),
+ reinterpret_cast<FunctionWithArgSignature>(
+ EvaluatorScriptClass::js_consoleLog));
+ installConsoleFunction(QLatin1String("warn"),
+ reinterpret_cast<FunctionWithArgSignature>(
+ EvaluatorScriptClass::js_consoleWarn));
}
void ScriptEngine::extendJavaScriptBuiltins()
@@ -573,6 +590,11 @@ void ScriptEngine::installQbsFunction(const QString &name, FunctionSignature f)
installFunction(name, &functionValue, f, &m_qbsObject);
}
+void ScriptEngine::installConsoleFunction(const QString &name, FunctionWithArgSignature f)
+{
+ m_consoleObject.setProperty(name, newFunction(f, &m_logger));
+}
+
void ScriptEngine::installImportFunctions()
{
installFunction(QLatin1String("loadFile"), &m_loadFileFunction, js_loadFile);