2021-03-30 23:14:36 +02:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2010-01-09 20:20:14 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
#include "scriptinterface/Object.h"
|
2017-01-06 12:14:03 +01:00
|
|
|
#include "scriptinterface/ScriptConversions.h"
|
2021-05-13 11:43:33 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
#include "graphics/Color.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "maths/Fixed.h"
|
2010-10-02 14:41:29 +02:00
|
|
|
#include "maths/FixedVector2D.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "maths/FixedVector3D.h"
|
2021-03-30 23:14:36 +02:00
|
|
|
#include "maths/Rect.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "ps/CLogger.h"
|
2017-04-17 03:42:11 +02:00
|
|
|
#include "simulation2/helpers/CinemaPath.h"
|
2011-02-10 17:06:28 +01:00
|
|
|
#include "simulation2/helpers/Grid.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "simulation2/system/IComponent.h"
|
|
|
|
#include "simulation2/system/ParamNode.h"
|
|
|
|
|
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 19:29:17 +01:00
|
|
|
#define FAIL(msg) STMT(LOGERROR(msg); return false)
|
|
|
|
#define FAIL_VOID(msg) STMT(ScriptException::Raise(rq, msg); return)
|
2011-03-23 09:12:04 +01:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<IComponent*>(const ScriptRequest& rq, JS::MutableHandleValue ret, IComponent* const& val)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
if (val == NULL)
|
2014-03-28 21:26:32 +01:00
|
|
|
{
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.setNull();
|
2014-03-28 21:26:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// If this is a scripted component, just return the JS object directly
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue instance(rq.cx, val->GetJSInstance());
|
2014-03-28 21:26:32 +01:00
|
|
|
if (!instance.isNull())
|
|
|
|
{
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.set(instance);
|
2014-03-28 21:26:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// Otherwise we need to construct a wrapper object
|
|
|
|
// (TODO: cache wrapper objects?)
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx);
|
2021-05-15 15:54:58 +02:00
|
|
|
if (!val->NewJSObject(rq.GetScriptInterface(), &obj))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
// Report as an error, since scripts really shouldn't try to use unscriptable interfaces
|
2015-01-22 21:31:30 +01:00
|
|
|
LOGERROR("IComponent does not have a scriptable interface");
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.setUndefined();
|
2014-03-28 21:26:32 +01:00
|
|
|
return;
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 21:26:32 +01:00
|
|
|
JS_SetPrivate(obj, static_cast<void*>(val));
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.setObject(*obj);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<CParamNode>(const ScriptRequest& rq, JS::MutableHandleValue ret, CParamNode const& val)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
val.ToJSVal(rq, true, ret);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// Prevent modifications to the object, so that it's safe to share between
|
|
|
|
// components and to reconstruct on deserialization
|
2014-03-28 21:26:32 +01:00
|
|
|
if (ret.isObject())
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::FreezeObject(rq, ret, true);
|
2010-05-07 02:24:22 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<const CParamNode*>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CParamNode* const& val)
|
2010-01-26 00:43:58 +01:00
|
|
|
{
|
|
|
|
if (val)
|
2020-11-13 14:18:22 +01:00
|
|
|
ToJSVal(rq, ret, *val);
|
2010-01-26 00:43:58 +01:00
|
|
|
else
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.setUndefined();
|
2010-01-26 00:43:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<CColor>(const ScriptRequest& rq, JS::HandleValue v, CColor& out)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2014-03-28 21:26:32 +01:00
|
|
|
if (!v.isObject())
|
2020-06-01 18:09:28 +02:00
|
|
|
FAIL("CColor has to be an object");
|
2011-03-23 09:12:04 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx, &v.toObject());
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue r(rq.cx);
|
|
|
|
JS::RootedValue g(rq.cx);
|
|
|
|
JS::RootedValue b(rq.cx);
|
|
|
|
JS::RootedValue a(rq.cx);
|
|
|
|
if (!JS_GetProperty(rq.cx, obj, "r", &r) || !FromJSVal(rq, r, out.r))
|
2011-03-23 09:12:04 +01:00
|
|
|
FAIL("Failed to get property CColor.r");
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "g", &g) || !FromJSVal(rq, g, out.g))
|
2011-03-23 09:12:04 +01:00
|
|
|
FAIL("Failed to get property CColor.g");
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "b", &b) || !FromJSVal(rq, b, out.b))
|
2011-03-23 09:12:04 +01:00
|
|
|
FAIL("Failed to get property CColor.b");
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "a", &a) || !FromJSVal(rq, a, out.a))
|
2011-03-23 09:12:04 +01:00
|
|
|
FAIL("Failed to get property CColor.a");
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<CColor>(const ScriptRequest& rq, JS::MutableHandleValue ret, CColor const& val)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-09-13 02:56:51 +02:00
|
|
|
ret,
|
|
|
|
"r", val.r,
|
|
|
|
"g", val.g,
|
|
|
|
"b", val.b,
|
|
|
|
"a", val.a);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<fixed>(const ScriptRequest& rq, JS::HandleValue v, fixed& out)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2014-03-28 21:26:32 +01:00
|
|
|
double ret;
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS::ToNumber(rq.cx, v, &ret))
|
2010-01-09 20:20:14 +01:00
|
|
|
return false;
|
2010-05-02 22:32:37 +02:00
|
|
|
out = fixed::FromDouble(ret);
|
2010-07-04 21:47:31 +02:00
|
|
|
// double can precisely represent the full range of fixed, so this is a non-lossy conversion
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<fixed>(const ScriptRequest& UNUSED(rq), JS::MutableHandleValue ret, const fixed& val)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2014-07-14 21:52:35 +02:00
|
|
|
ret.set(JS::NumberValue(val.ToDouble()));
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<CFixedVector3D>(const ScriptRequest& rq, JS::HandleValue v, CFixedVector3D& out)
|
2010-03-07 22:38:39 +01:00
|
|
|
{
|
2014-03-28 21:26:32 +01:00
|
|
|
if (!v.isObject())
|
2010-03-07 22:38:39 +01:00
|
|
|
return false; // TODO: report type error
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx, &v.toObject());
|
|
|
|
JS::RootedValue p(rq.cx);
|
2010-03-07 22:38:39 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "x", &p)) return false; // TODO: report type errors
|
|
|
|
if (!FromJSVal(rq, p, out.X)) return false;
|
2010-03-07 22:38:39 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "y", &p)) return false;
|
|
|
|
if (!FromJSVal(rq, p, out.Y)) return false;
|
2010-03-07 22:38:39 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "z", &p)) return false;
|
|
|
|
if (!FromJSVal(rq, p, out.Z)) return false;
|
2010-03-07 22:38:39 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<CFixedVector3D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CFixedVector3D& val)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2020-11-14 09:46:32 +01:00
|
|
|
JS::RootedObject global(rq.cx, rq.glob);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue valueVector3D(rq.cx);
|
2020-12-17 18:51:18 +01:00
|
|
|
if (!ScriptInterface::GetGlobalProperty(rq, "Vector3D", &valueVector3D))
|
2019-07-17 02:00:05 +02:00
|
|
|
FAIL_VOID("Failed to get Vector3D constructor");
|
2019-07-16 23:52:49 +02:00
|
|
|
|
2020-12-06 15:03:02 +01:00
|
|
|
JS::RootedValueArray<3> args(rq.cx);
|
2019-07-16 23:52:49 +02:00
|
|
|
args[0].setNumber(val.X.ToDouble());
|
|
|
|
args[1].setNumber(val.Y.ToDouble());
|
|
|
|
args[2].setNumber(val.Z.ToDouble());
|
|
|
|
|
2020-11-18 15:39:04 +01:00
|
|
|
JS::RootedObject objVec(rq.cx);
|
|
|
|
if (!JS::Construct(rq.cx, valueVector3D, args, &objVec))
|
2019-07-17 02:00:05 +02:00
|
|
|
FAIL_VOID("Failed to construct Vector3D object");
|
2020-11-18 15:39:04 +01:00
|
|
|
|
|
|
|
ret.setObject(*objVec);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
2010-10-02 14:41:29 +02:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::HandleValue v, CFixedVector2D& out)
|
2010-10-02 14:41:29 +02:00
|
|
|
{
|
2014-03-28 21:26:32 +01:00
|
|
|
if (!v.isObject())
|
2010-10-02 14:41:29 +02:00
|
|
|
return false; // TODO: report type error
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx, &v.toObject());
|
2010-10-02 14:41:29 +02:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue p(rq.cx);
|
2010-10-02 14:41:29 +02:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "x", &p)) return false; // TODO: report type errors
|
|
|
|
if (!FromJSVal(rq, p, out.X)) return false;
|
2010-10-02 14:41:29 +02:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!JS_GetProperty(rq.cx, obj, "y", &p)) return false;
|
|
|
|
if (!FromJSVal(rq, p, out.Y)) return false;
|
2010-10-02 14:41:29 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-16 00:35:20 +01:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CFixedVector2D& val)
|
2011-01-16 00:35:20 +01:00
|
|
|
{
|
2020-11-14 09:46:32 +01:00
|
|
|
JS::RootedObject global(rq.cx, rq.glob);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue valueVector2D(rq.cx);
|
2020-12-17 18:51:18 +01:00
|
|
|
if (!ScriptInterface::GetGlobalProperty(rq, "Vector2D", &valueVector2D))
|
2019-07-17 02:00:05 +02:00
|
|
|
FAIL_VOID("Failed to get Vector2D constructor");
|
2011-02-10 17:06:28 +01:00
|
|
|
|
2020-12-06 15:03:02 +01:00
|
|
|
JS::RootedValueArray<2> args(rq.cx);
|
2019-07-16 23:52:49 +02:00
|
|
|
args[0].setNumber(val.X.ToDouble());
|
|
|
|
args[1].setNumber(val.Y.ToDouble());
|
2011-02-10 17:06:28 +01:00
|
|
|
|
2020-11-18 15:39:04 +01:00
|
|
|
JS::RootedObject objVec(rq.cx);
|
|
|
|
if (!JS::Construct(rq.cx, valueVector2D, args, &objVec))
|
2019-07-17 02:00:05 +02:00
|
|
|
FAIL_VOID("Failed to construct Vector2D object");
|
2020-11-18 15:39:04 +01:00
|
|
|
|
|
|
|
ret.setObject(*objVec);
|
2011-02-10 17:06:28 +01:00
|
|
|
}
|
2011-10-16 04:55:58 +02:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<Grid<u8> >(const ScriptRequest& rq, JS::MutableHandleValue ret, const Grid<u8>& val)
|
2011-10-16 04:55:58 +02:00
|
|
|
{
|
2014-03-28 21:26:32 +01:00
|
|
|
u32 length = (u32)(val.m_W * val.m_H);
|
|
|
|
u32 nbytes = (u32)(length * sizeof(u8));
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject objArr(rq.cx, JS_NewUint8Array(rq.cx, length));
|
2016-09-02 18:33:10 +02:00
|
|
|
// Copy the array data and then remove the no-GC check to allow further changes to the JS data
|
|
|
|
{
|
|
|
|
JS::AutoCheckCannotGC nogc;
|
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-08 00:37:43 +02:00
|
|
|
bool sharedMemory;
|
|
|
|
memcpy((void*)JS_GetUint8ArrayData(objArr, &sharedMemory, nogc), val.m_Data, nbytes);
|
2016-09-02 18:33:10 +02:00
|
|
|
}
|
2014-03-28 21:26:32 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue data(rq.cx, JS::ObjectValue(*objArr));
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-09-13 02:56:51 +02:00
|
|
|
ret,
|
|
|
|
"width", val.m_W,
|
|
|
|
"height", val.m_H,
|
|
|
|
"data", data);
|
2011-10-16 04:55:58 +02:00
|
|
|
}
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> void Script::ToJSVal<Grid<u16> >(const ScriptRequest& rq, JS::MutableHandleValue ret, const Grid<u16>& val)
|
2014-03-28 21:26:32 +01:00
|
|
|
{
|
|
|
|
u32 length = (u32)(val.m_W * val.m_H);
|
|
|
|
u32 nbytes = (u32)(length * sizeof(u16));
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject objArr(rq.cx, JS_NewUint16Array(rq.cx, length));
|
2016-09-02 18:33:10 +02:00
|
|
|
// Copy the array data and then remove the no-GC check to allow further changes to the JS data
|
|
|
|
{
|
|
|
|
JS::AutoCheckCannotGC nogc;
|
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-08 00:37:43 +02:00
|
|
|
bool sharedMemory;
|
|
|
|
memcpy((void*)JS_GetUint16ArrayData(objArr, &sharedMemory, nogc), val.m_Data, nbytes);
|
2016-09-02 18:33:10 +02:00
|
|
|
}
|
2016-11-23 14:02:58 +01:00
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue data(rq.cx, JS::ObjectValue(*objArr));
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-09-13 02:56:51 +02:00
|
|
|
ret,
|
|
|
|
"width", val.m_W,
|
|
|
|
"height", val.m_H,
|
|
|
|
"data", data);
|
2012-01-30 07:21:11 +01:00
|
|
|
}
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<TNSpline>(const ScriptRequest& rq, JS::HandleValue v, TNSpline& out)
|
2017-04-17 03:42:11 +02:00
|
|
|
{
|
|
|
|
if (!v.isObject())
|
|
|
|
FAIL("Argument must be an object");
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx, &v.toObject());
|
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-08 00:37:43 +02:00
|
|
|
bool isArray;
|
2020-12-06 15:03:02 +01:00
|
|
|
if (!JS::IsArrayObject(rq.cx, obj, &isArray) || !isArray)
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Argument must be an array");
|
|
|
|
|
|
|
|
u32 numberOfNodes = 0;
|
2020-12-06 15:03:02 +01:00
|
|
|
if (!JS::GetArrayLength(rq.cx, obj, &numberOfNodes))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to get array length");
|
|
|
|
|
|
|
|
for (u32 i = 0; i < numberOfNodes; ++i)
|
|
|
|
{
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue node(rq.cx);
|
|
|
|
if (!JS_GetElement(rq.cx, obj, i, &node))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to read array element");
|
|
|
|
|
|
|
|
fixed deltaTime;
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, node, "deltaTime", deltaTime))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to read Spline.deltaTime property");
|
|
|
|
|
|
|
|
CFixedVector3D position;
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, node, "position", position))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to read Spline.position property");
|
|
|
|
|
|
|
|
out.AddNode(position, CFixedVector3D(), deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out.GetAllNodes().empty())
|
|
|
|
FAIL("Spline must contain at least one node");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:43:33 +02:00
|
|
|
template<> bool Script::FromJSVal<CCinemaPath>(const ScriptRequest& rq, JS::HandleValue v, CCinemaPath& out)
|
2017-04-17 03:42:11 +02:00
|
|
|
{
|
|
|
|
if (!v.isObject())
|
|
|
|
FAIL("Argument must be an object");
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedObject obj(rq.cx, &v.toObject());
|
2017-04-17 03:42:11 +02:00
|
|
|
|
|
|
|
CCinemaData pathData;
|
|
|
|
TNSpline positionSpline, targetSpline;
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "name", pathData.m_Name))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to get CCinemaPath.name property");
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "orientation", pathData.m_Orientation))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to get CCinemaPath.orientation property");
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "positionNodes", positionSpline))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to get CCinemaPath.positionNodes property");
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (pathData.m_Orientation == L"target" && !FromJSProperty(rq, v, "targetNodes", targetSpline))
|
2017-04-17 03:42:11 +02:00
|
|
|
FAIL("Failed to get CCinemaPath.targetNodes property");
|
|
|
|
|
|
|
|
// Other properties are not necessary to be defined
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "timescale", pathData.m_Timescale))
|
2017-04-17 03:42:11 +02:00
|
|
|
pathData.m_Timescale = fixed::FromInt(1);
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "mode", pathData.m_Mode))
|
2017-04-17 03:42:11 +02:00
|
|
|
pathData.m_Mode = L"ease_inout";
|
|
|
|
|
2020-11-13 14:18:22 +01:00
|
|
|
if (!FromJSProperty(rq, v, "style", pathData.m_Style))
|
2017-04-17 03:42:11 +02:00
|
|
|
pathData.m_Style = L"default";
|
|
|
|
|
|
|
|
out = CCinemaPath(pathData, positionSpline, targetSpline);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-06 12:14:03 +01:00
|
|
|
// define vectors
|
|
|
|
JSVAL_VECTOR(CFixedVector2D)
|
2019-07-29 13:56:11 +02:00
|
|
|
|
|
|
|
#undef FAIL
|
|
|
|
#undef FAIL_VOID
|