Showing the changes to libraries/script-engine/src/ConsoleScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -52,46 +52,10 @@ void ConsoleScriptingInterface::error(QString message) { · 51 unmodified lines | ||
| 52 | 52 | |
| 53 | 53 | void ConsoleScriptingInterface::exception(QString message) { |
| 54 | 54 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { |
| 55 | − scriptEngine->logConsoleException(message); | |
| 56 | − } | |
| 57 | − | |
| 58 | −} | |
| 59 | − | |
| 60 | −bool ConsoleScriptingInterface:: hasCorrectSyntax(QScriptProgram& program) { | |
| 61 | − const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode()); | |
| 62 | − if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { | |
| 63 | − const auto error = syntaxCheck.errorMessage(); | |
| 64 | − const auto line = QString::number(syntaxCheck.errorLineNumber()); | |
| 65 | − const auto column = QString::number(syntaxCheck.errorColumnNumber()); | |
| 66 | − const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, program.fileName(), line, column); | |
| 67 | − qCritical() << qPrintable(message); | |
| 68 | − return false; | |
| 55 | + scriptEngine->scriptErrorMessage(message); | |
| 69 | 56 | } |
| 70 | − return true; | |
| 71 | −} | |
| 72 | − | |
| 73 | −QString ConsoleScriptingInterface::hadUncaughtExceptions(QScriptEngine& engine, QString& fileName) { | |
| 74 | − log("4"); | |
| 75 | − //if (engine.hasUncaughtException()) { | |
| 76 | − const auto backtrace = engine.uncaughtExceptionBacktrace(); | |
| 77 | − const auto exception = engine.uncaughtException().toString(); | |
| 78 | − const auto line = QString::number(engine.uncaughtExceptionLineNumber()); | |
| 79 | − engine.clearExceptions(); | |
| 80 | − log("5"); | |
| 81 | − static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3"; | |
| 82 | − auto message = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line); | |
| 83 | − if (!backtrace.empty()) { | |
| 84 | − static const auto lineSeparator = "\n "; | |
| 85 | − message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); | |
| 86 | − } | |
| 87 | − // qCritical() << qPrintable(message); | |
| 88 | − log("6"); | |
| 89 | − return message; | |
| 90 | − //} | |
| 91 | − //return false; | |
| 92 | 57 | } |
| 93 | 58 | |
| 94 | − | |
| 95 | 59 | void ConsoleScriptingInterface::time(QString labelName) { |
| 96 | 60 | QDateTime _currentTime = QDateTime::currentDateTime().toUTC(); |
| 97 | 61 | _listOfTimeValues.insert(labelName, _currentTime.toUTC()); |
| @@ -106,10 +70,8 @@ void ConsoleScriptingInterface::timeEnd(QString labelName) { · 8 unmodified lines | ||
| 106 | 70 | |
| 107 | 71 | //Check if not exist items in list |
| 108 | 72 | if (!_labelInList) { |
| 109 | − if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | |
| 110 | − message = "No such label found " + labelName; | |
| 111 | − scriptEngine->scriptErrorMessage(message); | |
| 112 | − } | |
| 73 | + message = "No such label found " + labelName; | |
| 74 | + error(message); | |
| 113 | 75 | return; |
| 114 | 76 | } |
| 115 | 77 | |
| @@ -123,14 +85,10 @@ void ConsoleScriptingInterface::timeEnd(QString labelName) { · 7 unmodified lines | ||
| 123 | 85 | if (_dateTimeOfLabel.toString(TIME_FORMAT) == _currentDateTimeValue.toString(TIME_FORMAT)) { |
| 124 | 86 | millisecondsDiff = _dateTimeOfLabel.msecsTo(_currentDateTimeValue); |
| 125 | 87 | message = QString::number(millisecondsDiff) + " ms"; |
| 126 | − } | |
| 127 | − else { | |
| 88 | + } else { | |
| 128 | 89 | message = secondsToString(_dateTimeOfLabel.secsTo(_currentDateTimeValue)); |
| 129 | 90 | } |
| 130 | − | |
| 131 | − if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | |
| 132 | − scriptEngine->scriptPrintedMessage("Time : " + message); | |
| 133 | − } | |
| 91 | + log("Time : " + message); | |
| 134 | 92 | } |
| 135 | 93 | |
| 136 | 94 | QString ConsoleScriptingInterface::secondsToString(qint64 seconds) |
| @@ -147,24 +105,24 @@ void ConsoleScriptingInterface::asserts(bool condition, QString message) { · 10 unmodified lines | ||
| 147 | 105 | QString assertFailed = "Assertion failed"; |
| 148 | 106 | if (message.isEmpty()) { |
| 149 | 107 | message = assertFailed; |
| 150 | − } | |
| 151 | − else { | |
| 152 | − if (typeid(message) != typeid(QString)) { | |
| 108 | + } else { | |
| 109 | + QString inputType = typeid(message).name(); | |
| 110 | + if (!inputType.compare("QString")) { | |
| 153 | 111 | message = assertFailed; |
| 154 | − } | |
| 155 | − else { | |
| 112 | + } else { | |
| 156 | 113 | message = assertFailed + " " + message; |
| 157 | 114 | } |
| 158 | 115 | } |
| 159 | − if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | |
| 160 | − scriptEngine->scriptErrorMessage(message); | |
| 161 | − } | |
| 116 | + error(message); | |
| 162 | 117 | } |
| 163 | 118 | } |
| 164 | 119 | |
| 165 | −void ConsoleScriptingInterface::trace() { | |
| 166 | − if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | |
| 167 | − scriptEngine->logTraceException(); | |
| 120 | +void ConsoleScriptingInterface::trace() { | |
| 121 | + const auto lineSeparator = "\n "; | |
| 122 | + if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | |
| 123 | + QStringList backtrace = scriptEngine->currentContext()->backtrace(); | |
| 124 | + auto message = QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); | |
| 125 | + scriptEngine->scriptPrintedMessage(message); | |
| 168 | 126 | } |
| 169 | 127 | } |
| 170 | 128 | |