aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2016-08-24 14:13:04 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2016-08-29 08:34:10 +0000
commit33d36b3f2f8c2a9e28542f423d33385b0cb8f372 (patch)
tree5662c920b123ec354147842a9503cb8d7da1098a
parentee6d55dd955382b70228f469e785243761aa658d (diff)
More sensible fallback values for "base" & friends
When setting up the values of special properties like "base", "outer" and "original", we replaced invalid and undefined values with an empty array. This is all nice and well for array properties (so that people can write "base.concat()" without checking base first), but quite absurd for scalar properties. So for the latter, the only thing we do now is replace invalid values with undefined ones. The behavior for arrays stays the same. Change-Id: Icb3c74927c84025a07e3ef6c9c67b89d95320632 Reviewed-by: Jake Petroules <jake.petroules@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/lib/corelib/language/evaluatorscriptclass.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp
index bbfdf56a1..ecd7890db 100644
--- a/src/lib/corelib/language/evaluatorscriptclass.cpp
+++ b/src/lib/corelib/language/evaluatorscriptclass.cpp
@@ -98,13 +98,19 @@ private:
{
if (!extraScope->isObject())
*extraScope = scriptClass->engine()->newObject();
- if (!scriptValue.isValid() || scriptValue.isUndefined()) {
- // If there's no such value, use an empty array to have the convenience property
- // still available.
- extraScope->setProperty(conveniencePropertyName, engine->newArray());
- } else {
- extraScope->setProperty(conveniencePropertyName, scriptValue);
+ const PropertyDeclaration::Type type
+ = itemOfProperty->propertyDeclaration(propertyName->toString()).type();
+ const bool isArray = type == PropertyDeclaration::StringList
+ || type == PropertyDeclaration::PathList
+ || type == PropertyDeclaration::Variant;
+ QScriptValue valueToSet = scriptValue;
+ if (isArray) {
+ if (!valueToSet.isValid() || valueToSet.isUndefined())
+ valueToSet = engine->newArray();
+ } else if (!valueToSet.isValid()) {
+ valueToSet = engine->undefinedValue();
}
+ extraScope->setProperty(conveniencePropertyName, valueToSet);
}
void pushScope(const QScriptValue &scope)