diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-11 13:35:53 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-18 17:26:51 +0100 |
commit | 6f181768a3147bbfa9a33cf2c05453365693f5b9 (patch) | |
tree | 3ff80238b5784032c86cfc1a70088e17b62a7127 /src/qml/jsapi/qjsvalue.cpp | |
parent | d5ac54da624dbaebc865c8243a5e1c33d5e1c7ba (diff) |
Add a QJSManagedValue
A QJSManagedValue is a view on a QJSValue which always knows the engine
the value belongs to. This allows us to implement the JavaScript
semantics of the various QJSValue methods in a much more rigorous way.
[ChangeLog][QtQml] The new QJSManagedValue should be used instead of
QJSValue for manipulating properties and prototypes of JavaScript
values, as well as for calling JavaScript functions.
Change-Id: I9d445ffcf68dfa72dba9bae0818e83c80665ad66
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsvalue.cpp')
-rw-r--r-- | src/qml/jsapi/qjsvalue.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index ce3ab0076b..5525aee595 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -43,6 +43,7 @@ #include "qjsengine.h" #include "qjsvalue.h" #include "qjsprimitivevalue.h" +#include "qjsmanagedvalue.h" #include "qjsvalue_p.h" #include "qv4value_p.h" #include "qv4object_p.h" @@ -884,6 +885,20 @@ QJSValue::QJSValue(QJSPrimitiveValue &&value) Q_UNREACHABLE(); } +QJSValue::QJSValue(QJSManagedValue &&value) +{ + if (!value.d) { + d = QV4::Encode::undefined(); + } else if (value.d->isManaged()) { + QJSValuePrivate::setRawValue(this, value.d); + value.d = nullptr; + } else { + d = value.d->asReturnedValue(); + QV4::PersistentValueStorage::free(value.d); + value.d = nullptr; + } +} + static bool js_equal(const QString &string, const QV4::Value &value) { if (String *s = value.stringValue()) |