| 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 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | namespace QV4 { |
| 23 | |
| 24 | namespace Heap { |
| 25 | |
| 26 | #define ProxyObjectMembers(class, Member) \ |
| 27 | Member(class, Pointer, Object *, target) \ |
| 28 | Member(class, Pointer, Object *, handler) |
| 29 | |
| 30 | DECLARE_HEAP_OBJECT(ProxyObject, FunctionObject) { |
| 31 | DECLARE_MARKOBJECTS(ProxyObject) |
| 32 | |
| 33 | void init(const QV4::Object *target, const QV4::Object *handler); |
| 34 | }; |
| 35 | |
| 36 | struct ProxyFunctionObject : ProxyObject { |
| 37 | void init(const QV4::FunctionObject *target, const QV4::Object *handler); |
| 38 | }; |
| 39 | |
| 40 | struct ProxyConstructorObject : ProxyFunctionObject {}; |
| 41 | |
| 42 | #define ProxyMembers(class, Member) \ |
| 43 | Member(class, Pointer, Symbol *, revokableProxySymbol) \ |
| 44 | |
| 45 | DECLARE_HEAP_OBJECT(Proxy, FunctionObject) { |
| 46 | DECLARE_MARKOBJECTS(Proxy) |
| 47 | |
| 48 | void init(ExecutionEngine *engine); |
| 49 | }; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * The inheritance from FunctionObject is a hack. Regular proxy objects are no function objects. |
| 55 | * But this helps implement the proxy for function objects, where we need this and thus gives us |
| 56 | * all the virtual methods from ProxyObject without having to duplicate them. |
| 57 | * |
| 58 | * But it does require a few hacks to make sure we don't recognize regular proxy objects as function |
| 59 | * objects in the runtime. |
| 60 | */ |
| 61 | struct ProxyObject : FunctionObject { |
| 62 | V4_OBJECT2(ProxyObject, Object) |
| 63 | Q_MANAGED_TYPE(ProxyObject) |
| 64 | V4_INTERNALCLASS(ProxyObject) |
| 65 | |
| 66 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); |
| 67 | static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); |
| 68 | static bool virtualDeleteProperty(Managed *m, PropertyKey id); |
| 69 | static bool virtualHasProperty(const Managed *m, PropertyKey id); |
| 70 | static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p); |
| 71 | static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs); |
| 72 | static bool virtualIsExtensible(const Managed *m); |
| 73 | static bool virtualPreventExtensions(Managed *); |
| 74 | static Heap::Object *virtualGetPrototypeOf(const Managed *); |
| 75 | static bool virtualSetPrototypeOf(Managed *, const Object *); |
| 76 | static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *iteratorTarget); |
| 77 | }; |
| 78 | |
| 79 | struct ProxyFunctionObject : ProxyObject { |
| 80 | V4_OBJECT2(ProxyFunctionObject, FunctionObject) |
| 81 | Q_MANAGED_TYPE(ProxyObject) |
| 82 | V4_INTERNALCLASS(ProxyFunctionObject) |
| 83 | |
| 84 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
| 85 | }; |
| 86 | |
| 87 | struct ProxyConstructorObject : ProxyFunctionObject { |
| 88 | V4_OBJECT2(ProxyConstructorObject, ProxyFunctionObject) |
| 89 | |
| 90 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); |
| 91 | }; |
| 92 | |
| 93 | struct Proxy : FunctionObject |
| 94 | { |
| 95 | V4_OBJECT2(Proxy, FunctionObject) |
| 96 | |
| 97 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); |
| 98 | static ReturnedValue virtualCall(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 99 | |
| 100 | static ReturnedValue method_revocable(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 101 | |
| 102 | static ReturnedValue method_revoke(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 103 | }; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | QT_END_NAMESPACE |
| 108 | |
| 109 | #endif // QV4ECMAOBJECTS_P_H |
| 110 | |