diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-10 18:07:26 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-18 14:23:29 +0100 |
commit | d2e331dfa02475e773e51af6e7532951f4d1a233 (patch) | |
tree | d16f2ef9cfd363ff09d06fed70b226ccb212f3ca /src/qml/jsapi/qjsvalue.cpp | |
parent | 31211f1415f221ed1a974663fdde117fd6de357d (diff) |
Allow JavaScript primitive type transformations inline in C++
We don't want to call into the engine just for adding two numbers.
This implements the most common operators on primitive JavaScript
values. More are to follow in the future.
Change-Id: Id51a5af59a3af9fec78a2d8f293e59e6567e9204
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsvalue.cpp')
-rw-r--r-- | src/qml/jsapi/qjsvalue.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index ad5ab95408..ce3ab0076b 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -42,6 +42,7 @@ #include <QtCore/qdatetime.h> #include "qjsengine.h" #include "qjsvalue.h" +#include "qjsprimitivevalue.h" #include "qjsvalue_p.h" #include "qv4value_p.h" #include "qv4object_p.h" @@ -857,6 +858,32 @@ QJSValue& QJSValue::operator=(const QJSValue& other) return *this; } +QJSValue::QJSValue(QJSPrimitiveValue &&value) +{ + switch (value.type()) { + case QJSPrimitiveValue::Undefined: + d = QV4::Encode::undefined(); + return; + case QJSPrimitiveValue::Null: + d = QV4::Encode::null(); + return; + case QJSPrimitiveValue::Boolean: + d = QV4::Encode(value.asBoolean()); + return; + case QJSPrimitiveValue::Integer: + d = QV4::Encode(value.asInteger()); + return; + case QJSPrimitiveValue::Double: + d = QV4::Encode(value.asDouble()); + return; + case QJSPrimitiveValue::String: + QJSValuePrivate::setString(this, std::move(std::get<QString>(value.d))); + return; + } + + Q_UNREACHABLE(); +} + static bool js_equal(const QString &string, const QV4::Value &value) { if (String *s = value.stringValue()) |