Exact stack rooting for simulation message type conversions.
Also replaces some deprecated API (jsval typedef and OBJECT_TO_JSVAL) in that part of the code. Refs #2415 This was SVN commit r15624.
This commit is contained in:
parent
8ce8e6ba9a
commit
83aa817f71
@ -33,8 +33,8 @@
|
|||||||
virtual int GetType() const { return MT_##name; } \
|
virtual int GetType() const { return MT_##name; } \
|
||||||
virtual const char* GetScriptHandlerName() const { return "On" #name; } \
|
virtual const char* GetScriptHandlerName() const { return "On" #name; } \
|
||||||
virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
|
virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
|
||||||
virtual jsval ToJSVal(ScriptInterface& scriptInterface) const; \
|
virtual JS::Value ToJSVal(ScriptInterface& scriptInterface) const; \
|
||||||
static CMessage* FromJSVal(ScriptInterface&, jsval val);
|
static CMessage* FromJSVal(ScriptInterface&, JS::HandleValue val);
|
||||||
|
|
||||||
class SceneCollector;
|
class SceneCollector;
|
||||||
class CFrustum;
|
class CFrustum;
|
||||||
|
@ -22,41 +22,38 @@
|
|||||||
#include "simulation2/MessageTypes.h"
|
#include "simulation2/MessageTypes.h"
|
||||||
|
|
||||||
#define TOJSVAL_SETUP() \
|
#define TOJSVAL_SETUP() \
|
||||||
JSObject* obj; \
|
JSContext* cx = scriptInterface.GetContext(); \
|
||||||
{\
|
JSAutoRequest rq(cx); \
|
||||||
JSAutoRequest rq(scriptInterface.GetContext()); \
|
JS::RootedObject obj(cx, JS_NewObject(cx, NULL, NULL, NULL)); \
|
||||||
obj = JS_NewObject(scriptInterface.GetContext(), NULL, NULL, NULL); \
|
|
||||||
if (!obj) \
|
if (!obj) \
|
||||||
return JSVAL_VOID; \
|
return JS::UndefinedValue();
|
||||||
}
|
|
||||||
|
|
||||||
#define SET_MSG_PROPERTY(name) \
|
#define SET_MSG_PROPERTY(name) \
|
||||||
do { \
|
do { \
|
||||||
JSAutoRequest rq(scriptInterface.GetContext()); \
|
|
||||||
JSContext* cx = scriptInterface.GetContext(); \
|
|
||||||
JS::RootedValue prop(cx);\
|
JS::RootedValue prop(cx);\
|
||||||
ScriptInterface::ToJSVal(cx, &prop, this->name); \
|
ScriptInterface::ToJSVal(cx, &prop, this->name); \
|
||||||
if (! JS_SetProperty(cx, obj, #name, prop.address())) \
|
if (! JS_SetProperty(cx, obj, #name, prop.address())) \
|
||||||
return JSVAL_VOID; \
|
return JS::UndefinedValue(); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define FROMJSVAL_SETUP() \
|
#define FROMJSVAL_SETUP() \
|
||||||
if ( JSVAL_IS_PRIMITIVE(val)) \
|
JSContext* cx = scriptInterface.GetContext(); \
|
||||||
|
JSAutoRequest rq(cx); \
|
||||||
|
if (val.isPrimitive()) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
JSObject* obj = JSVAL_TO_OBJECT(val); \
|
JS::RootedObject obj(cx, &val.toObject()); \
|
||||||
JS::RootedValue prop(scriptInterface.GetContext());
|
JS::RootedValue prop(cx);
|
||||||
|
|
||||||
#define GET_MSG_PROPERTY(type, name) \
|
#define GET_MSG_PROPERTY(type, name) \
|
||||||
type name; \
|
type name; \
|
||||||
{ \
|
{ \
|
||||||
JSAutoRequest rq(scriptInterface.GetContext()); \
|
if (! JS_GetProperty(cx, obj, #name, prop.address())) \
|
||||||
if (! JS_GetProperty(scriptInterface.GetContext(), obj, #name, prop.address())) \
|
|
||||||
return NULL; \
|
return NULL; \
|
||||||
if (! ScriptInterface::FromJSVal(scriptInterface.GetContext(), prop, name)) \
|
if (! ScriptInterface::FromJSVal(cx, prop, name)) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
|
JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
if (m_Cached.uninitialised())
|
if (m_Cached.uninitialised())
|
||||||
m_Cached = CScriptValRooted(scriptInterface.GetContext(), ToJSVal(scriptInterface));
|
m_Cached = CScriptValRooted(scriptInterface.GetContext(), ToJSVal(scriptInterface));
|
||||||
@ -66,13 +63,13 @@ jsval CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageTurnStart::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageTurnStart::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
return new CMessageTurnStart();
|
return new CMessageTurnStart();
|
||||||
}
|
}
|
||||||
@ -80,13 +77,13 @@ CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface),
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
#define MESSAGE_1(name, t0, a0) \
|
#define MESSAGE_1(name, t0, a0) \
|
||||||
jsval CMessage##name::ToJSVal(ScriptInterface& scriptInterface) const \
|
JS::Value CMessage##name::ToJSVal(ScriptInterface& scriptInterface) const \
|
||||||
{ \
|
{ \
|
||||||
TOJSVAL_SETUP(); \
|
TOJSVAL_SETUP(); \
|
||||||
SET_MSG_PROPERTY(a0); \
|
SET_MSG_PROPERTY(a0); \
|
||||||
return OBJECT_TO_JSVAL(obj); \
|
return JS::ObjectValue(*obj); \
|
||||||
} \
|
} \
|
||||||
CMessage* CMessage##name::FromJSVal(ScriptInterface& scriptInterface, jsval val) \
|
CMessage* CMessage##name::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) \
|
||||||
{ \
|
{ \
|
||||||
FROMJSVAL_SETUP(); \
|
FROMJSVAL_SETUP(); \
|
||||||
GET_MSG_PROPERTY(t0, a0); \
|
GET_MSG_PROPERTY(t0, a0); \
|
||||||
@ -100,16 +97,16 @@ MESSAGE_1(Update_Final, fixed, turnLength)
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(deltaSimTime);
|
SET_MSG_PROPERTY(deltaSimTime);
|
||||||
SET_MSG_PROPERTY(offset);
|
SET_MSG_PROPERTY(offset);
|
||||||
SET_MSG_PROPERTY(deltaRealTime);
|
SET_MSG_PROPERTY(deltaRealTime);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(float, deltaSimTime);
|
GET_MSG_PROPERTY(float, deltaSimTime);
|
||||||
@ -120,13 +117,13 @@ CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, jsval
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageRenderSubmit::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
JS::Value CMessageRenderSubmit::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageRenderSubmit::ToJSVal not implemented");
|
LOGWARNING(L"CMessageRenderSubmit::ToJSVal not implemented");
|
||||||
return JSVAL_VOID;
|
return JS::UndefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageRenderSubmit::FromJSVal not implemented");
|
LOGWARNING(L"CMessageRenderSubmit::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -134,13 +131,13 @@ CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterfac
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageProgressiveLoad::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
JS::Value CMessageProgressiveLoad::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageProgressiveLoad::ToJSVal not implemented");
|
LOGWARNING(L"CMessageProgressiveLoad::ToJSVal not implemented");
|
||||||
return JSVAL_VOID;
|
return JS::UndefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageProgressiveLoad::FromJSVal not implemented");
|
LOGWARNING(L"CMessageProgressiveLoad::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -148,13 +145,13 @@ CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInter
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageDeserialized::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
JS::Value CMessageDeserialized::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageDeserialized::ToJSVal not implemented");
|
LOGWARNING(L"CMessageDeserialized::ToJSVal not implemented");
|
||||||
return JSVAL_VOID;
|
return JS::UndefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageDeserialized::FromJSVal not implemented");
|
LOGWARNING(L"CMessageDeserialized::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -162,14 +159,14 @@ CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& UNUSED(scriptInterfac
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageCreate::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageCreate::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -178,14 +175,14 @@ CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageDestroy::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageDestroy::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -194,16 +191,16 @@ CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, jsval val
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
SET_MSG_PROPERTY(from);
|
SET_MSG_PROPERTY(from);
|
||||||
SET_MSG_PROPERTY(to);
|
SET_MSG_PROPERTY(to);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -214,7 +211,7 @@ CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface,
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
@ -222,10 +219,10 @@ jsval CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
|||||||
SET_MSG_PROPERTY(x);
|
SET_MSG_PROPERTY(x);
|
||||||
SET_MSG_PROPERTY(z);
|
SET_MSG_PROPERTY(z);
|
||||||
SET_MSG_PROPERTY(a);
|
SET_MSG_PROPERTY(a);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -238,13 +235,13 @@ CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, j
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageInterpolatedPositionChanged::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
JS::Value CMessageInterpolatedPositionChanged::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageInterpolatedPositionChanged::ToJSVal not implemented");
|
LOGWARNING(L"CMessageInterpolatedPositionChanged::ToJSVal not implemented");
|
||||||
return JSVAL_VOID;
|
return JS::UndefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageInterpolatedPositionChanged::FromJSVal not implemented");
|
LOGWARNING(L"CMessageInterpolatedPositionChanged::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -252,15 +249,15 @@ CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
SET_MSG_PROPERTY(newTerritory);
|
SET_MSG_PROPERTY(newTerritory);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -270,15 +267,15 @@ CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInt
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(starting);
|
SET_MSG_PROPERTY(starting);
|
||||||
SET_MSG_PROPERTY(error);
|
SET_MSG_PROPERTY(error);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(bool, starting);
|
GET_MSG_PROPERTY(bool, starting);
|
||||||
@ -288,7 +285,7 @@ CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, jsv
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(i0);
|
SET_MSG_PROPERTY(i0);
|
||||||
@ -298,7 +295,7 @@ jsval CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
|||||||
return OBJECT_TO_JSVAL(obj);
|
return OBJECT_TO_JSVAL(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(int32_t, i0);
|
GET_MSG_PROPERTY(int32_t, i0);
|
||||||
@ -310,17 +307,17 @@ CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, js
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(player);
|
SET_MSG_PROPERTY(player);
|
||||||
SET_MSG_PROPERTY(ent);
|
SET_MSG_PROPERTY(ent);
|
||||||
SET_MSG_PROPERTY(oldVisibility);
|
SET_MSG_PROPERTY(oldVisibility);
|
||||||
SET_MSG_PROPERTY(newVisibility);
|
SET_MSG_PROPERTY(newVisibility);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(player_id_t, player);
|
GET_MSG_PROPERTY(player_id_t, player);
|
||||||
@ -332,55 +329,55 @@ CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface,
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageWaterChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageWaterChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return OBJECT_TO_JSVAL(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageWaterChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageWaterChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
return new CMessageWaterChanged();
|
return new CMessageWaterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageObstructionMapShapeChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageObstructionMapShapeChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageObstructionMapShapeChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageObstructionMapShapeChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
return new CMessageObstructionMapShapeChanged();
|
return new CMessageObstructionMapShapeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageTerritoriesChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageTerritoriesChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
return new CMessageTerritoriesChanged();
|
return new CMessageTerritoriesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(tag);
|
SET_MSG_PROPERTY(tag);
|
||||||
SET_MSG_PROPERTY(added);
|
SET_MSG_PROPERTY(added);
|
||||||
SET_MSG_PROPERTY(removed);
|
SET_MSG_PROPERTY(removed);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessageRangeUpdate::FromJSVal not implemented");
|
LOGWARNING(L"CMessageRangeUpdate::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -388,13 +385,13 @@ CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessagePathResult::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
JS::Value CMessagePathResult::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessagePathResult::ToJSVal not implemented");
|
LOGWARNING(L"CMessagePathResult::ToJSVal not implemented");
|
||||||
return JSVAL_VOID;
|
return JS::UndefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
LOGWARNING(L"CMessagePathResult::FromJSVal not implemented");
|
LOGWARNING(L"CMessagePathResult::FromJSVal not implemented");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -402,16 +399,16 @@ CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface)
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entities);
|
SET_MSG_PROPERTY(entities);
|
||||||
SET_MSG_PROPERTY(component);
|
SET_MSG_PROPERTY(component);
|
||||||
SET_MSG_PROPERTY(valueNames);
|
SET_MSG_PROPERTY(valueNames);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(std::vector<entity_id_t>, entities);
|
GET_MSG_PROPERTY(std::vector<entity_id_t>, entities);
|
||||||
@ -422,16 +419,16 @@ CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface,
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(player);
|
SET_MSG_PROPERTY(player);
|
||||||
SET_MSG_PROPERTY(component);
|
SET_MSG_PROPERTY(component);
|
||||||
SET_MSG_PROPERTY(valueNames);
|
SET_MSG_PROPERTY(valueNames);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(player_id_t, player);
|
GET_MSG_PROPERTY(player_id_t, player);
|
||||||
@ -442,16 +439,16 @@ CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterfa
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
SET_MSG_PROPERTY(entity);
|
SET_MSG_PROPERTY(entity);
|
||||||
SET_MSG_PROPERTY(oldRange);
|
SET_MSG_PROPERTY(oldRange);
|
||||||
SET_MSG_PROPERTY(newRange);
|
SET_MSG_PROPERTY(newRange);
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface, jsval val)
|
CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
FROMJSVAL_SETUP();
|
FROMJSVAL_SETUP();
|
||||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||||
@ -462,20 +459,20 @@ CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
jsval CMessageMinimapPing::ToJSVal(ScriptInterface& scriptInterface) const
|
JS::Value CMessageMinimapPing::ToJSVal(ScriptInterface& scriptInterface) const
|
||||||
{
|
{
|
||||||
TOJSVAL_SETUP();
|
TOJSVAL_SETUP();
|
||||||
return OBJECT_TO_JSVAL(obj);
|
return JS::ObjectValue(*obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CMessageMinimapPing::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
|
CMessage* CMessageMinimapPing::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
|
||||||
{
|
{
|
||||||
return new CMessageMinimapPing();
|
return new CMessageMinimapPing();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, jsval val)
|
CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val)
|
||||||
{
|
{
|
||||||
switch (mtid)
|
switch (mtid)
|
||||||
{
|
{
|
||||||
|
@ -42,8 +42,8 @@ public:
|
|||||||
virtual const char* GetScriptGlobalHandlerName() const { return globalHandlerName.c_str(); }
|
virtual const char* GetScriptGlobalHandlerName() const { return globalHandlerName.c_str(); }
|
||||||
virtual jsval ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); }
|
virtual jsval ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); }
|
||||||
|
|
||||||
CMessageScripted(int mtid, const std::string& name, const CScriptValRooted& msg) :
|
CMessageScripted(ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) :
|
||||||
mtid(mtid), handlerName("On" + name), globalHandlerName("OnGlobal" + name), msg(msg)
|
mtid(mtid), handlerName("On" + name), globalHandlerName("OnGlobal" + name), msg(scriptInterface.GetContext(), msg)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,26 +416,30 @@ std::vector<IComponent*> CComponentManager::Script_GetComponentsWithInterface(Sc
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMessage* CComponentManager::ConstructMessage(int mtid, CScriptVal data)
|
CMessage* CComponentManager::ConstructMessage(int mtid, JS::HandleValue data)
|
||||||
{
|
{
|
||||||
if (mtid == MT__Invalid || mtid > (int)m_MessageTypeIdsByName.size()) // (IDs start at 1 so use '>' here)
|
if (mtid == MT__Invalid || mtid > (int)m_MessageTypeIdsByName.size()) // (IDs start at 1 so use '>' here)
|
||||||
LOGERROR(L"PostMessage with invalid message type ID '%d'", mtid);
|
LOGERROR(L"PostMessage with invalid message type ID '%d'", mtid);
|
||||||
|
|
||||||
if (mtid < MT__LastNative)
|
if (mtid < MT__LastNative)
|
||||||
{
|
{
|
||||||
return CMessageFromJSVal(mtid, m_ScriptInterface, data.get());
|
return CMessageFromJSVal(mtid, m_ScriptInterface, data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new CMessageScripted(mtid, m_MessageTypeNamesById[mtid],
|
return new CMessageScripted(m_ScriptInterface, mtid, m_MessageTypeNamesById[mtid], data);
|
||||||
CScriptValRooted(m_ScriptInterface.GetContext(), data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentManager::Script_PostMessage(ScriptInterface::CxPrivate* pCxPrivate, int ent, int mtid, CScriptVal data)
|
void CComponentManager::Script_PostMessage(ScriptInterface::CxPrivate* pCxPrivate, int ent, int mtid, CScriptVal data1)
|
||||||
{
|
{
|
||||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData);
|
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData);
|
||||||
|
|
||||||
|
JSContext* cx = componentManager->GetScriptInterface().GetContext();
|
||||||
|
JSAutoRequest rq(cx);
|
||||||
|
// TODO: With ESR31 we should be able to take JS::HandleValue directly
|
||||||
|
JS::RootedValue data(cx, data1.get());
|
||||||
|
|
||||||
CMessage* msg = componentManager->ConstructMessage(mtid, data);
|
CMessage* msg = componentManager->ConstructMessage(mtid, data);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return; // error
|
return; // error
|
||||||
@ -445,10 +449,15 @@ void CComponentManager::Script_PostMessage(ScriptInterface::CxPrivate* pCxPrivat
|
|||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComponentManager::Script_BroadcastMessage(ScriptInterface::CxPrivate* pCxPrivate, int mtid, CScriptVal data)
|
void CComponentManager::Script_BroadcastMessage(ScriptInterface::CxPrivate* pCxPrivate, int mtid, CScriptVal data1)
|
||||||
{
|
{
|
||||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData);
|
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData);
|
||||||
|
|
||||||
|
JSContext* cx = componentManager->GetScriptInterface().GetContext();
|
||||||
|
JSAutoRequest rq(cx);
|
||||||
|
// TODO: With ESR31 we should be able to take JS::HandleValue directly
|
||||||
|
JS::RootedValue data(cx, data1.get());
|
||||||
|
|
||||||
CMessage* msg = componentManager->ConstructMessage(mtid, data);
|
CMessage* msg = componentManager->ConstructMessage(mtid, data);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return; // error
|
return; // error
|
||||||
|
@ -291,7 +291,7 @@ private:
|
|||||||
// callback function to handle recursively finding files in a directory
|
// callback function to handle recursively finding files in a directory
|
||||||
static Status FindJSONFilesCallback(const VfsPath&, const CFileInfo&, const uintptr_t);
|
static Status FindJSONFilesCallback(const VfsPath&, const CFileInfo&, const uintptr_t);
|
||||||
|
|
||||||
CMessage* ConstructMessage(int mtid, CScriptVal data);
|
CMessage* ConstructMessage(int mtid, JS::HandleValue data);
|
||||||
void SendGlobalMessage(entity_id_t ent, const CMessage& msg);
|
void SendGlobalMessage(entity_id_t ent, const CMessage& msg);
|
||||||
|
|
||||||
void FlattenDynamicSubscriptions();
|
void FlattenDynamicSubscriptions();
|
||||||
|
@ -31,14 +31,14 @@ public:
|
|||||||
virtual int GetType() const = 0;
|
virtual int GetType() const = 0;
|
||||||
virtual const char* GetScriptHandlerName() const = 0;
|
virtual const char* GetScriptHandlerName() const = 0;
|
||||||
virtual const char* GetScriptGlobalHandlerName() const = 0;
|
virtual const char* GetScriptGlobalHandlerName() const = 0;
|
||||||
virtual jsval ToJSVal(ScriptInterface&) const = 0;
|
virtual JS::Value ToJSVal(ScriptInterface&) const = 0;
|
||||||
jsval ToJSValCached(ScriptInterface&) const;
|
JS::Value ToJSValCached(ScriptInterface&) const;
|
||||||
private:
|
private:
|
||||||
mutable CScriptValRooted m_Cached;
|
mutable CScriptValRooted m_Cached;
|
||||||
};
|
};
|
||||||
// TODO: GetType could be replaced with a plain member variable to avoid some
|
// TODO: GetType could be replaced with a plain member variable to avoid some
|
||||||
// virtual calls, if that turns out to be worthwhile
|
// virtual calls, if that turns out to be worthwhile
|
||||||
|
|
||||||
CMessage* CMessageFromJSVal(int mtid, ScriptInterface&, jsval);
|
CMessage* CMessageFromJSVal(int mtid, ScriptInterface&, JS::HandleValue);
|
||||||
|
|
||||||
#endif // INCLUDED_MESSAGE
|
#endif // INCLUDED_MESSAGE
|
||||||
|
Loading…
Reference in New Issue
Block a user