mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-22 07:46:53 +00:00
Allowed JS access to GUI object event handlers, via object.onPress etc.
Stopped crashes when ordering entities without bounding boxes. This was SVN commit r2079.
This commit is contained in:
@@ -49,6 +49,19 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
|
||||
IGUIObject* e = (IGUIObject*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// Use onWhatever to access event handlers
|
||||
if (propName.Left(2) == "on")
|
||||
{
|
||||
CStr eventName (CStr(propName.substr(2)).LowerCase());
|
||||
std::map<CStr, JSFunction*>::iterator it = e->m_ScriptHandlers.find(eventName);
|
||||
if (it == e->m_ScriptHandlers.end())
|
||||
*vp = JSVAL_NULL;
|
||||
else
|
||||
*vp = OBJECT_TO_JSVAL(JS_GetFunctionObject(it->second));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Handle the "parent" property specially
|
||||
if (propName == "parent")
|
||||
{
|
||||
@@ -248,6 +261,20 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// Use onWhatever to set event handlers
|
||||
if (propName.Left(2) == "on")
|
||||
{
|
||||
JSFunction* func = JS_ValueToFunction(cx, *vp);
|
||||
if (! func)
|
||||
{
|
||||
JS_ReportError(cx, "on- event-handlers must be functions");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
CStr eventName (CStr(propName.substr(2)).LowerCase());
|
||||
e->m_ScriptHandlers[eventName] = func;
|
||||
}
|
||||
|
||||
// Retrieve the setting's type (and make sure it actually exists)
|
||||
EGUISettingType Type;
|
||||
if (e->GetSettingType(propName, Type) != PS_OK)
|
||||
|
||||
Reference in New Issue
Block a user