diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-11-08 10:20:40 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-11-08 15:35:11 +0000 |
commit | 84a12c6a78fde5f33ad63386a141b9b64d647815 (patch) | |
tree | 5fd9606e50682436ced4b8427d88a9aa26417a0a | |
parent | 97f8ec24fa1cfce7efdf96ab5ab779fff6940bf9 (diff) |
SVConverter: Factor out the creation of the extra scope
Clean up the handler function for JSSourceValue objects.
Change-Id: I04fd79c8c03016c5656f7f392e0e27388215e928
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/lib/corelib/language/evaluatorscriptclass.cpp | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp index 1120c8eca..18e088743 100644 --- a/src/lib/corelib/language/evaluatorscriptclass.cpp +++ b/src/lib/corelib/language/evaluatorscriptclass.cpp @@ -59,6 +59,8 @@ #include <QtScript/qscriptstring.h> #include <QtScript/qscriptvalue.h> +#include <utility> + namespace qbs { namespace Internal { @@ -119,6 +121,46 @@ private: extraScope->setProperty(conveniencePropertyName, valueToSet); } + std::pair<QScriptValue, bool> createExtraScope(const JSSourceValue *value, Item *outerItem) + { + std::pair<QScriptValue, bool> result; + auto &extraScope = result.first; + result.second = true; + if (value->sourceUsesBase()) { + QScriptValue baseValue; + if (value->baseValue()) { + SVConverter converter(scriptClass, object, value->baseValue(), itemOfProperty, + propertyName, data, &baseValue); + converter.start(); + } + setupConvenienceProperty(QLatin1String("base"), &extraScope, baseValue); + } + if (value->sourceUsesOuter() && outerItem) { + const QScriptValue v = data->evaluator->property(outerItem, *propertyName); + if (engine->hasErrorOrException(v)) { + extraScope = engine->lastErrorValue(v); + result.second = false; + return result; + } + setupConvenienceProperty(QLatin1String("outer"), &extraScope, v); + } + if (value->sourceUsesOriginal()) { + QScriptValue originalValue; + if (data->item->propertyDeclaration(propertyName->toString()).isScalar()) { + const Item *item = itemOfProperty; + while (item->type() == ItemType::ModuleInstance) + item = item->prototype(); + SVConverter converter(scriptClass, object, item->property(*propertyName), item, + propertyName, data, &originalValue); + converter.start(); + } else { + originalValue = engine->newArray(0); + } + setupConvenienceProperty(QLatin1String("original"), &extraScope, originalValue); + } + return result; + } + void pushScope(const QScriptValue &scope) { if (scope.isObject()) { @@ -228,39 +270,11 @@ private: } } - QScriptValue extraScope; - if (value->sourceUsesBase()) { - QScriptValue baseValue; - if (value->baseValue()) { - SVConverter converter(scriptClass, object, value->baseValue(), itemOfProperty, - propertyName, data, &baseValue); - converter.start(); - } - setupConvenienceProperty(QLatin1String("base"), &extraScope, baseValue); - } - if (value->sourceUsesOuter() && outerItem) { - const QScriptValue v = data->evaluator->property(outerItem, *propertyName); - if (engine->hasErrorOrException(v)) { - *result = engine->lastErrorValue(v); - return; - } - setupConvenienceProperty(QLatin1String("outer"), &extraScope, v); - } - if (value->sourceUsesOriginal()) { - QScriptValue originalValue; - if (data->item->propertyDeclaration(propertyName->toString()).isScalar()) { - const Item *item = itemOfProperty; - while (item->type() == ItemType::ModuleInstance) - item = item->prototype(); - SVConverter converter(scriptClass, object, item->property(*propertyName), item, - propertyName, data, &originalValue); - converter.start(); - } else { - originalValue = engine->newArray(0); - } - setupConvenienceProperty(QLatin1String("original"), &extraScope, originalValue); + auto maybeExtraScope = createExtraScope(value, outerItem); + if (!maybeExtraScope.second) { + *result = maybeExtraScope.first; + return; } - const Evaluator::FileContextScopes fileCtxScopes = data->evaluator->fileContextScopes(value->file()); pushScope(fileCtxScopes.fileScope); @@ -271,7 +285,7 @@ private: } if (value->definingItem()) pushItemScopes(value->definingItem()); - pushScope(extraScope); + pushScope(maybeExtraScope.first); const QScriptValue &theImportScope = fileCtxScopes.importScope; if (theImportScope.isError()) { *result = theImportScope; |