template<> void ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector3D& val) { JSAutoRequest rq(cx); // apply the Vector3D prototype to the return value; ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx); JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR3DPROTO).toObject()); JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, proto, JS::NullPtr())); if (!obj) { ret.setUndefined(); return; } JS::RootedValue x(cx); JS::RootedValue y(cx); JS::RootedValue z(cx); ToJSVal(cx, &x, val.X); ToJSVal(cx, &y, val.Y); ToJSVal(cx, &z, val.Z); JS_SetProperty(cx, obj, "x", x); JS_SetProperty(cx, obj, "y", y); JS_SetProperty(cx, obj, "z", z); ret.setObject(*obj); }
template<> void ScriptInterface::ToJSVal<CColor>(JSContext* cx, JS::MutableHandleValue ret, CColor const& val) { JSAutoRequest rq(cx); JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr())); if (!obj) { ret.setUndefined(); return; } JS::RootedValue r(cx); JS::RootedValue g(cx); JS::RootedValue b(cx); JS::RootedValue a(cx); ToJSVal(cx, &r, val.r); ToJSVal(cx, &g, val.g); ToJSVal(cx, &b, val.b); ToJSVal(cx, &a, val.a); JS_SetProperty(cx, obj, "r", r); JS_SetProperty(cx, obj, "g", g); JS_SetProperty(cx, obj, "b", b); JS_SetProperty(cx, obj, "a", a); ret.setObject(*obj); }
template<> void ScriptInterface::ToJSVal<const CParamNode*>(JSContext* cx, JS::MutableHandleValue ret, const CParamNode* const& val) { if (val) ToJSVal(cx, ret, *val); else ret.setUndefined(); }
jsval CMessage::ToJSValCached(ScriptInterface& scriptInterface) const { if (m_Cached.uninitialised()) m_Cached = CScriptValRooted(scriptInterface.GetContext(), ToJSVal(scriptInterface)); return m_Cached.get(); }
JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const { if (!m_Cached) m_Cached.reset(new JS::PersistentRootedValue(scriptInterface.GetJSRuntime(), ToJSVal(scriptInterface))); return m_Cached->get(); }
nsresult KeyPath::ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const { JS::Rooted<JS::Value> value(aCx); nsresult rv = ToJSVal(aCx, &value); if (NS_SUCCEEDED(rv)) { aValue = value; } return rv; }
void CancelLoad(const CStrW& message) { // Cancel loader LDR_Cancel(); // Call the cancelOnError GUI function, defined in ..gui/common/functions_utility_error.js // So all GUI pages that load games should include this script if (g_GUI && g_GUI->HasPages()) { JSContext* cx = g_ScriptingHost.getContext(); jsval fval, rval; JSBool ok = JS_GetProperty(cx, g_GUI->GetScriptObject(), "cancelOnError", &fval); ENSURE(ok); jsval msgval = ToJSVal(message); if (ok && !JSVAL_IS_VOID(fval)) JS_CallFunctionValue(cx, g_GUI->GetScriptObject(), fval, 1, &msgval, &rval); } }
template<> void ScriptInterface::ToJSVal<CStr8>(JSContext* cx, JS::MutableHandleValue ret, const CStr8& val) { ToJSVal(cx, ret, static_cast<const std::string&>(val)); }
template<> void ScriptInterface::ToJSVal<const wchar_t*>(JSContext* cx, JS::MutableHandleValue ret, const wchar_t* const& val) { ToJSVal(cx, ret, std::wstring(val)); }
template<> void ScriptInterface::ToJSVal<Path>(JSContext* cx, JS::MutableHandleValue ret, const Path& val) { ToJSVal(cx, ret, val.string()); }
template<> jsval ScriptInterface::ToJSVal<CStr8>(JSContext* cx, const CStr8& val) { return ToJSVal(cx, static_cast<const std::string&>(val)); }
template<> jsval ScriptInterface::ToJSVal<const wchar_t*>(JSContext* cx, const wchar_t* const& val) { return ToJSVal(cx, std::wstring(val)); }
template<> jsval ScriptInterface::ToJSVal<Path>(JSContext* cx, const Path& val) { return ToJSVal(cx, val.string()); }