checkExceptions after testing entity scripts in the sandbox

This commit is contained in:
Atlante45 2015-10-26 12:33:42 -07:00
parent ea56f965a4
commit a53a576aa3
2 changed files with 14 additions and 11 deletions

View file

@ -585,7 +585,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi
const auto result = QScriptEngine::evaluate(program);
--_evaluatesPending;
const auto hadUncaughtException = checkExceptions(this, program.fileName());
const auto hadUncaughtException = checkExceptions(*this, program.fileName());
if (_wantSignals) {
emit evaluationFinished(result, hadUncaughtException);
}
@ -654,7 +654,7 @@ void ScriptEngine::run() {
}
lastUpdate = now;
if (!checkExceptions(this, _fileNameString)) {
if (!checkExceptions(*this, _fileNameString)) {
stop();
}
}
@ -906,12 +906,12 @@ bool ScriptEngine::checkSyntax(const QScriptProgram& program) {
return true;
}
bool ScriptEngine::checkExceptions(QScriptEngine* engine, const QString& fileName) {
if (engine->hasUncaughtException()) {
const auto backtrace = engine->uncaughtExceptionBacktrace();
const auto exception = engine->uncaughtException().toString();
const auto line = QString::number(engine->uncaughtExceptionLineNumber());
engine->clearExceptions();
bool ScriptEngine::checkExceptions(QScriptEngine& engine, const QString& fileName) {
if (engine.hasUncaughtException()) {
const auto backtrace = engine.uncaughtExceptionBacktrace();
const auto exception = engine.uncaughtException().toString();
const auto line = QString::number(engine.uncaughtExceptionLineNumber());
engine.clearExceptions();
auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line);
if (!backtrace.empty()) {
@ -1021,7 +1021,10 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
}
QScriptEngine sandbox;
QScriptValue testConstructor = sandbox.evaluate(contents);
QScriptValue testConstructor = sandbox.evaluate(program);
if (!checkExceptions(sandbox, program.fileName())) {
return;
}
if (!testConstructor.isFunction()) {
qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n"

View file

@ -183,7 +183,7 @@ private:
void stopTimer(QTimer* timer);
static bool checkSyntax(const QScriptProgram& program);
static bool checkExceptions(QScriptEngine* engine, const QString& fileName);
static bool checkExceptions(QScriptEngine& engine, const QString& fileName);
AbstractControllerScriptingInterface* _controllerScriptingInterface;
QString _fileNameString;