Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_GUIProxy_impl.h
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | void JSI_GUIProxy<T>::CreateJSObject(const ScriptRequest& rq, T* ptr, GUIProxyProps* dataPtr, JS::PersistentRootedObject& val) | ||||
JS::RootedValue cppObj(rq.cx), data(rq.cx); | JS::RootedValue cppObj(rq.cx), data(rq.cx); | ||||
cppObj.get().setPrivate(ptr); | cppObj.get().setPrivate(ptr); | ||||
data.get().setPrivate(static_cast<void*>(dataPtr)); | data.get().setPrivate(static_cast<void*>(dataPtr)); | ||||
val.init(rq.cx, js::NewProxyObject(rq.cx, &Singleton(), cppObj, nullptr, options)); | val.init(rq.cx, js::NewProxyObject(rq.cx, &Singleton(), cppObj, nullptr, options)); | ||||
js::SetProxyReservedSlot(val, 0, data); | js::SetProxyReservedSlot(val, 0, data); | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
bool JSI_GUIProxy<T>::has(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp) const | |||||
{ | |||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | |||||
ScriptRequest rq(*pScriptInterface); | |||||
T* e = static_cast<T*>(js::GetProxyPrivate(proxy.get()).toPrivate()); | |||||
if (!e) | |||||
return false; | |||||
JS::RootedValue idval(rq.cx); | |||||
if (!JS_IdToValue(rq.cx, id, &idval)) | |||||
return false; | |||||
std::string propName; | |||||
if (!ScriptInterface::FromJSVal(rq, idval, propName)) | |||||
return false; | |||||
*bp = propName == "parent" || propName == "name" || propName == "children" || e->SettingExists(propName) || propName.substr(0, 2) == "on"; | |||||
if (!*bp) | |||||
{ | |||||
JS::RootedValue temp(rq.cx); | |||||
*bp = PropGetter(proxy, propName, &temp); | |||||
} | |||||
return true; | |||||
} | |||||
template <typename T> | |||||
bool JSI_GUIProxy<T>::get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue UNUSED(receiver), JS::HandleId id, JS::MutableHandleValue vp) const | bool JSI_GUIProxy<T>::get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue UNUSED(receiver), JS::HandleId id, JS::MutableHandleValue vp) const | ||||
{ | { | ||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | ||||
ScriptRequest rq(*pScriptInterface); | ScriptRequest rq(*pScriptInterface); | ||||
T* e = static_cast<T*>(js::GetProxyPrivate(proxy.get()).toPrivate()); | T* e = static_cast<T*>(js::GetProxyPrivate(proxy.get()).toPrivate()); | ||||
if (!e) | if (!e) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator