2019-01-13 08:37:41 -08:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "JSInterface_IGUIObject.h"
|
|
|
|
|
|
2004-12-21 05:37:24 -08:00
|
|
|
#include "gui/CGUI.h"
|
2019-08-29 02:07:29 -07:00
|
|
|
#include "gui/CGUISetting.h"
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
2016-09-02 09:23:44 -07:00
|
|
|
#include "scriptinterface/ScriptExtraHeaders.h"
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2004-09-06 04:28:30 -07:00
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
JSClass JSI_IGUIObject::JSI_class = {
|
|
|
|
|
"GUIObject", JSCLASS_HAS_PRIVATE,
|
2016-09-02 09:26:54 -07:00
|
|
|
nullptr, nullptr,
|
2004-07-08 08:23:47 -07:00
|
|
|
JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty,
|
2016-09-02 09:26:54 -07:00
|
|
|
nullptr, nullptr, nullptr, nullptr,
|
2019-07-22 18:24:49 -07:00
|
|
|
nullptr, nullptr, nullptr, nullptr
|
2004-07-08 08:23:47 -07:00
|
|
|
};
|
|
|
|
|
|
2014-03-28 13:26:32 -07:00
|
|
|
JSFunctionSpec JSI_IGUIObject::JSI_methods[] =
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-01-13 08:37:41 -08:00
|
|
|
JS_FN("toString", JSI_IGUIObject::toString, 0, 0),
|
|
|
|
|
JS_FN("focus", JSI_IGUIObject::focus, 0, 0),
|
|
|
|
|
JS_FN("blur", JSI_IGUIObject::blur, 0, 0),
|
|
|
|
|
JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0),
|
2014-03-28 13:26:32 -07:00
|
|
|
JS_FS_END
|
2004-07-08 08:23:47 -07:00
|
|
|
};
|
|
|
|
|
|
2019-09-30 01:19:56 -07:00
|
|
|
void JSI_IGUIObject::RegisterScriptClass(ScriptInterface& scriptInterface)
|
|
|
|
|
{
|
|
|
|
|
scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 0, nullptr, JSI_methods, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2014-07-12 12:08:39 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2014-07-13 08:31:48 -07:00
|
|
|
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
|
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 12:08:39 -07:00
|
|
|
JS::RootedValue idval(cx);
|
2015-01-24 06:46:52 -08:00
|
|
|
if (!JS_IdToValue(cx, id, &idval))
|
|
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
|
|
|
|
if (!ScriptInterface::FromJSVal(cx, idval, propName))
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-07-22 18:24:49 -07:00
|
|
|
// Skip registered functions and inherited properties
|
2019-08-02 09:55:15 -07:00
|
|
|
// including JSInterfaces of derived classes
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "constructor" ||
|
|
|
|
|
propName == "prototype" ||
|
2010-08-11 14:04:09 -07:00
|
|
|
propName == "toString" ||
|
2013-03-07 05:49:49 -08:00
|
|
|
propName == "toJSON" ||
|
2010-08-13 06:50:03 -07:00
|
|
|
propName == "focus" ||
|
2011-08-20 10:17:53 -07:00
|
|
|
propName == "blur" ||
|
2019-03-18 15:15:40 -07:00
|
|
|
propName == "getTextSize" ||
|
2011-08-20 10:17:53 -07:00
|
|
|
propName == "getComputedSize"
|
2004-07-08 08:23:47 -07:00
|
|
|
)
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2005-03-29 14:04:38 -08:00
|
|
|
// Use onWhatever to access event handlers
|
2010-11-16 15:00:52 -08:00
|
|
|
if (propName.substr(0, 2) == "on")
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
2016-01-12 16:42:55 -08:00
|
|
|
std::map<CStr, JS::Heap<JSObject*>>::iterator it = e->m_ScriptHandlers.find(eventName);
|
2005-03-29 14:04:38 -08:00
|
|
|
if (it == e->m_ScriptHandlers.end())
|
2015-01-24 06:46:52 -08:00
|
|
|
vp.setNull();
|
2005-03-29 14:04:38 -08:00
|
|
|
else
|
2015-01-24 06:46:52 -08:00
|
|
|
vp.setObject(*it->second.get());
|
|
|
|
|
return true;
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "parent")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
|
|
|
|
IGUIObject* parent = e->GetParent();
|
2016-06-02 15:49:28 -07:00
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
if (parent)
|
2014-03-28 13:26:32 -07:00
|
|
|
vp.set(JS::ObjectValue(*parent->GetJSObject()));
|
2004-07-08 08:23:47 -07:00
|
|
|
else
|
2014-03-28 13:26:32 -07:00
|
|
|
vp.set(JS::NullValue());
|
2016-06-02 15:49:28 -07:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (propName == "children")
|
|
|
|
|
{
|
2019-09-12 17:56:51 -07:00
|
|
|
ScriptInterface::CreateArray(cx, vp);
|
2016-06-02 15:49:28 -07:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < e->m_Children.size(); ++i)
|
2019-07-22 12:35:14 -07:00
|
|
|
pScriptInterface->SetPropertyInt(vp, i, e->m_Children[i]);
|
2016-06-02 15:49:28 -07:00
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2004-12-15 13:24:46 -08:00
|
|
|
else if (propName == "name")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-07-22 12:35:14 -07:00
|
|
|
ScriptInterface::ToJSVal(cx, vp, e->GetName());
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2019-07-29 07:46:29 -07:00
|
|
|
else if (e->SettingExists(propName))
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-08-03 19:20:08 -07:00
|
|
|
e->m_Settings[propName]->ToJSVal(cx, vp);
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2019-07-29 07:46:29 -07:00
|
|
|
|
|
|
|
|
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str());
|
|
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-08-13 07:11:43 -07:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, obj, &JSI_IGUIObject::JSI_class);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_NOT_NONNULL_OBJECT);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2014-07-12 12:08:39 -07:00
|
|
|
JSAutoRequest rq(cx);
|
|
|
|
|
JS::RootedValue idval(cx);
|
2015-01-24 06:46:52 -08:00
|
|
|
if (!JS_IdToValue(cx, id, &idval))
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_NOT_NONNULL_OBJECT);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
|
|
|
|
if (!ScriptInterface::FromJSVal(cx, idval, propName))
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_UNDEFINED_PROP);
|
2010-11-16 15:00:52 -08:00
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
if (propName == "name")
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2010-11-16 15:00:52 -08:00
|
|
|
std::string value;
|
2014-03-28 13:26:32 -07:00
|
|
|
if (!ScriptInterface::FromJSVal(cx, vp, value))
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_UNDEFINED_PROP);
|
2010-11-16 15:00:52 -08:00
|
|
|
e->SetName(value);
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.succeed();
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2004-12-13 04:07:12 -08:00
|
|
|
|
2015-08-02 07:40:51 -07:00
|
|
|
JS::RootedObject vpObj(cx);
|
|
|
|
|
if (vp.isObject())
|
|
|
|
|
vpObj = &vp.toObject();
|
|
|
|
|
|
2005-03-29 14:04:38 -08:00
|
|
|
// Use onWhatever to set event handlers
|
2010-11-16 15:00:52 -08:00
|
|
|
if (propName.substr(0, 2) == "on")
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
2014-03-28 13:26:32 -07:00
|
|
|
if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject()))
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
|
|
|
|
JS_ReportError(cx, "on- event-handlers must be functions");
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_NOT_FUNCTION);
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
CStr eventName(CStr(propName.substr(2)).LowerCase());
|
2014-08-08 06:41:47 -07:00
|
|
|
e->SetScriptHandler(eventName, vpObj);
|
2005-03-29 15:34:58 -08:00
|
|
|
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.succeed();
|
2005-03-29 14:04:38 -08:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 07:46:29 -07:00
|
|
|
if (e->SettingExists(propName))
|
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
|
|
|
return e->m_Settings[propName]->FromJSVal(cx, vp, true) ? result.succeed() : result.fail(JSMSG_TYPE_ERR_BAD_ARGS);
|
2004-12-13 04:07:12 -08:00
|
|
|
|
2019-07-29 07:46:29 -07:00
|
|
|
JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str());
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
return result.fail(JSMSG_UNDEFINED_PROP);
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp)
|
2004-07-08 08:23:47 -07:00
|
|
|
{
|
2019-08-13 07:11:43 -07:00
|
|
|
// No JSAutoRequest needed for these calls
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
ScriptInterface::ToJSVal(cx, args.rval(), "[GUIObject: " + e->GetName() + "]");
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2004-07-08 08:23:47 -07:00
|
|
|
}
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
bool JSI_IGUIObject::focus(JSContext* cx, uint argc, JS::Value* vp)
|
2010-08-11 14:04:09 -07:00
|
|
|
{
|
2019-08-13 07:11:43 -07:00
|
|
|
// No JSAutoRequest needed for these calls
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2019-08-21 03:12:33 -07:00
|
|
|
e->GetGUI().SetFocusedObject(e);
|
2019-08-13 07:11:43 -07:00
|
|
|
args.rval().setUndefined();
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2010-08-13 06:50:03 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
bool JSI_IGUIObject::blur(JSContext* cx, uint argc, JS::Value* vp)
|
2010-08-13 06:50:03 -07:00
|
|
|
{
|
2019-08-13 07:11:43 -07:00
|
|
|
// No JSAutoRequest needed for these calls
|
|
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class);
|
2010-11-16 15:00:52 -08:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-08-13 06:50:03 -07:00
|
|
|
|
2019-08-21 03:12:33 -07:00
|
|
|
e->GetGUI().SetFocusedObject(nullptr);
|
2019-08-13 07:11:43 -07:00
|
|
|
args.rval().setUndefined();
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2010-08-11 14:04:09 -07:00
|
|
|
}
|
2011-08-20 10:17:53 -07:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp)
|
2011-08-20 10:17:53 -07:00
|
|
|
{
|
2014-07-26 15:33:16 -07:00
|
|
|
JSAutoRequest rq(cx);
|
2019-08-13 07:11:43 -07:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(cx, args, &JSI_IGUIObject::JSI_class);
|
2011-08-20 10:17:53 -07:00
|
|
|
if (!e)
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2011-08-20 10:17:53 -07:00
|
|
|
|
|
|
|
|
e->UpdateCachedSize();
|
2019-09-04 09:15:37 -07:00
|
|
|
ScriptInterface::ToJSVal(cx, args.rval(), e->m_CachedActualSize);
|
2011-08-20 10:17:53 -07:00
|
|
|
|
2015-01-24 06:46:52 -08:00
|
|
|
return true;
|
2011-08-20 10:17:53 -07:00
|
|
|
}
|