1// Copyright (C) 2018 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#ifndef QV4PROXY_P_H
4#define QV4PROXY_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4object_p.h"
18#include "qv4functionobject_p.h"
19
20QT_BEGIN_NAMESPACE
21
22namespace QV4 {
23
24namespace Heap {
25
26#define ProxyObjectMembers(class, Member) \
27 Member(class, Pointer, Object *, target) \
28 Member(class, Pointer, Object *, handler)
29
30DECLARE_HEAP_OBJECT(ProxyObject, FunctionObject) {
31 DECLARE_MARKOBJECTS(ProxyObject)
32
33 void init(const QV4::Object *target, const QV4::Object *handler);
34};
35
36struct ProxyFunctionObject : ProxyObject {
37 void init(const QV4::FunctionObject *target, const QV4::Object *handler);
38};
39
40#define ProxyMembers(class, Member) \
41 Member(class, Pointer, Symbol *, revokableProxySymbol) \
42
43DECLARE_HEAP_OBJECT(Proxy, FunctionObject) {
44 DECLARE_MARKOBJECTS(Proxy)
45
46 void init(QV4::ExecutionContext *ctx);
47};
48
49}
50
51/*
52 * The inheritance from FunctionObject is a hack. Regular proxy objects are no function objects.
53 * But this helps implement the proxy for function objects, where we need this and thus gives us
54 * all the virtual methods from ProxyObject without having to duplicate them.
55 *
56 * But it does require a few hacks to make sure we don't recognize regular proxy objects as function
57 * objects in the runtime.
58 */
59struct ProxyObject : FunctionObject {
60 V4_OBJECT2(ProxyObject, Object)
61 Q_MANAGED_TYPE(ProxyObject)
62 V4_INTERNALCLASS(ProxyObject)
63 enum {
64 IsFunctionObject = false
65 };
66
67 static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty);
68 static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver);
69 static bool virtualDeleteProperty(Managed *m, PropertyKey id);
70 static bool virtualHasProperty(const Managed *m, PropertyKey id);
71 static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p);
72 static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs);
73 static bool virtualIsExtensible(const Managed *m);
74 static bool virtualPreventExtensions(Managed *);
75 static Heap::Object *virtualGetPrototypeOf(const Managed *);
76 static bool virtualSetPrototypeOf(Managed *, const Object *);
77 static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *iteratorTarget);
78};
79
80struct ProxyFunctionObject : ProxyObject {
81 V4_OBJECT2(ProxyFunctionObject, FunctionObject)
82 Q_MANAGED_TYPE(ProxyObject)
83 V4_INTERNALCLASS(ProxyFunctionObject)
84 enum {
85 IsFunctionObject = true
86 };
87
88 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
89 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
90};
91
92struct Proxy : FunctionObject
93{
94 V4_OBJECT2(Proxy, FunctionObject)
95
96 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
97 static ReturnedValue virtualCall(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
98
99 static ReturnedValue method_revocable(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
100
101 static ReturnedValue method_revoke(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
102};
103
104}
105
106QT_END_NAMESPACE
107
108#endif // QV4ECMAOBJECTS_P_H
109

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