diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-17 10:01:42 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-23 06:51:16 +0100 |
commit | f8f31dd0e1f9425ba272691c79e719ebc4bcfb94 (patch) | |
tree | 1f79039e87d9c43905f678e11fe902766fe72ed1 /src/qml/jsapi | |
parent | 78aea267209c34abeb4895712dc76c923aa46165 (diff) |
Implement some unary operators on QJSPrimitiveValue
operator++ is not actually the same as += 1, for example.
Change-Id: If1069a9a47170707faee11be05424188027bb0b5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r-- | src/qml/jsapi/qjsprimitivevalue.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsprimitivevalue.h b/src/qml/jsapi/qjsprimitivevalue.h index f4488adad1..363a2e8c43 100644 --- a/src/qml/jsapi/qjsprimitivevalue.h +++ b/src/qml/jsapi/qjsprimitivevalue.h @@ -327,6 +327,43 @@ public: return std::fmod(lhs.toDouble(), rhs.toDouble()); } + QJSPrimitiveValue &operator++() + { + // ++a is modeled as a -= (-1) to avoid the potential string concatenation + return (*this = operate<SubOperators>(*this, -1)); + } + + QJSPrimitiveValue operator++(int) + { + // a++ is modeled as a -= (-1) to avoid the potential string concatenation + QJSPrimitiveValue other = operate<SubOperators>(*this, -1); + std::swap(other, *this); + return +other; // We still need to coerce the original value. + } + + QJSPrimitiveValue &operator--() + { + return (*this = operate<SubOperators>(*this, 1)); + } + + QJSPrimitiveValue operator--(int) + { + QJSPrimitiveValue other = operate<SubOperators>(*this, 1); + std::swap(other, *this); + return +other; // We still need to coerce the original value. + } + + QJSPrimitiveValue operator+() + { + // +a is modeled as a -= 0. That should force it to number. + return (*this = operate<SubOperators>(*this, 0)); + } + + QJSPrimitiveValue operator-() + { + return (*this = operate<MulOperators>(*this, -1)); + } + constexpr bool strictlyEquals(const QJSPrimitiveValue &other) const { const Type myType = type(); |