Index: source/gui/scripting/JSInterface_GUITypes.h =================================================================== --- source/gui/scripting/JSInterface_GUITypes.h +++ source/gui/scripting/JSInterface_GUITypes.h @@ -26,19 +26,13 @@ extern JSClass JSI_class; \ extern JSPropertySpec JSI_props[]; \ extern JSFunctionSpec JSI_methods[]; \ + void RegisterScriptClass(ScriptInterface& scriptInterface); \ bool construct(JSContext* cx, uint argc, JS::Value* vp); \ bool toString(JSContext* cx, uint argc, JS::Value* vp); \ } GUISTDTYPE(Size) GUISTDTYPE(Color) -GUISTDTYPE(Mouse) #undef GUISTDTYPE // avoid unnecessary pollution - -namespace JSI_GUITypes -{ - void init(ScriptInterface& scriptInterface); -} - #endif // INCLUDED_JSI_GUITYPES Index: source/gui/scripting/JSInterface_GUITypes.cpp =================================================================== --- source/gui/scripting/JSInterface_GUITypes.cpp +++ source/gui/scripting/JSInterface_GUITypes.cpp @@ -33,10 +33,20 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] = { - JS_FS("toString", JSI_GUISize::toString, 0, 0), + JS_FS("toString", JSI_GUISize::toString, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), JS_FS_END }; +JSPropertySpec JSI_GUISize::JSI_props[] = +{ + JS_PS_END +}; + +void JSI_GUISize::RegisterScriptClass(ScriptInterface& scriptInterface) +{ + scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, nullptr, JSI_GUISize::JSI_methods, nullptr, nullptr); +} + bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); @@ -130,7 +140,6 @@ /**** GUIColor ****/ - JSClass JSI_GUIColor::JSI_class = { "GUIColor", 0, nullptr, nullptr, @@ -141,10 +150,20 @@ JSFunctionSpec JSI_GUIColor::JSI_methods[] = { - JS_FS("toString", JSI_GUIColor::toString, 0, 0), + JS_FS("toString", JSI_GUIColor::toString, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), JS_FS_END }; +JSPropertySpec JSI_GUIColor::JSI_props[] = +{ + JS_PS_END +}; + +void JSI_GUIColor::RegisterScriptClass(ScriptInterface& scriptInterface) +{ + scriptInterface.DefineCustomObjectType(&JSI_GUIColor::JSI_class, JSI_GUIColor::construct, 1, nullptr, JSI_GUIColor::JSI_methods, nullptr, nullptr); +} + bool JSI_GUIColor::construct(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); @@ -196,72 +215,3 @@ rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); return true; } - -/**** GUIMouse ****/ - - -JSClass JSI_GUIMouse::JSI_class = { - "GUIMouse", 0, - nullptr, nullptr, - nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, JSI_GUIMouse::construct, nullptr -}; - -JSFunctionSpec JSI_GUIMouse::JSI_methods[] = -{ - JS_FS("toString", JSI_GUIMouse::toString, 0, 0), - JS_FS_END -}; - -bool JSI_GUIMouse::construct(JSContext* cx, uint argc, JS::Value* vp) -{ - JSAutoRequest rq(cx); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - - ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIMouse")); - - if (args.length() == 3) - { - JS_SetProperty(cx, obj, "x", args[0]); - JS_SetProperty(cx, obj, "y", args[1]); - JS_SetProperty(cx, obj, "buttons", args[2]); - } - else - { - JS::RootedValue zero (cx, JS::NumberValue(0)); - JS_SetProperty(cx, obj, "x", zero); - JS_SetProperty(cx, obj, "y", zero); - JS_SetProperty(cx, obj, "buttons", zero); - } - - args.rval().setObject(*obj); - return true; -} - -bool JSI_GUIMouse::toString(JSContext* cx, uint argc, JS::Value* vp) -{ - UNUSED2(argc); - JS::CallReceiver rec = JS::CallReceiverFromVp(vp); - - i32 x, y, buttons; - ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - pScriptInterface->GetProperty(rec.thisv(), "x", x); - pScriptInterface->GetProperty(rec.thisv(), "y", y); - pScriptInterface->GetProperty(rec.thisv(), "buttons", buttons); - - char buffer[256]; - snprintf(buffer, 256, "%d %d %d", x, y, buttons); - rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); - return true; -} - - -// Initialise all the types at once: -void JSI_GUITypes::init(ScriptInterface& scriptInterface) -{ - scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, nullptr, JSI_GUISize::JSI_methods, NULL, NULL); - scriptInterface.DefineCustomObjectType(&JSI_GUIColor::JSI_class, JSI_GUIColor::construct, 1, nullptr, JSI_GUIColor::JSI_methods, NULL, NULL); - scriptInterface.DefineCustomObjectType(&JSI_GUIMouse::JSI_class, JSI_GUIMouse::construct, 1, nullptr, JSI_GUIMouse::JSI_methods, NULL, NULL); -} Index: source/gui/scripting/JSInterface_IGUIObject.h =================================================================== --- source/gui/scripting/JSInterface_IGUIObject.h +++ source/gui/scripting/JSInterface_IGUIObject.h @@ -25,6 +25,7 @@ extern JSClass JSI_class; extern JSPropertySpec JSI_props[]; extern JSFunctionSpec JSI_methods[]; + void RegisterScriptClass(ScriptInterface& scriptInterface); bool getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); bool setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp); bool construct(JSContext* cx, uint argc, JS::Value* vp); @@ -32,7 +33,6 @@ bool focus(JSContext* cx, uint argc, JS::Value* vp); bool blur(JSContext* cx, uint argc, JS::Value* vp); bool getComputedSize(JSContext* cx, uint argc, JS::Value* vp); - void init(ScriptInterface& scriptInterface); } #endif // INCLUDED_JSI_IGUIOBJECT Index: source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- source/gui/scripting/JSInterface_IGUIObject.cpp +++ source/gui/scripting/JSInterface_IGUIObject.cpp @@ -18,48 +18,56 @@ #include "precompiled.h" #include "JSInterface_IGUIObject.h" -#include "JSInterface_GUITypes.h" -#include "gui/IGUIObject.h" #include "gui/CGUI.h" -#include "gui/IGUIScrollBar.h" -#include "gui/CList.h" -#include "gui/GUIManager.h" - +#include "gui/CGUIList.h" +#include "gui/CGUISprite.h" +#include "gui/CGUISeries.h" +#include "gui/GUIutil.h" +#include "gui/IGUIObject.h" +#include "gui/scripting/JSInterface_GUITypes.h" #include "ps/CLogger.h" - +#include "ps/CStr.h" #include "scriptinterface/ScriptInterface.h" #include "scriptinterface/ScriptExtraHeaders.h" +#include +#include + JSClass JSI_IGUIObject::JSI_class = { "GUIObject", JSCLASS_HAS_PRIVATE, nullptr, nullptr, JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, JSI_IGUIObject::construct, nullptr + nullptr, nullptr, nullptr, nullptr }; JSPropertySpec JSI_IGUIObject::JSI_props[] = { - { 0 } + JS_PS_END }; JSFunctionSpec JSI_IGUIObject::JSI_methods[] = { - JS_FS("toString", JSI_IGUIObject::toString, 0, 0), - JS_FS("focus", JSI_IGUIObject::focus, 0, 0), - JS_FS("blur", JSI_IGUIObject::blur, 0, 0), - JS_FS("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), + JS_FS("toString", JSI_IGUIObject::toString, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), + JS_FS("focus", JSI_IGUIObject::focus, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), + JS_FS("blur", JSI_IGUIObject::blur, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), + JS_FS("getComputedSize", JSI_IGUIObject::getComputedSize, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT), JS_FS_END }; +void JSI_IGUIObject::RegisterScriptClass(ScriptInterface& scriptInterface) +{ + scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, JSI_props, JSI_methods, nullptr, nullptr); +} + bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { JSAutoRequest rq(cx); ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; JS::RootedValue idval(cx); @@ -75,8 +83,7 @@ // 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" || - propName == "prototype" || + if (propName == "prototype" || propName == "toString" || propName == "toJSON" || propName == "focus" || @@ -89,8 +96,8 @@ if (propName.substr(0, 2) == "on") { CStr eventName(CStr(propName.substr(2)).LowerCase()); - std::map>::iterator it = e->m_ScriptHandlers.find(eventName); - if (it == e->m_ScriptHandlers.end()) + std::map>::iterator it = guiObject->m_ScriptHandlers.find(eventName); + if (it == guiObject->m_ScriptHandlers.end()) vp.setNull(); else vp.setObject(*it->second.get()); @@ -99,7 +106,7 @@ if (propName == "parent") { - IGUIObject* parent = e->GetParent(); + IGUIObject* parent = guiObject->GetParent(); if (parent) vp.set(JS::ObjectValue(*parent->GetJSObject())); @@ -113,10 +120,10 @@ JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty())); vp.setObject(*obj); - for (size_t i = 0; i < e->m_Children.size(); ++i) + for (size_t i = 0; i < guiObject->m_Children.size(); ++i) { JS::RootedValue val(cx); - ScriptInterface::ToJSVal(cx, &val, e->m_Children[i]); + ScriptInterface::ToJSVal(cx, &val, guiObject->m_Children[i]); JS_SetElement(cx, obj, i, val); } @@ -124,14 +131,14 @@ } else if (propName == "name") { - vp.set(JS::StringValue(JS_NewStringCopyZ(cx, e->GetName().c_str()))); + vp.set(JS::StringValue(JS_NewStringCopyZ(cx, guiObject->GetName().c_str()))); return true; } else { // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; - if (e->GetSettingType(propName, Type) != PSRETURN_OK) + if (guiObject->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid GUIObject property '%s'", propName.c_str()); return false; @@ -143,7 +150,7 @@ case GUIST_bool: { bool value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); vp.set(JS::BooleanValue(value)); break; } @@ -151,7 +158,7 @@ case GUIST_int: { int value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); vp.set(JS::Int32Value(value)); break; } @@ -159,7 +166,7 @@ case GUIST_uint: { u32 value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); if (value >= std::numeric_limits::max()) LOGERROR("Integer overflow on converting to GUIST_uint"); else @@ -170,7 +177,7 @@ case GUIST_float: { float value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); // Create a garbage-collectable double vp.set(JS::NumberValue(value)); return !vp.isNull(); @@ -179,7 +186,7 @@ case GUIST_CColor: { CColor color; - GUI::GetSetting(e, propName, color); + GUI::GetSetting(guiObject, propName, color); JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor")); vp.setObject(*obj); JS::RootedValue c(cx); @@ -201,7 +208,7 @@ case GUIST_CClientArea: { CClientArea area; - GUI::GetSetting(e, propName, area); + GUI::GetSetting(guiObject, propName, area); JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); vp.setObject(*obj); @@ -230,7 +237,7 @@ case GUIST_CGUIString: { CGUIString value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString()); break; } @@ -238,7 +245,7 @@ case GUIST_CStr: { CStr value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value); break; } @@ -246,7 +253,7 @@ case GUIST_CStrW: { CStrW value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value); break; } @@ -254,7 +261,7 @@ case GUIST_CGUISpriteInstance: { CGUISpriteInstance *value; - GUI::GetSettingPointer(e, propName, value); + GUI::GetSettingPointer(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value->GetName()); break; } @@ -262,7 +269,7 @@ case GUIST_EAlign: { EAlign value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); CStr word; switch (value) { @@ -278,7 +285,7 @@ case GUIST_EVAlign: { EVAlign value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); CStr word; switch (value) { @@ -294,7 +301,7 @@ case GUIST_CGUIList: { CGUIList value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value.m_Items); break; } @@ -302,7 +309,7 @@ case GUIST_CGUISeries: { CGUISeries value; - GUI::GetSetting(e, propName, value); + GUI::GetSetting(guiObject, propName, value); ScriptInterface::ToJSVal(cx, vp, value.m_Series); break; } @@ -319,8 +326,8 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp) { - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; JSAutoRequest rq(cx); @@ -337,7 +344,7 @@ std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - e->SetName(value); + guiObject->SetName(value); return true; } @@ -355,14 +362,14 @@ } CStr eventName(CStr(propName.substr(2)).LowerCase()); - e->SetScriptHandler(eventName, vpObj); + guiObject->SetScriptHandler(eventName, vpObj); return true; } // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; - if (e->GetSettingType(propName, Type) != PSRETURN_OK) + if (guiObject->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid setting '%s'", propName.c_str()); return true; @@ -376,7 +383,7 @@ if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - GUI::SetSetting(e, propName, value); + GUI::SetSetting(guiObject, propName, value); break; } @@ -386,7 +393,7 @@ if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - GUI::SetSetting(e, propName, value); + GUI::SetSetting(guiObject, propName, value); break; } @@ -396,7 +403,7 @@ if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - GUI::SetSetting(e, propName, CGUISpriteInstance(value)); + GUI::SetSetting(guiObject, propName, CGUISpriteInstance(value)); break; } @@ -408,7 +415,7 @@ CGUIString str; str.SetValue(value); - GUI::SetSetting(e, propName, str); + GUI::SetSetting(guiObject, propName, str); break; } @@ -427,7 +434,7 @@ JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); return false; } - GUI::SetSetting(e, propName, a); + GUI::SetSetting(guiObject, propName, a); break; } @@ -446,7 +453,7 @@ JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); return false; } - GUI::SetSetting(e, propName, a); + GUI::SetSetting(guiObject, propName, a); break; } @@ -454,7 +461,7 @@ { int value; if (ScriptInterface::FromJSVal(cx, vp, value)) - GUI::SetSetting(e, propName, value); + GUI::SetSetting(guiObject, propName, value); else { JS_ReportError(cx, "Cannot convert value to int"); @@ -467,7 +474,7 @@ { u32 value; if (ScriptInterface::FromJSVal(cx, vp, value)) - GUI::SetSetting(e, propName, value); + GUI::SetSetting(guiObject, propName, value); else { JS_ReportError(cx, "Cannot convert value to u32"); @@ -480,7 +487,7 @@ { double value; if (JS::ToNumber(cx, vp, &value) == true) - GUI::SetSetting(e, propName, (float)value); + GUI::SetSetting(guiObject, propName, (float)value); else { JS_ReportError(cx, "Cannot convert value to float"); @@ -492,7 +499,7 @@ case GUIST_bool: { bool value = JS::ToBoolean(vp); - GUI::SetSetting(e, propName, value); + GUI::SetSetting(guiObject, propName, value); break; } @@ -504,16 +511,16 @@ if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - if (e->SetSetting(propName, value) != PSRETURN_OK) + if (guiObject->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return false; } } - else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL)) + else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, nullptr)) { CClientArea area; - GUI::GetSetting(e, propName, area); + GUI::GetSetting(guiObject, propName, area); ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; #define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y) @@ -527,7 +534,7 @@ P(percent, bottom, rbottom); #undef P - GUI::SetSetting(e, propName, area); + GUI::SetSetting(guiObject, propName, area); } else { @@ -545,13 +552,13 @@ if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - if (e->SetSetting(propName, value) != PSRETURN_OK) + if (guiObject->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return false; } } - else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL)) + else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, nullptr)) { CColor color; JS::RootedValue t(cx); @@ -566,7 +573,7 @@ PROP(b); PROP(a); #undef PROP - GUI::SetSetting(e, propName, color); + GUI::SetSetting(guiObject, propName, color); } else { @@ -580,7 +587,7 @@ { CGUIList list; if (ScriptInterface::FromJSVal(cx, vp, list.m_Items)) - GUI::SetSetting(e, propName, list); + GUI::SetSetting(guiObject, propName, list); else { JS_ReportError(cx, "Failed to get list '%s'", propName.c_str()); @@ -593,7 +600,7 @@ { CGUISeries series; if (ScriptInterface::FromJSVal(cx, vp, series.m_Series)) - GUI::SetSetting(e, propName, series); + GUI::SetSetting(guiObject, propName, series); else { JS_ReportError(cx, "Invalid value for chart series '%s'", propName.c_str()); @@ -610,99 +617,63 @@ return !JS_IsExceptionPending(cx); } - -bool JSI_IGUIObject::construct(JSContext* cx, uint argc, JS::Value* vp) +bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; + JS::RootedObject thisObj(cx, &JS::CallArgsFromVp(argc, vp).thisv().toObject()); - 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) -{ - scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL); -} - -bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) -{ - JSAutoRequest rq(cx); - JS::CallReceiver rec = JS::CallReceiverFromVp(vp); - - JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); - - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; char buffer[256]; - snprintf(buffer, 256, "[GUIObject: %s]", e->GetName().c_str()); + snprintf(buffer, 256, "[GUIObject: %s]", guiObject->GetName().c_str()); buffer[255] = 0; - rec.rval().setString(JS_NewStringCopyZ(cx, buffer)); + JS::CallReceiverFromVp(vp).rval().setString(JS_NewStringCopyZ(cx, buffer)); return true; } -bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), JS::Value* vp) +bool JSI_IGUIObject::focus(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); - JS::CallReceiver rec = JS::CallReceiverFromVp(vp); + JS::RootedObject thisObj(cx, &JS::CallArgsFromVp(argc, vp).thisv().toObject()); - JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); - - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; - e->GetGUI()->SetFocusedObject(e); + guiObject->GetGUI()->SetFocusedObject(guiObject); - rec.rval().setUndefined(); + JS::CallReceiverFromVp(vp).rval().setUndefined(); return true; } -bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), JS::Value* vp) +bool JSI_IGUIObject::blur(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); - JS::CallReceiver rec = JS::CallReceiverFromVp(vp); - - JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); + JS::RootedObject thisObj(cx, &JS::CallArgsFromVp(argc, vp).thisv().toObject()); - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; - e->GetGUI()->SetFocusedObject(NULL); + guiObject->GetGUI()->SetFocusedObject(nullptr); - rec.rval().setUndefined(); + JS::CallReceiverFromVp(vp).rval().setUndefined(); return true; } -bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp) +bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); - JS::CallReceiver rec = JS::CallReceiverFromVp(vp); - - JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); + JS::RootedObject thisObj(cx, &JS::CallArgsFromVp(argc, vp).thisv().toObject()); - IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); - if (!e) + IGUIObject* guiObject = static_cast(JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, nullptr)); + if (!guiObject) return false; - e->UpdateCachedSize(); - CRect size = e->m_CachedActualSize; + guiObject->UpdateCachedSize(); + CRect size = guiObject->m_CachedActualSize; JS::RootedValue objVal(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); try @@ -719,6 +690,6 @@ return false; } - rec.rval().set(objVal); + JS::CallReceiverFromVp(vp).rval().set(objVal); return true; } Index: source/gui/scripting/ScriptFunctions.cpp =================================================================== --- source/gui/scripting/ScriptFunctions.cpp +++ source/gui/scripting/ScriptFunctions.cpp @@ -49,8 +49,9 @@ */ void GuiScriptingInit(ScriptInterface& scriptInterface) { - JSI_IGUIObject::init(scriptInterface); - JSI_GUITypes::init(scriptInterface); + JSI_IGUIObject::RegisterScriptClass(scriptInterface); + JSI_GUIColor::RegisterScriptClass(scriptInterface); + JSI_GUISize::RegisterScriptClass(scriptInterface); JSI_ConfigDB::RegisterScriptFunctions(scriptInterface); JSI_Console::RegisterScriptFunctions(scriptInterface); Index: source/scriptinterface/ScriptInterface.h =================================================================== --- source/scriptinterface/ScriptInterface.h +++ source/scriptinterface/ScriptInterface.h @@ -264,7 +264,7 @@ * Complex values (functions, XML, etc) won't be cloned correctly, but basic * types and cyclic references should be fine. */ - JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const; + JS::Value CloneValueFromOtherContext(const ScriptInterface& otherScriptInterface, JS::HandleValue val) const; /** * Convert a JS::Value to a C++ type. (This might trigger GC.) Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -1103,12 +1103,12 @@ return JS_GetPrivate(obj); } -JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const +JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherScriptInterface, JS::HandleValue val) const { PROFILE("CloneValueFromOtherContext"); JSAutoRequest rq(m->m_cx); JS::RootedValue out(m->m_cx); - shared_ptr structuredClone = otherContext.WriteStructuredClone(val); + shared_ptr structuredClone = otherScriptInterface.WriteStructuredClone(val); ReadStructuredClone(structuredClone, &out); return out.get(); }