Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/Scripting/JSInterface_GUIProxy.h
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | class IGUIProxyObject final | ||||
friend std::unique_ptr<IGUIProxyObject> std::make_unique<IGUIProxyObject>(); | friend std::unique_ptr<IGUIProxyObject> std::make_unique<IGUIProxyObject>(); | ||||
public: | public: | ||||
JSObject* Get() const | JSObject* Get() const | ||||
{ | { | ||||
return m_Object.get(); | return m_Object.get(); | ||||
} | } | ||||
using PrivateData = IGUIObject*; | using PrivateData = IGUIObject*; | ||||
template<typename T> | template<typename T> | ||||
static T* FromPrivateSlot(JSObject* obj) | static T* FromPrivateSlot(JSObject* obj) | ||||
{ | { | ||||
return static_cast<T*>(FromPrivateSlot<IGUIObject>(obj)); | |||||
} | |||||
protected: | |||||
template<typename T> | |||||
static T* UnsafeFromPrivateSlot(JSObject* obj) | |||||
{ | |||||
return static_cast<T*>(static_cast<PrivateData>(js::GetProxyPrivate(obj).toPrivate())); | return static_cast<T*>(static_cast<PrivateData>(js::GetProxyPrivate(obj).toPrivate())); | ||||
} | } | ||||
protected: | |||||
IGUIProxyObject() = default; | IGUIProxyObject() = default; | ||||
IGUIProxyObject(const IGUIProxyObject&) = delete; | IGUIProxyObject(const IGUIProxyObject&) = delete; | ||||
IGUIProxyObject(IGUIProxyObject&&) = delete; | IGUIProxyObject(IGUIProxyObject&&) = delete; | ||||
JS::PersistentRootedObject m_Object; | JS::PersistentRootedObject m_Object; | ||||
PrivateData m_Ptr; | PrivateData m_Ptr; | ||||
}; | }; | ||||
// Declare the IGUIObject* specialization - it's defined in _impl.h | |||||
template<> IGUIObject* IGUIProxyObject::FromPrivateSlot<IGUIObject>(JSObject*); | |||||
/** | /** | ||||
* Proxies need to store some data whose lifetime is tied to an interface. | * Proxies need to store some data whose lifetime is tied to an interface. | ||||
* This is the virtual interface of that data. | * This is the virtual interface of that data. | ||||
*/ | */ | ||||
class GUIProxyProps | class GUIProxyProps | ||||
{ | { | ||||
public: | public: | ||||
Show All 30 Lines | |||||
*/ | */ | ||||
template<typename GUIObjectType> | template<typename GUIObjectType> | ||||
class JSI_GUIProxy : public js::BaseProxyHandler | class JSI_GUIProxy : public js::BaseProxyHandler | ||||
{ | { | ||||
// Need to friend other specializations so CreateFunctions() can call the IGUIObject version in all codepaths. | // Need to friend other specializations so CreateFunctions() can call the IGUIObject version in all codepaths. | ||||
template<typename T> | template<typename T> | ||||
friend class JSI_GUIProxy; | friend class JSI_GUIProxy; | ||||
public: | public: | ||||
// Access the js::Class of the Proxy. | |||||
static JSClass& ClassDefinition(); | |||||
// For convenience, this is the single instantiated JSI_GUIProxy. | // For convenience, this is the single instantiated JSI_GUIProxy. | ||||
static JSI_GUIProxy& Singleton(); | static JSI_GUIProxy& Singleton(); | ||||
// Call this in CGUI::AddObjectTypes. | // Call this in CGUI::AddObjectTypes. | ||||
static std::pair<const js::BaseProxyHandler*, GUIProxyProps*> CreateData(ScriptInterface& scriptInterface); | static std::pair<const js::BaseProxyHandler*, GUIProxyProps*> CreateData(ScriptInterface& scriptInterface); | ||||
// Create the JS object, the proxy, the data and wrap it in a convenient unique_ptr. | // Create the JS object, the proxy, the data and wrap it in a convenient unique_ptr. | ||||
static std::unique_ptr<IGUIProxyObject> CreateJSObject(const ScriptRequest& rq, GUIObjectType* ptr, GUIProxyProps* data); | static std::unique_ptr<IGUIProxyObject> CreateJSObject(const ScriptRequest& rq, GUIObjectType* ptr, GUIProxyProps* data); | ||||
protected: | protected: | ||||
// @param family can't be nullptr because that's used for some DOM object and it crashes. | // @param family can't be nullptr because that's used for some DOM object and it crashes. | ||||
JSI_GUIProxy() : BaseProxyHandler(this, false, false) {}; | JSI_GUIProxy() : BaseProxyHandler(this, false, false) {}; | ||||
// Note: SM provides no virtual destructor for baseProxyHandler. | // Note: SM provides no virtual destructor for baseProxyHandler. | ||||
// This also enforces making proxy handlers dataless static variables. | // This also enforces making proxy handlers dataless static variables. | ||||
~JSI_GUIProxy() {}; | ~JSI_GUIProxy() {}; | ||||
static GUIObjectType* FromPrivateSlot(const ScriptRequest&, JS::CallArgs& args); | |||||
// The default implementations need to know the type of the GUIProxyProps for this proxy type. | // The default implementations need to know the type of the GUIProxyProps for this proxy type. | ||||
// This is done by specializing this struct's alias type. | // This is done by specializing this struct's alias type. | ||||
struct PropCache; | struct PropCache; | ||||
// Specialize this to define the custom properties of this type. | // Specialize this to define the custom properties of this type. | ||||
static void CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache); | static void CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache); | ||||
// Convenience helper for the above. | // Convenience helper for the above. | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator