History

checkExceptions after testing entity scripts in the sandbox

Atlante45 committed 11 years ago

Commit 38013931 parent 1c048882 files · +14 −11Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+13−10
@@ -585,7 +585,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 584 unmodified lines
585585 const auto result = QScriptEngine::evaluate(program);
586586 --_evaluatesPending;
587587
588− const auto hadUncaughtException = checkExceptions(this, program.fileName());
588+ const auto hadUncaughtException = checkExceptions(*this, program.fileName());
589589 if (_wantSignals) {
590590 emit evaluationFinished(result, hadUncaughtException);
591591 }
@@ -654,7 +654,7 @@ void ScriptEngine::run() { · 62 unmodified lines
654654 }
655655 lastUpdate = now;
656656
657− if (!checkExceptions(this, _fileNameString)) {
657+ if (!checkExceptions(*this, _fileNameString)) {
658658 stop();
659659 }
660660 }
@@ -906,12 +906,12 @@ bool ScriptEngine::checkSyntax(const QScriptProgram& program) { · 245 unmodified lines
906906 return true;
907907 }
908908
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();
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();
915915
916916 auto message = QString("[UncaughtException] %1 in %2:%3").arg(exception, fileName, line);
917917 if (!backtrace.empty()) {
@@ -1021,8 +1021,11 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 103 unmodified lines
10211021 }
10221022
10231023 QScriptEngine sandbox;
1024− QScriptValue testConstructor = sandbox.evaluate(contents);
1025−
1024+ QScriptValue testConstructor = sandbox.evaluate(program);
1025+ if (!checkExceptions(sandbox, program.fileName())) {
1026+ return;
1027+ }
1028+
10261029 if (!testConstructor.isFunction()) {
10271030 qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n"
10281031 " NOT CONSTRUCTOR\n"