diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-08-23 16:06:26 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-08-23 19:18:19 +0000 |
commit | 732c25029ec95feb27a607ef19bb3b7423a955a1 (patch) | |
tree | c53e44cf7b7cd4555bc34aedf0474ca128292d40 /src/qml/jsruntime/qv4proxy_p.h | |
parent | f15cc9f1df8e17f049c111e3147d6c63c07eb756 (diff) |
Implement support for call/callAsConstructor in Proxy objects
This adds the last missing piece of functionality for
Proxy objects.
Also fix a bug where we ignored the newTarget in
Reflect.construct.
Change-Id: I2443470f2ca13fb6223768c3bf6bdc3766bb4fc3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4proxy_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4proxy_p.h | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4proxy_p.h b/src/qml/jsruntime/qv4proxy_p.h index bad4d040c7..7c10b91b13 100644 --- a/src/qml/jsruntime/qv4proxy_p.h +++ b/src/qml/jsruntime/qv4proxy_p.h @@ -63,12 +63,16 @@ namespace Heap { Member(class, Pointer, Object *, target) \ Member(class, Pointer, Object *, handler) -DECLARE_HEAP_OBJECT(ProxyObject, Object) { +DECLARE_HEAP_OBJECT(ProxyObject, FunctionObject) { DECLARE_MARKOBJECTS(ProxyObject) void init(const QV4::Object *target, const QV4::Object *handler); }; +struct ProxyFunctionObject : ProxyObject { + void init(const QV4::FunctionObject *target, const QV4::Object *handler); +}; + #define ProxyMembers(class, Member) \ Member(class, Pointer, Symbol *, revokableProxySymbol) \ @@ -80,10 +84,21 @@ DECLARE_HEAP_OBJECT(Proxy, FunctionObject) { } -struct ProxyObject: Object { +/* + * The inheritance from FunctionObject is a hack. Regular proxy objects are no function objects. + * But this helps implement the proxy for function objects, where we need this and thus gives us + * all the virtual methods from ProxyObject without having to duplicate them. + * + * But it does require a few hacks to make sure we don't recognize regular proxy objects as function + * objects in the runtime. + */ +struct ProxyObject : FunctionObject { V4_OBJECT2(ProxyObject, Object) Q_MANAGED_TYPE(ProxyObject) V4_INTERNALCLASS(ProxyObject) + enum { + IsFunctionObject = false + }; static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); @@ -96,10 +111,18 @@ struct ProxyObject: Object { static Heap::Object *virtualGetPrototypeOf(const Managed *); static bool virtualSetPrototypeOf(Managed *, const Object *); static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m); +}; - // those might require a second proxy object that derives from FunctionObject... -// static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); -// static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); +struct ProxyFunctionObject : ProxyObject { + V4_OBJECT2(ProxyFunctionObject, FunctionObject) + Q_MANAGED_TYPE(ProxyObject) + V4_INTERNALCLASS(ProxyFunctionObject) + enum { + IsFunctionObject = true + }; + + static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); + static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); }; struct Proxy : FunctionObject |