| 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 QV4QMLCONTEXT_P_H |
| 5 | #define QV4QMLCONTEXT_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 <private/qqmlcontextdata_p.h> |
| 19 | #include <private/qtqmlglobal_p.h> |
| 20 | #include <private/qv4context_p.h> |
| 21 | #include <private/qv4object_p.h> |
| 22 | |
| 23 | #include <QtCore/qglobal.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace QV4 { |
| 28 | |
| 29 | struct QQmlContextWrapper; |
| 30 | |
| 31 | namespace Heap { |
| 32 | |
| 33 | #define QQmlContextWrapperMembers(class, Member) \ |
| 34 | Member(class, Pointer, Module *, module) |
| 35 | |
| 36 | DECLARE_HEAP_OBJECT(QQmlContextWrapper, Object) { |
| 37 | DECLARE_MARKOBJECTS(QQmlContextWrapper) |
| 38 | |
| 39 | void init(QQmlRefPointer<QQmlContextData> context, QObject *scopeObject); |
| 40 | void destroy(); |
| 41 | |
| 42 | // This has to be a plain pointer because object needs to be a POD type. |
| 43 | QQmlContextData *context; |
| 44 | QV4QPointer<QObject> scopeObject; |
| 45 | }; |
| 46 | |
| 47 | #define QmlContextMembers(class, Member) |
| 48 | |
| 49 | DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext) { |
| 50 | DECLARE_MARKOBJECTS(QmlContext) |
| 51 | |
| 52 | QQmlContextWrapper *qml() { return static_cast<QQmlContextWrapper *>(activation.get()); } |
| 53 | void init(QV4::ExecutionContext *outerContext, QV4::QQmlContextWrapper *qml); |
| 54 | }; |
| 55 | |
| 56 | } |
| 57 | |
| 58 | struct Q_QML_EXPORT QQmlContextWrapper : Object |
| 59 | { |
| 60 | V4_OBJECT2(QQmlContextWrapper, Object) |
| 61 | V4_NEEDS_DESTROY |
| 62 | V4_INTERNALCLASS(QmlContextWrapper) |
| 63 | |
| 64 | inline QObject *getScopeObject() const { return d()->scopeObject; } |
| 65 | inline QQmlRefPointer<QQmlContextData> getContext() const { return d()->context; } |
| 66 | |
| 67 | static ReturnedValue getPropertyAndBase(const QQmlContextWrapper *resource, PropertyKey id, const Value *receiver, |
| 68 | bool *hasProperty, Value *base, Lookup *lookup = nullptr); |
| 69 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); |
| 70 | static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); |
| 71 | |
| 72 | static ReturnedValue resolveQmlContextPropertyLookupGetter(Lookup *l, ExecutionEngine *engine, Value *base); |
| 73 | static ReturnedValue lookupScript(Lookup *l, ExecutionEngine *engine, Value *base); |
| 74 | static ReturnedValue lookupSingleton(Lookup *l, ExecutionEngine *engine, Value *base); |
| 75 | static ReturnedValue lookupValueSingleton(Lookup *l, ExecutionEngine *engine, Value *base); |
| 76 | static ReturnedValue lookupIdObject(Lookup *l, ExecutionEngine *engine, Value *base); |
| 77 | static ReturnedValue lookupIdObjectInParentContext(Lookup *l, ExecutionEngine *engine, Value *base); |
| 78 | static ReturnedValue lookupScopeObjectProperty(Lookup *l, ExecutionEngine *engine, Value *base); |
| 79 | static ReturnedValue lookupScopeObjectMethod(Lookup *l, ExecutionEngine *engine, Value *base); |
| 80 | static ReturnedValue lookupScopeFallbackProperty(Lookup *l, ExecutionEngine *engine, Value *base); |
| 81 | static ReturnedValue lookupContextObjectProperty(Lookup *l, ExecutionEngine *engine, Value *base); |
| 82 | static ReturnedValue lookupContextObjectMethod(Lookup *l, ExecutionEngine *engine, Value *base); |
| 83 | static ReturnedValue lookupInGlobalObject(Lookup *l, ExecutionEngine *engine, Value *base); |
| 84 | static ReturnedValue lookupInParentContextHierarchy(Lookup *l, ExecutionEngine *engine, Value *base); |
| 85 | static ReturnedValue lookupType(Lookup *l, ExecutionEngine *engine, Value *base); |
| 86 | }; |
| 87 | |
| 88 | struct Q_QML_EXPORT QmlContext : public ExecutionContext |
| 89 | { |
| 90 | V4_MANAGED(QmlContext, ExecutionContext) |
| 91 | V4_INTERNALCLASS(QmlContext) |
| 92 | |
| 93 | static Heap::QmlContext *create( |
| 94 | QV4::ExecutionContext *parent, QQmlRefPointer<QQmlContextData> context, |
| 95 | QObject *scopeObject); |
| 96 | |
| 97 | QObject *qmlScope() const { |
| 98 | return d()->qml()->scopeObject; |
| 99 | } |
| 100 | |
| 101 | QQmlRefPointer<QQmlContextData> qmlContext() const { |
| 102 | return d()->qml()->context; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | QT_END_NAMESPACE |
| 109 | |
| 110 | #endif |
| 111 | |
| 112 | |