0ad/source/gui/Scripting/JSInterface_CText.cpp
wraitii d07f271d60 [SM60 2/2] Update to Spidermonkey 60 APIs
Two noteworthy changes:
- Proxies are update to the SM60 API, having an explicit reserved slot
and a private slot, in which the 'proxy data' and the C++ object are
stored. This fixes a debug assertion failure of SM52 (See bugs 1237504
and 1339411)
- The GC callback behaviour has changed slightly, and we should now only
look for GC_SLICE_BEGIN and GC_SLICE_END calls (Bug 1364547)

Other updates are minor:
- Bug 1339036: JSTYPE_VOID beomes JSTYPE_UNDEFINED
- Bug 1308236 - avoid ambiguous comparison by changing NULL to nullptr
- Bug 1421358, GC::reason::REFRESH_FRAME was removed. API is indicated
in jsapi.h so use that.
- Compartment behaviours update
- ClassOps changes (Bug 1389510 removed the getter/setter - 7c04ea0211 -
and bug 1370608 added one more before that so net minus one)
- Minor tests touchups again.

Tested by: SubitaNeo, Stan
Thanks to bellaz89 for the Shared Array fix

Closes #5859

Differential Revision: https://code.wildfiregames.com/D3116
This was SVN commit r24243.
2020-11-24 15:47:03 +00:00

80 lines
2.9 KiB
C++

/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "JSInterface_GUIProxy.h"
#include "gui/CGUI.h"
#include "gui/CGUISetting.h"
#include "gui/ObjectBases/IGUIObject.h"
#include "gui/ObjectTypes/CText.h"
#include "ps/CLogger.h"
#include "scriptinterface/ScriptExtraHeaders.h"
#include "scriptinterface/ScriptInterface.h"
#include <string>
// Include the definition of the generic templates.
#include "JSInterface_GUIProxy_impl.h"
namespace {
struct SData
{
JS::PersistentRootedObject m_ToString;
JS::PersistentRootedObject m_Focus;
JS::PersistentRootedObject m_Blur;
JS::PersistentRootedObject m_GetComputedSize;
JS::PersistentRootedObject m_GetTextSize;
};
}
template <>
bool JSI_GUIProxy<CText>::funcGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const
{
const SData& data = *static_cast<const SData*>(js::GetProxyReservedSlot(proxy, 0).toPrivate());
if (propName == "toString")
return vp.setObjectOrNull(data.m_ToString), true;
if (propName == "focus")
return vp.setObjectOrNull(data.m_Focus), true;
if (propName == "blur")
return vp.setObjectOrNull(data.m_Blur), true;
if (propName == "getComputedSize")
return vp.setObjectOrNull(data.m_GetComputedSize), true;
if (propName == "getTextSize")
return vp.setObjectOrNull(data.m_GetTextSize), true;
return false;
}
template <>
std::pair<const js::BaseProxyHandler*, void*> JSI_GUIProxy<CText>::CreateData(ScriptInterface& scriptInterface)
{
SData* data = new SData();
ScriptRequest rq(scriptInterface);
#define func(class, func) &apply_to<CText, class, &class::func>
data->m_ToString.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, toString), 0, 0, "toString")));
data->m_Focus.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, focus), 0, 0, "focus")));
data->m_Blur.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, blur), 0, 0, "blur")));
data->m_GetComputedSize.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(IGUIObject, getComputedSize), 0, 0, "getComputedSize")));
data->m_GetTextSize.init(rq.cx, JS_GetFunctionObject(JS_NewFunction(rq.cx, func(CText, getTextSize), 0, 0, "getTextSize")));
#undef func
return { &Singleton(), data };
}
template class JSI_GUIProxy<CText>;