1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QV4VARIANTOBJECT_P_H
5#define QV4VARIANTOBJECT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qglobal.h>
19#include <QtQml/qqmllist.h>
20#include <QtCore/qvariant.h>
21
22#include <private/qv4value_p.h>
23#include <private/qv4object_p.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QV4 {
28
29namespace Heap {
30
31struct VariantObject : Object
32{
33 void init();
34 void init(const QMetaType type, const void *data);
35 void destroy() {
36 Q_ASSERT(scarceData);
37 if (isScarce())
38 addVmePropertyReference();
39 delete scarceData;
40 Object::destroy();
41 }
42 bool isScarce() const;
43 int vmePropertyReferenceCount;
44
45 const QVariant &data() const { return scarceData->data; }
46 QVariant &data() { return scarceData->data; }
47
48 void addVmePropertyReference() { scarceData->node.remove(); }
49 void removeVmePropertyReference() { internalClass->engine->scarceResources.insert(n: scarceData); }
50
51private:
52 ExecutionEngine::ScarceResourceData *scarceData;
53};
54
55}
56
57struct VariantObject : Object
58{
59 V4_OBJECT2(VariantObject, Object)
60 V4_PROTOTYPE(variantPrototype)
61 V4_NEEDS_DESTROY
62
63 void addVmePropertyReference() const;
64 void removeVmePropertyReference() const;
65
66protected:
67 static bool virtualIsEqualTo(Managed *m, Managed *other);
68};
69
70struct VariantPrototype : VariantObject
71{
72public:
73 V4_PROTOTYPE(objectPrototype)
74 void init();
75
76 static ReturnedValue method_preserve(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
77 static ReturnedValue method_destroy(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
78 static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
79 static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
80};
81
82}
83
84QT_END_NAMESPACE
85
86#endif
87
88

source code of qtdeclarative/src/qml/jsruntime/qv4variantobject_p.h