mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Implement FromJSVal<IObject*> safely
By making all GUI proxy objects share the same class, we can easily confirm if a given JS object is one, and from there convert to the appropriate types. Differential Revision: https://code.wildfiregames.com/D3907 This was SVN commit r25347.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "gui/SettingTypes/CGUIList.h"
|
||||
#include "gui/SettingTypes/CGUISeries.h"
|
||||
#include "gui/SettingTypes/CGUISize.h"
|
||||
#include "gui/Scripting/JSInterface_GUIProxy.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "maths/Size2D.h"
|
||||
#include "maths/Vector2D.h"
|
||||
@@ -136,6 +137,22 @@ template<> void ScriptInterface::ToJSVal<IGUIObject*>(const ScriptRequest& UNUSE
|
||||
ret.setObject(*val->GetJSObject());
|
||||
}
|
||||
|
||||
template<> bool ScriptInterface::FromJSVal<IGUIObject*>(const ScriptRequest& rq, JS::HandleValue v, IGUIObject*& out)
|
||||
{
|
||||
if (!v.isObject())
|
||||
{
|
||||
ScriptException::Raise(rq, "Value is not an IGUIObject.");
|
||||
return false;
|
||||
}
|
||||
out = IGUIProxyObject::FromPrivateSlot<IGUIObject>(v.toObjectOrNull());
|
||||
if (!out)
|
||||
{
|
||||
ScriptException::Raise(rq, "Value is not an IGUIObject.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> void ScriptInterface::ToJSVal<CGUIString>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUIString& val)
|
||||
{
|
||||
ScriptInterface::ToJSVal(rq, ret, val.GetOriginalString());
|
||||
|
||||
Reference in New Issue
Block a user