From 415b873ea3d930f7853f9cf25f6c403e85e07101 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 16 Dec 2016 10:19:40 +0100 Subject: EvaluatorScriptClass: Catch exceptions from script importing code Change-Id: I435a3610f0b5eed9eabb012592ef13f36f8c68cc Reviewed-by: Joerg Bornemann --- src/lib/corelib/language/evaluatorscriptclass.cpp | 30 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp index 0a2e96c11..73f7e83e2 100644 --- a/src/lib/corelib/language/evaluatorscriptclass.cpp +++ b/src/lib/corelib/language/evaluatorscriptclass.cpp @@ -103,6 +103,15 @@ public: } private: + QScriptValue importScope(Evaluator *evaluator, const FileContextConstPtr &file) + { + try { + return evaluator->importScope(file); + } catch (const ErrorInfo &e) { + return evaluator->engine()->currentContext()->throwError(e.toString()); + } + } + void setupConvenienceProperty(const QString &conveniencePropertyName, QScriptValue *extraScope, const QScriptValue &scriptValue) { @@ -194,7 +203,15 @@ private: if (alternative->value->definingItem()) pushItemScopes(alternative->value->definingItem()); engine->currentContext()->pushScope(conditionScope); - engine->currentContext()->pushScope(data->evaluator->importScope(value->file())); + const QScriptValue theImportScope = importScope(data->evaluator, value->file()); + if (theImportScope.isError()) { + engine->currentContext()->popScope(); + engine->currentContext()->popScope(); + popScopes(); + *result = theImportScope; + return; + } + engine->currentContext()->pushScope(theImportScope); const QScriptValue cr = engine->evaluate(alternative->condition); const QScriptValue overrides = engine->evaluate(alternative->overrideListProperties); engine->currentContext()->popScope(); @@ -269,9 +286,14 @@ private: if (value->definingItem()) pushItemScopes(value->definingItem()); pushScope(extraScope); - pushScope(data->evaluator->importScope(value->file())); - *result = engine->evaluate(value->sourceCodeForEvaluation(), value->file()->filePath(), - value->line()); + const QScriptValue theImportScope = importScope(data->evaluator, value->file()); + if (theImportScope.isError()) { + *result = theImportScope; + } else { + pushScope(data->evaluator->importScope(value->file())); + *result = engine->evaluate(value->sourceCodeForEvaluation(), value->file()->filePath(), + value->line()); + } popScopes(); } -- cgit v1.2.3