Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp
Show All 30 Lines | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptExtraHeaders.h" | #include "scriptinterface/ScriptExtraHeaders.h" | ||||
JSClass JSI_IGUIObject::JSI_class = { | JSClass JSI_IGUIObject::JSI_class = { | ||||
"GUIObject", JSCLASS_HAS_PRIVATE, | "GUIObject", JSCLASS_HAS_PRIVATE, | ||||
nullptr, nullptr, | nullptr, nullptr, | ||||
JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, | JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, | ||||
nullptr, nullptr, nullptr, nullptr, | nullptr, nullptr, nullptr, nullptr, | ||||
nullptr, nullptr, JSI_IGUIObject::construct, nullptr | nullptr, nullptr, nullptr, nullptr | ||||
}; | }; | ||||
JSFunctionSpec JSI_IGUIObject::JSI_methods[] = | JSFunctionSpec JSI_IGUIObject::JSI_methods[] = | ||||
{ | { | ||||
JS_FN("toString", JSI_IGUIObject::toString, 0, 0), | JS_FN("toString", JSI_IGUIObject::toString, 0, 0), | ||||
JS_FN("focus", JSI_IGUIObject::focus, 0, 0), | JS_FN("focus", JSI_IGUIObject::focus, 0, 0), | ||||
JS_FN("blur", JSI_IGUIObject::blur, 0, 0), | JS_FN("blur", JSI_IGUIObject::blur, 0, 0), | ||||
JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), | JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), | ||||
Show All 13 Lines | bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) | ||||
JS::RootedValue idval(cx); | JS::RootedValue idval(cx); | ||||
if (!JS_IdToValue(cx, id, &idval)) | if (!JS_IdToValue(cx, id, &idval)) | ||||
return false; | return false; | ||||
std::string propName; | std::string propName; | ||||
if (!ScriptInterface::FromJSVal(cx, idval, propName)) | if (!ScriptInterface::FromJSVal(cx, idval, propName)) | ||||
return false; | return false; | ||||
// Skip some things which are known to be functions rather than properties. | // Skip registered functions and inherited properties | ||||
// ("constructor" *must* be here, else it'll try to GetSettingType before | |||||
// the private IGUIObject* has been set (and thus crash). The others are | |||||
// partly for efficiency, and also to allow correct reporting of attempts to | |||||
// access nonexistent properties.) | |||||
if (propName == "constructor" || | if (propName == "constructor" || | ||||
propName == "prototype" || | propName == "prototype" || | ||||
propName == "toString" || | propName == "toString" || | ||||
propName == "toJSON" || | propName == "toJSON" || | ||||
propName == "focus" || | propName == "focus" || | ||||
propName == "blur" || | propName == "blur" || | ||||
propName == "getTextSize" || | propName == "getTextSize" || | ||||
propName == "getComputedSize" | propName == "getComputedSize" | ||||
▲ Show 20 Lines • Show All 515 Lines • ▼ Show 20 Lines | #undef PROP | ||||
default: | default: | ||||
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); | JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); | ||||
break; | break; | ||||
} | } | ||||
return !JS_IsExceptionPending(cx); | return !JS_IsExceptionPending(cx); | ||||
} | } | ||||
bool JSI_IGUIObject::construct(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | |||||
if (args.length() == 0) | |||||
{ | |||||
JS_ReportError(cx, "GUIObject has no default constructor"); | |||||
return false; | |||||
} | |||||
JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIObject")); | |||||
// Store the IGUIObject in the JS object's 'private' area | |||||
IGUIObject* guiObject = (IGUIObject*)args[0].get().toPrivate(); | |||||
JS_SetPrivate(obj, guiObject); | |||||
args.rval().setObject(*obj); | |||||
return true; | |||||
} | |||||
void JSI_IGUIObject::init(ScriptInterface& scriptInterface) | void JSI_IGUIObject::init(ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, nullptr, JSI_methods, nullptr, nullptr); | scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr); | ||||
} | } | ||||
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | ||||
JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator