Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -83,6 +83,37 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 82 unmodified lines | ||
| 83 | 83 | out = qobject_cast<AbstractInputController*>(object.toQObject()); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | +bool checkSyntax(const QScriptProgram& program) { | |
| 87 | + const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode()); | |
| 88 | + if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { | |
| 89 | + const auto error = syntaxCheck.errorMessage(); | |
| 90 | + const auto line = QString::number(syntaxCheck.errorLineNumber()); | |
| 91 | + const auto column = QString::number(syntaxCheck.errorColumnNumber()); | |
| 92 | + const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, program.fileName(), line, column); | |
| 93 | + qCWarning(scriptengine) << qPrintable(message); | |
| 94 | + return false; | |
| 95 | + } | |
| 96 | + return true; | |
| 97 | +} | |
| 98 | + | |
| 99 | +bool checkExceptions(QScriptEngine& engine, const QString& fileName) { | |
| 100 | + if (engine.hasUncaughtException()) { | |
| 101 | + const auto backtrace = engine.uncaughtExceptionBacktrace(); | |
| 102 | + const auto exception = engine.uncaughtException().toString(); | |
| 103 | + const auto line = QString::number(engine.uncaughtExceptionLineNumber()); | |
| 104 | + engine.clearExceptions(); | |
| 105 | + | |
| 106 | + auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line); | |
| 107 | + if (!backtrace.empty()) { | |
| 108 | + static const auto lineSeparator = "\n "; | |
| 109 | + message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); | |
| 110 | + } | |
| 111 | + qCWarning(scriptengine) << qPrintable(message); | |
| 112 | + return false; | |
| 113 | + } | |
| 114 | + return true; | |
| 115 | +} | |
| 116 | + | |
| 86 | 117 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, |
| 87 | 118 | AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) : |
| 88 | 119 | |
| @@ -893,37 +924,6 @@ void ScriptEngine::load(const QString& loadFile) { · 804 unmodified lines | ||
| 893 | 924 | } |
| 894 | 925 | } |
| 895 | 926 | |
| 896 | −bool ScriptEngine::checkSyntax(const QScriptProgram& program) { | |
| 897 | − const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode()); | |
| 898 | − if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { | |
| 899 | − const auto error = syntaxCheck.errorMessage(); | |
| 900 | − const auto line = QString::number(syntaxCheck.errorLineNumber()); | |
| 901 | − const auto column = QString::number(syntaxCheck.errorColumnNumber()); | |
| 902 | − const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, program.fileName(), line, column); | |
| 903 | − qCWarning(scriptengine) << qPrintable(message); | |
| 904 | − return false; | |
| 905 | − } | |
| 906 | − return true; | |
| 907 | −} | |
| 908 | − | |
| 909 | −bool ScriptEngine::checkExceptions(QScriptEngine& engine, const QString& fileName) { | |
| 910 | − if (engine.hasUncaughtException()) { | |
| 911 | − const auto backtrace = engine.uncaughtExceptionBacktrace(); | |
| 912 | − const auto exception = engine.uncaughtException().toString(); | |
| 913 | − const auto line = QString::number(engine.uncaughtExceptionLineNumber()); | |
| 914 | − engine.clearExceptions(); | |
| 915 | − | |
| 916 | − auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line); | |
| 917 | − if (!backtrace.empty()) { | |
| 918 | − static const auto lineSeparator = "\n "; | |
| 919 | − message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); | |
| 920 | − } | |
| 921 | − qCWarning(scriptengine) << qPrintable(message); | |
| 922 | − return false; | |
| 923 | − } | |
| 924 | − return true; | |
| 925 | −} | |
| 926 | − | |
| 927 | 927 | // Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args |
| 928 | 928 | void ScriptEngine::forwardHandlerCall(const EntityItemID& entityID, const QString& eventName, QScriptValueList eventHanderArgs) { |
| 929 | 929 | if (QThread::currentThread() != thread()) { |