Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_IGUIObject.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | else if (propName == "name") | ||||
return true; | return true; | ||||
} | } | ||||
else if (e->SettingExists(propName)) | else if (e->SettingExists(propName)) | ||||
{ | { | ||||
e->m_Settings[propName]->ToJSVal(cx, vp); | e->m_Settings[propName]->ToJSVal(cx, vp); | ||||
return true; | return true; | ||||
} | } | ||||
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); | LOGERROR("Property '%s' does not exist!", propName.c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | ||||
{ | { | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | ||||
if (!e) | if (!e) | ||||
return result.fail(JSMSG_NOT_NONNULL_OBJECT); | return result.fail(JSMSG_NOT_NONNULL_OBJECT); | ||||
Show All 20 Lines | bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) | ||||
if (vp.isObject()) | if (vp.isObject()) | ||||
vpObj = &vp.toObject(); | vpObj = &vp.toObject(); | ||||
// Use onWhatever to set event handlers | // Use onWhatever to set event handlers | ||||
if (propName.substr(0, 2) == "on") | if (propName.substr(0, 2) == "on") | ||||
{ | { | ||||
if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject())) | if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject())) | ||||
{ | { | ||||
JS_ReportError(cx, "on- event-handlers must be functions"); | LOGERROR("on- event-handlers must be functions"); | ||||
return result.fail(JSMSG_NOT_FUNCTION); | return result.fail(JSMSG_NOT_FUNCTION); | ||||
} | } | ||||
CStr eventName(propName.substr(2)); | CStr eventName(propName.substr(2)); | ||||
e->SetScriptHandler(eventName, vpObj); | e->SetScriptHandler(eventName, vpObj); | ||||
return result.succeed(); | return result.succeed(); | ||||
} | } | ||||
if (e->SettingExists(propName)) | if (e->SettingExists(propName)) | ||||
return e->m_Settings[propName]->FromJSVal(cx, vp, true) ? result.succeed() : result.fail(JSMSG_TYPE_ERR_BAD_ARGS); | return e->m_Settings[propName]->FromJSVal(cx, vp, true) ? result.succeed() : result.fail(JSMSG_TYPE_ERR_BAD_ARGS); | ||||
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); | LOGERROR("Property '%s' does not exist!", propName.c_str()); | ||||
return result.fail(JSMSG_UNDEFINED_PROP); | return result.fail(JSMSG_UNDEFINED_PROP); | ||||
} | } | ||||
bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result) | bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result) | ||||
{ | { | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class); | ||||
if (!e) | if (!e) | ||||
return result.fail(JSMSG_NOT_NONNULL_OBJECT); | return result.fail(JSMSG_NOT_NONNULL_OBJECT); | ||||
Show All 10 Lines | bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result) | ||||
// event handlers | // event handlers | ||||
if (propName.substr(0, 2) == "on") | if (propName.substr(0, 2) == "on") | ||||
{ | { | ||||
CStr eventName(propName.substr(2)); | CStr eventName(propName.substr(2)); | ||||
e->UnsetScriptHandler(eventName); | e->UnsetScriptHandler(eventName); | ||||
return result.succeed(); | return result.succeed(); | ||||
} | } | ||||
JS_ReportError(cx, "Only event handlers can be deleted from GUI objects!"); | LOGERROR("Only event handlers can be deleted from GUI objects!"); | ||||
return result.fail(JSMSG_UNDEFINED_PROP); | return result.fail(JSMSG_UNDEFINED_PROP); | ||||
} | } | ||||
bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) | bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
// No JSAutoRequest needed for these calls | // No JSAutoRequest needed for these calls | ||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator