2020-01-15 08:00:37 -08:00
|
|
|
/* Copyright (C) 2020 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"
|
2020-06-14 13:51:21 -07:00
|
|
|
#include "ps/CLogger.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,
|
2019-10-28 04:35:04 -07:00
|
|
|
nullptr,
|
|
|
|
|
JSI_IGUIObject::deleteProperty,
|
|
|
|
|
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-13 08:31:48 -07:00
|
|
|
ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*pScriptInterface);
|
2014-07-13 08:31:48 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.cx, id, &idval))
|
2015-01-24 06:46:52 -08:00
|
|
|
return false;
|
2010-11-16 15:00:52 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!ScriptInterface::FromJSVal(rq, 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
|
|
|
{
|
2020-01-15 08:00:37 -08:00
|
|
|
CStr eventName(propName.substr(2));
|
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")
|
|
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ScriptInterface::CreateArray(rq, 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
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ScriptInterface::ToJSVal(rq, 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
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
e->m_Settings[propName]->ToJSVal(rq, 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
|
|
|
|
2020-06-14 03:34:49 -07:00
|
|
|
LOGERROR("Property '%s' does not exist!", propName.c_str());
|
2019-07-29 07:46:29 -07:00
|
|
|
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
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.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;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!ScriptInterface::FromJSVal(rq, 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;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!ScriptInterface::FromJSVal(rq, 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
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject vpObj(rq.cx);
|
2015-08-02 07:40:51 -07:00
|
|
|
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
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(rq.cx, &vp.toObject()))
|
2005-03-29 14:04:38 -08:00
|
|
|
{
|
2020-06-14 03:34:49 -07:00
|
|
|
LOGERROR("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
|
|
|
}
|
|
|
|
|
|
2020-01-15 08:00:37 -08:00
|
|
|
CStr eventName(propName.substr(2));
|
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))
|
2020-11-13 05:18:22 -08:00
|
|
|
return e->m_Settings[propName]->FromJSVal(rq, vp, true) ? result.succeed() : result.fail(JSMSG_TYPE_ERR_BAD_ARGS);
|
2004-12-13 04:07:12 -08:00
|
|
|
|
2020-06-14 03:34:49 -07:00
|
|
|
LOGERROR("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-10-28 04:35:04 -07:00
|
|
|
bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result)
|
|
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, obj, &JSI_IGUIObject::JSI_class);
|
2019-10-28 04:35:04 -07:00
|
|
|
if (!e)
|
|
|
|
|
return result.fail(JSMSG_NOT_NONNULL_OBJECT);
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.cx, id, &idval))
|
2019-10-28 04:35:04 -07:00
|
|
|
return result.fail(JSMSG_NOT_NONNULL_OBJECT);
|
|
|
|
|
|
|
|
|
|
std::string propName;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!ScriptInterface::FromJSVal(rq, idval, propName))
|
2019-10-28 04:35:04 -07:00
|
|
|
return result.fail(JSMSG_UNDEFINED_PROP);
|
|
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
if (propName.substr(0, 2) == "on")
|
|
|
|
|
{
|
2020-01-15 08:00:37 -08:00
|
|
|
CStr eventName(propName.substr(2));
|
2019-10-28 04:35:04 -07:00
|
|
|
e->UnsetScriptHandler(eventName);
|
|
|
|
|
return result.succeed();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-14 03:34:49 -07:00
|
|
|
LOGERROR("Only event handlers can be deleted from GUI objects!");
|
2019-10-28 04:35:04 -07:00
|
|
|
return result.fail(JSMSG_UNDEFINED_PROP);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2020-11-13 05:18:22 -08:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
|
|
|
|
|
ScriptInterface::ToJSVal(rq, 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
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2020-11-13 05:18:22 -08:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2020-11-13 05:18:22 -08:00
|
|
|
|
2019-08-13 07:11:43 -07:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
2020-11-13 05:18:22 -08:00
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
ScriptRequest rq(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface);
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
|
IGUIObject* e = ScriptInterface::GetPrivate<IGUIObject>(rq, 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();
|
2020-11-13 05:18:22 -08:00
|
|
|
ScriptInterface::ToJSVal(rq, 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
|
|
|
}
|