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 | void ConsoleScriptingInterface::exception(QString message) { | 53 | void ConsoleScriptingInterface::exception(QString message) { |
| 54 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | 54 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { |
| 55 | scriptEngine->logConsoleException(message); | 55 | scriptEngine->scriptErrorMessage(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; | ||
| 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 | void ConsoleScriptingInterface::time(QString labelName) { | 59 | void ConsoleScriptingInterface::time(QString labelName) { |
| 96 | QDateTime _currentTime = QDateTime::currentDateTime().toUTC(); | 60 | QDateTime _currentTime = QDateTime::currentDateTime().toUTC(); |
| 97 | _listOfTimeValues.insert(labelName, _currentTime.toUTC()); | 61 | _listOfTimeValues.insert(labelName, _currentTime.toUTC()); |
| @@ -106,10 +70,8 @@ void ConsoleScriptingInterface::timeEnd(QString labelName) { · 8 unmodified lines | |||
| 106 | 70 | ||
| 107 | //Check if not exist items in list | 71 | //Check if not exist items in list |
| 108 | if (!_labelInList) { | 72 | if (!_labelInList) { |
| 109 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | 73 | message = "No such label found " + labelName; |
| 110 | message = "No such label found " + labelName; | 74 | error(message); |
| 111 | scriptEngine->scriptErrorMessage(message); | ||
| 112 | } | ||
| 113 | return; | 75 | return; |
| 114 | } | 76 | } |
| 115 | 77 | ||
| @@ -123,14 +85,10 @@ void ConsoleScriptingInterface::timeEnd(QString labelName) { · 7 unmodified lines | |||
| 123 | if (_dateTimeOfLabel.toString(TIME_FORMAT) == _currentDateTimeValue.toString(TIME_FORMAT)) { | 85 | if (_dateTimeOfLabel.toString(TIME_FORMAT) == _currentDateTimeValue.toString(TIME_FORMAT)) { |
| 124 | millisecondsDiff = _dateTimeOfLabel.msecsTo(_currentDateTimeValue); | 86 | millisecondsDiff = _dateTimeOfLabel.msecsTo(_currentDateTimeValue); |
| 125 | message = QString::number(millisecondsDiff) + " ms"; | 87 | message = QString::number(millisecondsDiff) + " ms"; |
| 126 | } | 88 | } else { |
| 127 | else { | ||
| 128 | message = secondsToString(_dateTimeOfLabel.secsTo(_currentDateTimeValue)); | 89 | message = secondsToString(_dateTimeOfLabel.secsTo(_currentDateTimeValue)); |
| 129 | } | 90 | } |
| 130 | 91 | log("Time : " + message); | |
| 131 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | ||
| 132 | scriptEngine->scriptPrintedMessage("Time : " + message); | ||
| 133 | } | ||
| 134 | } | 92 | } |
| 135 | 93 | ||
| 136 | QString ConsoleScriptingInterface::secondsToString(qint64 seconds) | 94 | QString ConsoleScriptingInterface::secondsToString(qint64 seconds) |
| @@ -147,24 +105,24 @@ void ConsoleScriptingInterface::asserts(bool condition, QString message) { · 10 unmodified lines | |||
| 147 | QString assertFailed = "Assertion failed"; | 105 | QString assertFailed = "Assertion failed"; |
| 148 | if (message.isEmpty()) { | 106 | if (message.isEmpty()) { |
| 149 | message = assertFailed; | 107 | message = assertFailed; |
| 150 | } | 108 | } else { |
| 151 | else { | 109 | QString inputType = typeid(message).name(); |
| 152 | if (typeid(message) != typeid(QString)) { | 110 | if (!inputType.compare("QString")) { |
| 153 | message = assertFailed; | 111 | message = assertFailed; |
| 154 | } | 112 | } else { |
| 155 | else { | ||
| 156 | message = assertFailed + " " + message; | 113 | message = assertFailed + " " + message; |
| 157 | } | 114 | } |
| 158 | } | 115 | } |
| 159 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | 116 | error(message); |
| 160 | scriptEngine->scriptErrorMessage(message); | ||
| 161 | } | ||
| 162 | } | 117 | } |
| 163 | } | 118 | } |
| 164 | 119 | ||
| 165 | void ConsoleScriptingInterface::trace() { | 120 | void ConsoleScriptingInterface::trace() { |
| 166 | if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) { | 121 | const auto lineSeparator = "\n "; |
| 167 | scriptEngine->logTraceException(); | 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 | ||