18#ifndef INCLUDED_JSI_GUIPROXY
19#define INCLUDED_JSI_GUIPROXY
24#include <js/GCVector.h>
26#include <js/PropertyDescriptor.h>
28#include <js/RootingAPI.h>
29#include <js/TypeDecls.h>
39namespace JS {
class CallArgs; }
40namespace Script {
class Interface; }
41namespace Script {
class Request; }
45# pragma GCC diagnostic push
46# pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
48# pragma warning(push, 1)
49# pragma warning(disable: 4265)
60 friend std::unique_ptr<IGUIProxyObject> std::make_unique<IGUIProxyObject>();
72 return static_cast<T*
>(FromPrivateSlot<IGUIObject>(obj));
78 return static_cast<T*
>(
static_cast<PrivateData>(js::GetProxyPrivate(obj).toPrivate()));
89template<>
IGUIObject* IGUIProxyObject::FromPrivateSlot<IGUIObject>(JSObject*);
101 virtual bool has(
const std::string& name)
const = 0;
103 virtual JSObject*
get(
const std::string& name)
const = 0;
130template<
typename GUIObjectType>
163 template<auto callable>
167 bool PropGetter(JS::HandleObject proxy,
const std::string& propName, JS::MutableHandleValue vp)
const;
172 bool get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue receiver, JS::HandleId
id, JS::MutableHandleValue vp)
const final;
174 bool set(JSContext* cx, JS::HandleObject proxy, JS::HandleId
id, JS::HandleValue vp,
175 JS::HandleValue receiver, JS::ObjectOpResult& result)
const final;
177 bool delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId
id, JS::ObjectOpResult& result)
const final;
182 bool getOwnPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId
id, JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc)
const final;
186 JS::Handle<JS::PropertyDescriptor>, JS::ObjectOpResult& )
const override
191 bool ownPropertyKeys(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleIdVector props)
const final;
195 JS::MutableHandleIdVector )
const override
201 JS::MutableHandleObject )
const override
207 bool* )
const override
213 JS::ObjectOpResult& )
const override
217 bool isExtensible(JSContext*, JS::HandleObject ,
bool* extensible)
const override
225# pragma GCC diagnostic pop
Proxies need to store some data whose lifetime is tied to an interface.
Definition: JSInterface_GUIProxy.h:96
virtual bool setFunction(const Script::Request &rq, const std::string &name, JSFunction *function)=0
virtual bool has(const std::string &name) const =0
virtual std::vector< std::string_view > getPropsNames() const =0
virtual JSObject * get(const std::string &name) const =0
virtual ~GUIProxyProps()
Definition: JSInterface_GUIProxy.h:98
GUI object such as a button or an input-box.
Definition: IGUIObject.h:63
JS GUI proxies need to store some private data.
Definition: JSInterface_GUIProxy.h:57
IGUIProxyObject(IGUIProxyObject &&)=delete
JS::PersistentRootedObject m_Object
Definition: JSInterface_GUIProxy.h:85
static T * FromPrivateSlot(JSObject *obj)
Definition: JSInterface_GUIProxy.h:70
IGUIProxyObject()=default
static T * UnsafeFromPrivateSlot(JSObject *obj)
Definition: JSInterface_GUIProxy.h:76
PrivateData m_Ptr
Definition: JSInterface_GUIProxy.h:86
IGUIProxyObject(const IGUIProxyObject &)=delete
JSObject * Get() const
Definition: JSInterface_GUIProxy.h:62
Handles the js interface with C++ GUI objects.
Definition: JSInterface_GUIProxy.h:132
static GUIObjectType * FromPrivateSlot(const Script::Request &, JS::CallArgs &args)
Definition: JSInterface_GUIProxy_impl.h:140
bool ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const final
Definition: JSInterface_GUIProxy_impl.h:364
~JSI_GUIProxy()
Definition: JSInterface_GUIProxy.h:151
bool getPrototypeIfOrdinary(JSContext *, JS::HandleObject, bool *, JS::MutableHandleObject) const override
Definition: JSInterface_GUIProxy.h:200
bool enumerate(JSContext *, JS::HandleObject, JS::MutableHandleIdVector) const override
Definition: JSInterface_GUIProxy.h:194
bool delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, JS::ObjectOpResult &result) const final
Definition: JSInterface_GUIProxy_impl.h:332
bool PropGetter(JS::HandleObject proxy, const std::string &propName, JS::MutableHandleValue vp) const
Definition: JSInterface_GUIProxy_impl.h:147
static std::unique_ptr< IGUIProxyObject > CreateJSObject(const Script::Request &rq, GUIObjectType *ptr, GUIProxyProps *data)
Definition: JSInterface_GUIProxy_impl.h:184
bool preventExtensions(JSContext *, JS::HandleObject, JS::ObjectOpResult &) const override
Definition: JSInterface_GUIProxy.h:212
static JSI_GUIProxy & Singleton()
Definition: JSInterface_GUIProxy_impl.h:58
bool isExtensible(JSContext *, JS::HandleObject, bool *extensible) const override
Definition: JSInterface_GUIProxy.h:217
static void CreateFunction(const Script::Request &rq, GUIProxyProps *cache, const std::string &name)
Definition: JSInterface_GUIProxy_impl.h:178
bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, JS::MutableHandle< mozilla::Maybe< JS::PropertyDescriptor > > desc) const final
Definition: JSInterface_GUIProxy_impl.h:425
bool defineProperty(JSContext *, JS::HandleObject, JS::HandleId, JS::Handle< JS::PropertyDescriptor >, JS::ObjectOpResult &) const override
Definition: JSInterface_GUIProxy.h:185
bool set(JSContext *cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue vp, JS::HandleValue receiver, JS::ObjectOpResult &result) const final
Definition: JSInterface_GUIProxy_impl.h:276
static std::pair< const js::BaseProxyHandler *, GUIProxyProps * > CreateData(Script::Interface &scriptInterface)
Definition: JSInterface_GUIProxy_impl.h:161
static void CreateFunctions(const Script::Request &rq, GUIProxyProps *cache)
bool get(JSContext *cx, JS::HandleObject proxy, JS::HandleValue receiver, JS::HandleId id, JS::MutableHandleValue vp) const final
Definition: JSInterface_GUIProxy_impl.h:201
JSI_GUIProxy()
Definition: JSInterface_GUIProxy.h:147
bool setImmutablePrototype(JSContext *, JS::HandleObject, bool *) const override
Definition: JSInterface_GUIProxy.h:206
Definition: Interface.h:93
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
#define T(string_literal)
Definition: secure_crt.cpp:81