1
0
forked from 0ad/0ad

Pass ScriptInterface as a const ref where possible.

Reviewed By: elexis
Differential Revision: https://code.wildfiregames.com/D739
This was SVN commit r20028.
This commit is contained in:
leper 2017-08-24 00:32:42 +00:00
parent 7970c3dc54
commit 9defd11440
72 changed files with 271 additions and 273 deletions

View File

@ -373,7 +373,7 @@ PSRETURN CMapSummaryReader::LoadMap(const VfsPath& pathname)
return PSRETURN_OK;
}
void CMapSummaryReader::GetMapSettings(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void CMapSummaryReader::GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -176,7 +176,7 @@ public:
* }
* @endcode
*/
void GetMapSettings(ScriptInterface& scriptInterface, JS::MutableHandleValue);
void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue);
private:
CStr m_ScriptSettings;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -57,7 +57,7 @@ IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
scriptInterface.RegisterFunction<bool, &JSI_GameView::Get##NAME##Enabled>("GameView_Get" #NAME "Enabled"); \
scriptInterface.RegisterFunction<void, bool, &JSI_GameView::Set##NAME##Enabled>("GameView_Set" #NAME "Enabled");
void JSI_GameView::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_GameView::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
REGISTER_BOOLEAN_SCRIPT_SETTING(Culling);
REGISTER_BOOLEAN_SCRIPT_SETTING(LockCullCamera);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -28,7 +28,7 @@
namespace JSI_GameView
{
void RegisterScriptFunctions(ScriptInterface& ScriptInterface);
void RegisterScriptFunctions(const ScriptInterface& ScriptInterface);
DECLARE_BOOLEAN_SCRIPT_SETTING(Culling);
DECLARE_BOOLEAN_SCRIPT_SETTING(LockCullCamera);

View File

@ -965,7 +965,7 @@ static TimerUnit js_timer_overhead;
static TimerClient js_timer_clients[MAX_JS_TIMERS];
static wchar_t js_timer_descriptions_buf[MAX_JS_TIMERS * 12]; // depends on MAX_JS_TIMERS and format string below
static void InitJsTimers(ScriptInterface& scriptInterface)
static void InitJsTimers(const ScriptInterface& scriptInterface)
{
wchar_t* pos = js_timer_descriptions_buf;
for(size_t i = 0; i < MAX_JS_TIMERS; i++)

View File

@ -157,7 +157,7 @@ void JSI_L10n::ReevaluateCurrentLocaleAndReload(ScriptInterface::CxPrivate* UNUS
}
void JSI_L10n::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_L10n::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<std::wstring, std::wstring, &Translate>("Translate");
scriptInterface.RegisterFunction<std::wstring, std::string, std::wstring, &TranslateWithContext>("TranslateWithContext");

View File

@ -42,7 +42,7 @@ namespace JSI_L10n
*
* @sa GuiScriptingInit()
*/
void RegisterScriptFunctions(ScriptInterface& ScriptInterface);
void RegisterScriptFunctions(const ScriptInterface& ScriptInterface);
/**
* Returns the translation of the specified string to the

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -129,7 +129,7 @@ std::vector<T> ts_make_vector(T* start, size_t size_bytes)
class ScriptInterface;
// Script-based testing setup (defined in test_setup.cpp). Defines TS_* functions.
void ScriptTestSetup(ScriptInterface&);
void ScriptTestSetup(const ScriptInterface&);
// Default game data directory
// (TODO: game-specific functions like this probably shouldn't be inside lib/, but it's useful

View File

@ -36,8 +36,8 @@ public:
virtual void recv() = 0;
virtual void SendIqGetBoardList() = 0;
virtual void SendIqGetProfile(const std::string& player) = 0;
virtual void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
virtual void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
virtual void SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
virtual void SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
virtual void SendIqUnregisterGame() = 0;
virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players) = 0;
virtual void SetNick(const std::string& nick) = 0;
@ -48,14 +48,14 @@ public:
virtual void GetPresence(const std::string& nickname, std::string& presence) = 0;
virtual void GetRole(const std::string& nickname, std::string& role) = 0;
virtual void GetSubject(std::string& subject) = 0;
virtual void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void ClearPresenceUpdates() = 0;
virtual int GetMucMessageCount() = 0;
virtual void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
virtual void SendMUCMessage(const std::string& message) = 0;
virtual void SendStunEndpointToHost(StunClient::StunEndpoint* stunEndpoint, const std::string& hostJID) = 0;

View File

@ -301,7 +301,7 @@ void XmppClient::SendIqGetProfile(const std::string& player)
*
* @param data A JS array of game statistics
*/
void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data)
void XmppClient::SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data)
{
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
@ -334,7 +334,7 @@ void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleVa
*
* @param data A JS array of game attributes
*/
void XmppClient::SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data)
void XmppClient::SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data)
{
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
@ -453,7 +453,7 @@ void XmppClient::handleOOB(const glooxwrapper::JID&, const glooxwrapper::OOB&)
*
* @return A JS array containing all known players and their presences
*/
void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void XmppClient::GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -478,7 +478,7 @@ void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableH
*
* @return A JS array containing all known games
*/
void XmppClient::GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -502,7 +502,7 @@ void XmppClient::GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHan
*
* @return A JS array containing all known leaderboard data
*/
void XmppClient::GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void XmppClient::GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -526,7 +526,7 @@ void XmppClient::GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHa
*
* @return A JS array containing the specific user's profile data
*/
void XmppClient::GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void XmppClient::GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -552,7 +552,7 @@ void XmppClient::GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHand
/**
* Send GUI message queue when queried.
*/
void XmppClient::GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void XmppClient::GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
if (m_GuiMessageQueue.empty())
{

View File

@ -64,8 +64,8 @@ public:
void recv();
void SendIqGetBoardList();
void SendIqGetProfile(const std::string& player);
void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data);
void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data);
void SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data);
void SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data);
void SendIqUnregisterGame();
void SendIqChangeStateGame(const std::string& nbp, const std::string& players);
void SetNick(const std::string& nick);
@ -77,16 +77,13 @@ public:
void GetRole(const std::string& nickname, std::string& role);
void GetSubject(std::string& subject);
void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void SendStunEndpointToHost(StunClient::StunEndpoint* stunEndpoint, const std::string& hostJID);
//Script
ScriptInterface& GetScriptInterface();
protected:
/* Xmpp handlers */
/* MUC handlers */
@ -146,7 +143,7 @@ public:
std::wstring message;
std::time_t time;
};
void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
void SendMUCMessage(const std::string& message);
void ClearPresenceUpdates();
int GetMucMessageCount();

View File

@ -27,7 +27,7 @@
#include "third_party/encryption/pkcs5_pbkdf2.h"
#include "third_party/encryption/sha.h"
void JSI_Lobby::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
// Lobby functions
scriptInterface.RegisterFunction<bool, &JSI_Lobby::HasXmppClient>("HasXmppClient");

View File

@ -24,7 +24,7 @@
namespace JSI_Lobby
{
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
bool HasXmppClient(ScriptInterface::CxPrivate* pCxPrivate);
bool IsRankedGame(ScriptInterface::CxPrivate* pCxPrivate);

View File

@ -93,7 +93,7 @@ CStr CNetMessage::ToString() const
CNetMessage* CNetMessageFactory::CreateMessage(const void* pData,
size_t dataSize,
ScriptInterface& scriptInterface)
const ScriptInterface& scriptInterface)
{
CNetMessage* pNewMessage = NULL;
CNetMessage header;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -103,7 +103,7 @@ public:
* @param scriptInterface Script instance to use when constructing scripted messages
* @return The new message created
*/
static CNetMessage* CreateMessage(const void* pData, size_t dataSize, ScriptInterface& scriptInterface);
static CNetMessage* CreateMessage(const void* pData, size_t dataSize, const ScriptInterface& scriptInterface);
};
/**
@ -113,8 +113,8 @@ public:
class CSimulationMessage : public CNetMessage
{
public:
CSimulationMessage(ScriptInterface& scriptInterface);
CSimulationMessage(ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data);
CSimulationMessage(const ScriptInterface& scriptInterface);
CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data);
/** The compiler can't create a copy constructor because of the PersistentRooted member,
* so we have to write it manually.
@ -132,7 +132,7 @@ public:
u32 m_Turn;
JS::PersistentRooted<JS::Value> m_Data;
private:
ScriptInterface* m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
};
/**
@ -142,8 +142,8 @@ class CGameSetupMessage : public CNetMessage
{
NONCOPYABLE(CGameSetupMessage);
public:
CGameSetupMessage(ScriptInterface& scriptInterface);
CGameSetupMessage(ScriptInterface& scriptInterface, JS::HandleValue data);
CGameSetupMessage(const ScriptInterface& scriptInterface);
CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data);
virtual u8* Serialize(u8* pBuffer) const;
virtual const u8* Deserialize(const u8* pStart, const u8* pEnd);
virtual size_t GetSerializedLength() const;
@ -151,7 +151,7 @@ public:
JS::PersistentRootedValue m_Data;
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
};
// This time, the classes are created

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -59,7 +59,7 @@ public:
class CBufferBinarySerializer : public CBinarySerializer<CBufferBinarySerializerImpl>
{
public:
CBufferBinarySerializer(ScriptInterface& scriptInterface, u8* buffer) :
CBufferBinarySerializer(const ScriptInterface& scriptInterface, u8* buffer) :
CBinarySerializer<CBufferBinarySerializerImpl>(scriptInterface, buffer)
{
}
@ -98,7 +98,7 @@ public:
class CLengthBinarySerializer : public CBinarySerializer<CLengthBinarySerializerImpl>
{
public:
CLengthBinarySerializer(ScriptInterface& scriptInterface) :
CLengthBinarySerializer(const ScriptInterface& scriptInterface) :
CBinarySerializer<CLengthBinarySerializerImpl>(scriptInterface)
{
}
@ -109,19 +109,19 @@ public:
}
};
CSimulationMessage::CSimulationMessage(ScriptInterface& scriptInterface) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(&scriptInterface), m_Data(scriptInterface.GetJSRuntime())
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime())
{
}
CSimulationMessage::CSimulationMessage(ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(&scriptInterface),
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface),
m_Client(client), m_Player(player), m_Turn(turn), m_Data(scriptInterface.GetJSRuntime(), data)
{
}
CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) :
m_Data(orig.m_ScriptInterface->GetJSRuntime()),
m_Data(orig.m_ScriptInterface.GetJSRuntime()),
m_Client(orig.m_Client),
m_Player(orig.m_Player),
m_ScriptInterface(orig.m_ScriptInterface),
@ -136,7 +136,7 @@ u8* CSimulationMessage::Serialize(u8* pBuffer) const
// TODO: ought to handle serialization exceptions
// TODO: ought to represent common commands more efficiently
u8* pos = CNetMessage::Serialize(pBuffer);
CBufferBinarySerializer serializer(*m_ScriptInterface, pos);
CBufferBinarySerializer serializer(m_ScriptInterface, pos);
serializer.NumberU32_Unbounded("client", m_Client);
serializer.NumberI32_Unbounded("player", m_Player);
serializer.NumberU32_Unbounded("turn", m_Turn);
@ -151,7 +151,7 @@ const u8* CSimulationMessage::Deserialize(const u8* pStart, const u8* pEnd)
// TODO: ought to represent common commands more efficiently
const u8* pos = CNetMessage::Deserialize(pStart, pEnd);
std::istringstream stream(std::string(pos, pEnd));
CStdDeserializer deserializer(*m_ScriptInterface, stream);
CStdDeserializer deserializer(m_ScriptInterface, stream);
deserializer.NumberU32_Unbounded("client", m_Client);
deserializer.NumberI32_Unbounded("player", m_Player);
deserializer.NumberU32_Unbounded("turn", m_Turn);
@ -163,7 +163,7 @@ size_t CSimulationMessage::GetSerializedLength() const
{
// TODO: serializing twice is stupidly inefficient - we should just
// do it once, store the result, and use it here and in Serialize
CLengthBinarySerializer serializer(*m_ScriptInterface);
CLengthBinarySerializer serializer(m_ScriptInterface);
serializer.NumberU32_Unbounded("client", m_Client);
serializer.NumberI32_Unbounded("player", m_Player);
serializer.NumberU32_Unbounded("turn", m_Turn);
@ -176,7 +176,7 @@ size_t CSimulationMessage::GetSerializedLength() const
CStr CSimulationMessage::ToString() const
{
std::string source = m_ScriptInterface->ToString(const_cast<JS::PersistentRootedValue*>(&m_Data));
std::string source = m_ScriptInterface.ToString(const_cast<JS::PersistentRootedValue*>(&m_Data));
std::stringstream stream;
stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }";
@ -184,12 +184,12 @@ CStr CSimulationMessage::ToString() const
}
CGameSetupMessage::CGameSetupMessage(ScriptInterface& scriptInterface) :
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime())
{
}
CGameSetupMessage::CGameSetupMessage(ScriptInterface& scriptInterface, JS::HandleValue data) :
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface),
m_Data(scriptInterface.GetJSRuntime(), data)
{

View File

@ -360,7 +360,7 @@ bool STUNRequestAndResponse(ENetHost* transactionHost)
ParseStunResponse(buffer);
}
JS::Value StunClient::FindStunEndpointHost(ScriptInterface& scriptInterface, int port)
JS::Value StunClient::FindStunEndpointHost(const ScriptInterface& scriptInterface, int port)
{
ENetAddress hostAddr{ENET_HOST_ANY, (u16)port};
ENetHost* transactionHost = enet_host_create(&hostAddr, 1, 1, 0, 0);

View File

@ -33,7 +33,7 @@ struct StunEndpoint {
void SendStunRequest(ENetHost* transactionHost, u32 targetIp, u16 targetPort);
JS::Value FindStunEndpointHost(ScriptInterface& scriptInterface, int port);
JS::Value FindStunEndpointHost(const ScriptInterface& scriptInterface, int port);
StunEndpoint* FindStunEndpointJoin(ENetHost* transactionHost);

View File

@ -67,10 +67,10 @@
#endif
static void ReportGLLimits(ScriptInterface& scriptInterface, JS::HandleValue settings);
static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings);
#if ARCH_X86_X64
void ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret)
void ConvertCaches(const ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -93,7 +93,7 @@ void ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache,
}
}
void ConvertTLBs(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void ConvertTLBs(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -351,7 +351,7 @@ void RunHardwareDetection()
scriptInterface.CallFunctionVoid(global, "RunHardwareDetection", settings);
}
static void ReportGLLimits(ScriptInterface& scriptInterface, JS::HandleValue settings)
static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings)
{
const char* errstr = "(error)";

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -484,9 +484,9 @@ namespace
struct DumpTable
{
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
JS::PersistentRooted<JS::Value> m_Root;
DumpTable(ScriptInterface& scriptInterface, JS::HandleValue root) :
DumpTable(const ScriptInterface& scriptInterface, JS::HandleValue root) :
m_ScriptInterface(scriptInterface), m_Root(scriptInterface.GetJSRuntime(), root)
{
}
@ -600,7 +600,7 @@ void CProfileViewer::SaveToFile()
m->outputStream.flush();
}
JS::Value CProfileViewer::SaveToJS(ScriptInterface& scriptInterface)
JS::Value CProfileViewer::SaveToJS(const ScriptInterface& scriptInterface)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -191,7 +191,7 @@ public:
* SaveToJS: Return a script value containing the current profiler data
* (for all profile tables).
*/
JS::Value SaveToJS(ScriptInterface& scriptInterface);
JS::Value SaveToJS(const ScriptInterface& scriptInterface);
/**
* ShowTable: Set the named profile table to be the displayed one. If it

View File

@ -41,7 +41,7 @@
#include <ctime>
#include <fstream>
CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) :
CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) :
m_ScriptInterface(scriptInterface), m_Stream(NULL)
{
}

View File

@ -73,7 +73,7 @@ class CReplayLogger : public IReplayLogger
{
NONCOPYABLE(CReplayLogger);
public:
CReplayLogger(ScriptInterface& scriptInterface);
CReplayLogger(const ScriptInterface& scriptInterface);
~CReplayLogger();
virtual void StartGame(JS::MutableHandleValue attribs);
@ -82,7 +82,7 @@ public:
virtual OsPath GetDirectory() const;
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
std::ostream* m_Stream;
OsPath m_Directory;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -154,7 +154,7 @@ public:
* for the metadata because it would be error prone with rooting and the stack-based rooting
* types and confusing (a chain of pointers pointing to other pointers).
*/
CGameLoader(ScriptInterface& scriptInterface, std::string* savedState) :
CGameLoader(const ScriptInterface& scriptInterface, std::string* savedState) :
m_ScriptInterface(scriptInterface),
m_Metadata(scriptInterface.GetJSRuntime()),
m_SavedState(savedState)
@ -192,12 +192,12 @@ public:
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
JS::PersistentRooted<JS::Value> m_Metadata;
std::string* m_SavedState;
};
Status SavedGames::Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState)
Status SavedGames::Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState)
{
// Determine the filename to load
const VfsPath basename(L"saves/" + name);
@ -221,7 +221,7 @@ Status SavedGames::Load(const std::wstring& name, ScriptInterface& scriptInterfa
return INFO::OK;
}
JS::Value SavedGames::GetSavedGames(ScriptInterface& scriptInterface)
JS::Value SavedGames::GetSavedGames(const ScriptInterface& scriptInterface)
{
TIMER(L"GetSavedGames");
JSContext* cx = scriptInterface.GetContext();
@ -294,7 +294,7 @@ bool SavedGames::DeleteSavedGame(const std::wstring& name)
return true;
}
JS::Value SavedGames::GetEngineInfo(ScriptInterface& scriptInterface)
JS::Value SavedGames::GetEngineInfo(const ScriptInterface& scriptInterface)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -70,7 +70,7 @@ Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& s
* loaded from simulation.dat inside the archive.
* @return INFO::OK if successfully loaded, else an error Status
*/
Status Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState);
Status Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState);
/**
* Get list of saved games for GUI script usage
@ -78,7 +78,7 @@ Status Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::Muta
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return array of objects containing saved game data
*/
JS::Value GetSavedGames(ScriptInterface& scriptInterface);
JS::Value GetSavedGames(const ScriptInterface& scriptInterface);
/**
* Permanently deletes the saved game archive with the given name
@ -94,7 +94,7 @@ bool DeleteSavedGame(const std::wstring& name);
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return list of objects containing saved game data
*/
JS::Value GetEngineInfo(ScriptInterface& scriptInterface);
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface);
}

View File

@ -64,7 +64,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory)
return g_Game->StartVisualReplay(replayFile);
}
bool VisualReplay::ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -89,7 +89,7 @@ bool VisualReplay::ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHa
return false;
}
void VisualReplay::StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays)
void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays)
{
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@ -104,7 +104,7 @@ void VisualReplay::StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleOb
LOGERROR("Could not store the replay cache");
}
JS::HandleObject VisualReplay::ReloadReplayCache(ScriptInterface& scriptInterface, bool compareFiles)
JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles)
{
TIMER(L"ReloadReplayCache");
JSContext* cx = scriptInterface.GetContext();
@ -217,7 +217,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(ScriptInterface& scriptInterfac
return replays;
}
JS::Value VisualReplay::GetReplays(ScriptInterface& scriptInterface, bool compareFiles)
JS::Value VisualReplay::GetReplays(const ScriptInterface& scriptInterface, bool compareFiles)
{
TIMER(L"GetReplays");
JSContext* cx = scriptInterface.GetContext();
@ -320,7 +320,7 @@ inline int getReplayDuration(std::istream* replayStream, const OsPath& fileName,
return -1;
}
JS::Value VisualReplay::LoadReplayData(ScriptInterface& scriptInterface, const OsPath& directory)
JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory)
{
// The directory argument must not be constant, otherwise concatenating will fail
const OsPath replayFile = GetDirectoryName() / directory / L"commands.txt";
@ -434,7 +434,7 @@ JS::Value VisualReplay::GetReplayAttributes(ScriptInterface::CxPrivate* pCxPriva
return attribs;
}
void VisualReplay::AddReplayToCache(ScriptInterface& scriptInterface, const CStrW& directoryName)
void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName)
{
TIMER(L"AddReplayToCache");
JSContext* cx = scriptInterface.GetContext();

View File

@ -48,7 +48,7 @@ bool StartVisualReplay(const OsPath& directory);
* @param cachedReplaysObject - the cached replays.
* @return true on succes
*/
bool ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
/**
* Stores the replay list in the replay cache file
@ -56,7 +56,7 @@ bool ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cac
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param replays - the replay list to store.
*/
void StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays);
void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays);
/**
* Load the replay cache and check if there are new/deleted replays. If so, update the cache.
@ -65,7 +65,7 @@ void StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays);
* @param compareFiles - compare the directory name and the FileSize of the replays and the cache.
* @return cache entries
*/
JS::HandleObject ReloadReplayCache(ScriptInterface& scriptInterface, bool compareFiles);
JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles);
/**
* Get a list of replays to display in the GUI.
@ -75,13 +75,13 @@ JS::HandleObject ReloadReplayCache(ScriptInterface& scriptInterface, bool compar
* but nearly ensures, that no changed replay is missed.
* @return array of objects containing replay data
*/
JS::Value GetReplays(ScriptInterface& scriptInterface, bool compareFiles);
JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles);
/**
* Parses a commands.txt file and extracts metadata.
* Works similarly to CGame::LoadReplayData().
*/
JS::Value LoadReplayData(ScriptInterface& scriptInterface, const OsPath& directory);
JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory);
/**
* Permanently deletes the visual replay (including the parent directory)
@ -114,7 +114,7 @@ void SaveReplayMetadata(ScriptInterface* scriptInterface);
/**
* Adds a replay to the replayCache.
*/
void AddReplayToCache(ScriptInterface& scriptInterface, const CStrW& directoryName);
void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName);
}
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -133,7 +133,7 @@ bool JSI_ConfigDB::SetFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const
return true;
}
void JSI_ConfigDB::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_ConfigDB::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::HasChanges>("ConfigDB_HasChanges");
scriptInterface.RegisterFunction<bool, std::wstring, bool, &JSI_ConfigDB::SetChanges>("ConfigDB_SetChanges");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -33,7 +33,7 @@ namespace JSI_ConfigDB
bool WriteValueToFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path);
bool Reload(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
bool SetFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
}
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -47,7 +47,7 @@ void JSI_Console::SetVisibleEnabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivat
g_Console->SetVisible(Enabled);
}
void JSI_Console::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_Console::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<bool, &JSI_Console::GetVisibleEnabled>("Console_GetVisibleEnabled");
scriptInterface.RegisterFunction<void, bool, &JSI_Console::SetVisibleEnabled>("Console_SetVisibleEnabled");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -26,7 +26,7 @@ namespace JSI_Console
bool GetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate);
void SetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate, bool Enabled);
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
}
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -123,7 +123,7 @@ void JSI_Mod::SetMods(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std:
g_modsLoaded = mods;
}
void JSI_Mod::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_Mod::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<JS::Value, &JSI_Mod::GetAvailableMods>("GetAvailableMods");
scriptInterface.RegisterFunction<void, &JSI_Mod::RestartEngine>("RestartEngine");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,7 +22,7 @@ class ScriptInterface;
namespace JSI_Mod
{
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
JS::Value GetAvailableMods(ScriptInterface::CxPrivate* pCxPrivate);
void RestartEngine(ScriptInterface::CxPrivate* pCxPrivate);
void SetMods(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStr>& mods);

View File

@ -63,7 +63,7 @@ CStrW JSI_VisualReplay::GetReplayDirectoryName(ScriptInterface::CxPrivate* UNUSE
return wstring_from_utf8(OsPath(VisualReplay::GetDirectoryName() / directoryName).string8());
}
void JSI_VisualReplay::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_VisualReplay::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<JS::Value, bool, &GetReplays>("GetReplays");
scriptInterface.RegisterFunction<bool, CStrW, &DeleteReplay>("DeleteReplay");

View File

@ -30,7 +30,7 @@ namespace JSI_VisualReplay
bool HasReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName);
JS::Value GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName);
void AddReplayToCache(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName);
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
CStrW GetReplayDirectoryName(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName);
}

View File

@ -71,7 +71,7 @@ void JSI_Renderer::RecreateShadowMap(ScriptInterface::CxPrivate* UNUSED(pCxPriva
scriptInterface.RegisterFunction<bool, &JSI_Renderer::Get##NAME##Enabled>("Renderer_Get" #NAME "Enabled"); \
scriptInterface.RegisterFunction<void, bool, &JSI_Renderer::Set##NAME##Enabled>("Renderer_Set" #NAME "Enabled");
void JSI_Renderer::RegisterScriptFunctions(ScriptInterface& scriptInterface)
void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<std::string, &JSI_Renderer::GetRenderPath>("Renderer_GetRenderPath");
scriptInterface.RegisterFunction<void, std::string, &JSI_Renderer::SetRenderPath>("Renderer_SetRenderPath");

View File

@ -47,7 +47,7 @@ namespace JSI_Renderer
DECLARE_BOOLEAN_SCRIPT_SETTING(Postproc);
DECLARE_BOOLEAN_SCRIPT_SETTING(DisplayFrustum);
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
}
#undef DECLARE_BOOLEAN_SCRIPT_SETTING

View File

@ -59,7 +59,8 @@ template <typename T> struct MaybeRef;
// Define RegisterFunction<TR, T0..., f>
#define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \
void RegisterFunction(const char* name) { \
void RegisterFunction(const char* name) const \
{ \
Register(name, call<R T0_TAIL(z,i), fptr>, nargs<T0(z,i)>()); \
}
BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)

View File

@ -56,7 +56,7 @@ struct ScriptInterface_impl
{
ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime);
~ScriptInterface_impl();
void Register(const char* name, JSNative fptr, uint nargs);
void Register(const char* name, JSNative fptr, uint nargs) const;
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted
// members have to be called before the runtime destructor.
@ -393,7 +393,7 @@ ScriptInterface_impl::~ScriptInterface_impl()
JS_DestroyContext(m_cx);
}
void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs)
void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs) const
{
JSAutoRequest rq(m_cx);
JS::RootedObject nativeScope(m_cx, m_nativeScope);
@ -489,7 +489,7 @@ bool ScriptInterface::ReplaceNondeterministicRNG(boost::rand48& rng)
return false;
}
void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs)
void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) const
{
m->Register(name, fptr, (uint)nargs);
}
@ -612,7 +612,7 @@ bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool r
return ok;
}
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate)
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const
{
JSAutoRequest rq(m->m_cx);
uint attrs = 0;
@ -630,7 +630,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::Ha
return true;
}
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate)
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const
{
JSAutoRequest rq(m->m_cx);
uint attrs = 0;
@ -649,7 +649,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS:
return true;
}
bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate)
bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const
{
JSAutoRequest rq(m->m_cx);
uint attrs = 0;
@ -1103,7 +1103,7 @@ void ScriptInterface::ForceGC()
JS_GC(this->GetJSRuntime());
}
JS::Value ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val)
JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const
{
PROFILE("CloneValueFromOtherContext");
JSAutoRequest rq(m->m_cx);
@ -1124,7 +1124,7 @@ ScriptInterface::StructuredClone::~StructuredClone()
JS_ClearStructuredClone(m_Data, m_Size, NULL, NULL);
}
shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClone(JS::HandleValue v)
shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClone(JS::HandleValue v) const
{
JSAutoRequest rq(m->m_cx);
u64* data = NULL;
@ -1141,7 +1141,7 @@ shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClo
return ret;
}
void ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr, JS::MutableHandleValue ret)
void ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr, JS::MutableHandleValue ret) const
{
JSAutoRequest rq(m->m_cx);
JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, ret, NULL, NULL);

View File

@ -151,21 +151,21 @@ public:
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true);
bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const;
/**
* Set the named property on the given object.
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true);
bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true) const;
/**
* Set the integer-named property on the given object.
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true);
bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true) const;
/**
* Get the named property on the given object.
@ -266,7 +266,7 @@ public:
* Complex values (functions, XML, etc) won't be cloned correctly, but basic
* types and cyclic references should be fine.
*/
JS::Value CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val);
JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const;
/**
* Convert a jsval to a C++ type. (This might trigger GC.)
@ -319,8 +319,8 @@ public:
size_t m_Size;
};
shared_ptr<StructuredClone> WriteStructuredClone(JS::HandleValue v);
void ReadStructuredClone(const shared_ptr<StructuredClone>& ptr, JS::MutableHandleValue ret);
shared_ptr<StructuredClone> WriteStructuredClone(JS::HandleValue v) const;
void ReadStructuredClone(const shared_ptr<StructuredClone>& ptr, JS::MutableHandleValue ret) const;
/**
* Converts |a| if needed and assigns it to |handle|.
@ -360,9 +360,9 @@ private:
bool Eval_(const char* code, JS::MutableHandleValue ret) const;
bool Eval_(const wchar_t* code, JS::MutableHandleValue ret) const;
bool SetGlobal_(const char* name, JS::HandleValue value, bool replace);
bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate);
bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate);
bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate);
bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate) const;
bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate) const;
bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) const;
bool GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const;
bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const;
static bool IsExceptionPending(JSContext* cx);
@ -394,7 +394,7 @@ private:
JSClass* m_Class;
JSNative m_Constructor;
};
void Register(const char* name, JSNative fptr, size_t nargs);
void Register(const char* name, JSNative fptr, size_t nargs) const;
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted
// members have to be called before the runtime destructor.
@ -409,7 +409,7 @@ public:
// This declares:
//
// template <R, T0..., TR (*fptr) (void* cbdata, T0...)>
// void RegisterFunction(const char* functionName);
// void RegisterFunction(const char* functionName) const;
//
// template <R, T0..., TR (*fptr) (void* cbdata, T0...)>
// static JSNative call;
@ -494,7 +494,7 @@ bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace)
}
template<typename T>
bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate)
bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) const
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@ -503,7 +503,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T
}
template<typename T>
bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate)
bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate) const
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@ -512,7 +512,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, cons
}
template<typename T>
bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate)
bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate) const
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());

View File

@ -188,7 +188,7 @@ public:
handle_templates_test(script, val, &out, nbrVal);
}
void handle_templates_test(ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal)
void handle_templates_test(const ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal)
{
int nbr = 0;

View File

@ -35,8 +35,8 @@
virtual int GetType() const { return MT_##name; } \
virtual const char* GetScriptHandlerName() const { return "On" #name; } \
virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
virtual JS::Value ToJSVal(ScriptInterface& scriptInterface) const; \
static CMessage* FromJSVal(ScriptInterface&, JS::HandleValue val);
virtual JS::Value ToJSVal(const ScriptInterface& scriptInterface) const; \
static CMessage* FromJSVal(const ScriptInterface&, JS::HandleValue val);
class SceneCollector;
class CFrustum;

View File

@ -161,7 +161,7 @@ public:
SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter,
SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter);
static std::vector<SimulationCommand> CloneCommandsFromOtherContext(ScriptInterface& oldScript, ScriptInterface& newScript,
static std::vector<SimulationCommand> CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript,
const std::vector<SimulationCommand>& commands)
{
JSContext* cxOld = oldScript.GetContext();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -38,7 +38,7 @@ struct GetAIsHelper
{
NONCOPYABLE(GetAIsHelper);
public:
GetAIsHelper(ScriptInterface& scriptInterface) :
GetAIsHelper(const ScriptInterface& scriptInterface) :
m_ScriptInterface(scriptInterface),
m_AIs(scriptInterface.GetJSRuntime())
{
@ -78,10 +78,10 @@ public:
}
JS::PersistentRootedObject m_AIs;
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
};
JS::Value ICmpAIManager::GetAIs(ScriptInterface& scriptInterface)
JS::Value ICmpAIManager::GetAIs(const ScriptInterface& scriptInterface)
{
GetAIsHelper helper(scriptInterface);
helper.Run();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -51,7 +51,7 @@ public:
* Returns a vector of {"id":"value-for-AddPlayer", "name":"Human readable name"}
* objects, based on all the available AI scripts.
*/
static JS::Value GetAIs(ScriptInterface& scriptInterface);
static JS::Value GetAIs(const ScriptInterface& scriptInterface);
DECLARE_INTERFACE_TYPE(AIManager)
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,7 +36,7 @@ public:
g_VFS.reset();
}
static void load_script(ScriptInterface& scriptInterface, const VfsPath& pathname)
static void load_script(const ScriptInterface& scriptInterface, const VfsPath& pathname)
{
CVFSFile file;
TS_ASSERT_EQUALS(file.Load(g_VFS, pathname), PSRETURN_OK);

View File

@ -505,7 +505,7 @@ But for now everything is put in there.)
Now you have to add C++/JS conversions into MessageTypeConversions.cpp, so scripts can send and receive messages:
@code
JS::Value CMessageExample::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageExample::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(x);
@ -513,7 +513,7 @@ JS::Value CMessageExample::ToJSVal(ScriptInterface& scriptInterface) const
return JS::ObjectValue(*obj);
}
CMessage* CMessageExample::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageExample::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(int, x);
@ -528,12 +528,12 @@ with a set of scalar fields.)
If you don't want to support scripts sending/receiving the message, you can implement stub functions instead:
@code
JS::Value CMessageExample::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
JS::Value CMessageExample::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const
{
return JS::UndefinedValue();
}
CMessage* CMessageExample::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageExample::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return NULL;
}

View File

@ -52,7 +52,7 @@
return NULL; \
}
JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
JS::Value CMessage::ToJSValCached(const ScriptInterface& scriptInterface) const
{
if (!m_Cached)
m_Cached.reset(new JS::PersistentRootedValue(scriptInterface.GetJSRuntime(), ToJSVal(scriptInterface)));
@ -62,13 +62,13 @@ JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const
////////////////////////////////
JS::Value CMessageTurnStart::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageTurnStart::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageTurnStart::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return new CMessageTurnStart();
}
@ -76,13 +76,13 @@ CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface),
////////////////////////////////
#define MESSAGE_1(name, t0, a0) \
JS::Value CMessage##name::ToJSVal(ScriptInterface& scriptInterface) const \
JS::Value CMessage##name::ToJSVal(const ScriptInterface& scriptInterface) const \
{ \
TOJSVAL_SETUP(); \
SET_MSG_PROPERTY(a0); \
return JS::ObjectValue(*obj); \
} \
CMessage* CMessage##name::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) \
CMessage* CMessage##name::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) \
{ \
FROMJSVAL_SETUP(); \
GET_MSG_PROPERTY(t0, a0); \
@ -96,7 +96,7 @@ MESSAGE_1(Update_Final, fixed, turnLength)
////////////////////////////////
JS::Value CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageInterpolate::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(deltaSimTime);
@ -105,7 +105,7 @@ JS::Value CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const
return JS::ObjectValue(*obj);
}
CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageInterpolate::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(float, deltaSimTime);
@ -116,13 +116,13 @@ CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, JS::H
////////////////////////////////
JS::Value CMessageRenderSubmit::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
JS::Value CMessageRenderSubmit::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const
{
LOGWARNING("CMessageRenderSubmit::ToJSVal not implemented");
return JS::UndefinedValue();
}
CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageRenderSubmit::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
LOGWARNING("CMessageRenderSubmit::FromJSVal not implemented");
return NULL;
@ -130,13 +130,13 @@ CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterfac
////////////////////////////////
JS::Value CMessageProgressiveLoad::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
JS::Value CMessageProgressiveLoad::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const
{
LOGWARNING("CMessageProgressiveLoad::ToJSVal not implemented");
return JS::UndefinedValue();
}
CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageProgressiveLoad::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
LOGWARNING("CMessageProgressiveLoad::FromJSVal not implemented");
return NULL;
@ -144,13 +144,13 @@ CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInter
////////////////////////////////
JS::Value CMessageDeserialized::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageDeserialized::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageDeserialized::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
return new CMessageDeserialized();
@ -158,14 +158,14 @@ CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& scriptInterface, JS::
////////////////////////////////
JS::Value CMessageCreate::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageCreate::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
return JS::ObjectValue(*obj);
}
CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageCreate::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -174,14 +174,14 @@ CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, JS::Handle
////////////////////////////////
JS::Value CMessageDestroy::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageDestroy::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
return JS::ObjectValue(*obj);
}
CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageDestroy::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -190,7 +190,7 @@ CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, JS::Handl
////////////////////////////////
JS::Value CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageOwnershipChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
@ -199,7 +199,7 @@ JS::Value CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) co
return JS::ObjectValue(*obj);
}
CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageOwnershipChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -210,7 +210,7 @@ CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface,
////////////////////////////////
JS::Value CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessagePositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
@ -221,7 +221,7 @@ JS::Value CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) con
return JS::ObjectValue(*obj);
}
CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessagePositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -234,13 +234,13 @@ CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, J
////////////////////////////////
JS::Value CMessageInterpolatedPositionChanged::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
JS::Value CMessageInterpolatedPositionChanged::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const
{
LOGWARNING("CMessageInterpolatedPositionChanged::ToJSVal not implemented");
return JS::UndefinedValue();
}
CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageInterpolatedPositionChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
LOGWARNING("CMessageInterpolatedPositionChanged::FromJSVal not implemented");
return NULL;
@ -248,7 +248,7 @@ CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED
////////////////////////////////
JS::Value CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageTerritoryPositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
@ -256,7 +256,7 @@ JS::Value CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInter
return JS::ObjectValue(*obj);
}
CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageTerritoryPositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -266,7 +266,7 @@ CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInt
////////////////////////////////
JS::Value CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageMotionChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(starting);
@ -274,7 +274,7 @@ JS::Value CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const
return JS::ObjectValue(*obj);
}
CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageMotionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(bool, starting);
@ -284,7 +284,7 @@ CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, JS:
////////////////////////////////
JS::Value CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageTerrainChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(i0);
@ -294,7 +294,7 @@ JS::Value CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) cons
return OBJECT_TO_JSVAL(obj);
}
CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageTerrainChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(int32_t, i0);
@ -306,7 +306,7 @@ CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, JS
////////////////////////////////
JS::Value CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageVisibilityChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(player);
@ -316,7 +316,7 @@ JS::Value CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) c
return JS::ObjectValue(*obj);
}
CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageVisibilityChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(player_id_t, player);
@ -328,46 +328,46 @@ CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface,
////////////////////////////////
JS::Value CMessageWaterChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageWaterChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return OBJECT_TO_JSVAL(obj);
}
CMessage* CMessageWaterChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageWaterChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return new CMessageWaterChanged();
}
////////////////////////////////
JS::Value CMessageObstructionMapShapeChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageObstructionMapShapeChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageObstructionMapShapeChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageObstructionMapShapeChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return new CMessageObstructionMapShapeChanged();
}
////////////////////////////////
JS::Value CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageTerritoriesChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageTerritoriesChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageTerritoriesChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return new CMessageTerritoriesChanged();
}
////////////////////////////////
JS::Value CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageRangeUpdate::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(tag);
@ -376,7 +376,7 @@ JS::Value CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const
return JS::ObjectValue(*obj);
}
CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageRangeUpdate::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
LOGWARNING("CMessageRangeUpdate::FromJSVal not implemented");
return NULL;
@ -384,13 +384,13 @@ CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface
////////////////////////////////
JS::Value CMessagePathResult::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const
JS::Value CMessagePathResult::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const
{
LOGWARNING("CMessagePathResult::ToJSVal not implemented");
return JS::UndefinedValue();
}
CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessagePathResult::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
LOGWARNING("CMessagePathResult::FromJSVal not implemented");
return NULL;
@ -398,7 +398,7 @@ CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface)
////////////////////////////////
JS::Value CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageValueModification::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entities);
@ -407,7 +407,7 @@ JS::Value CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) c
return JS::ObjectValue(*obj);
}
CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageValueModification::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(std::vector<entity_id_t>, entities);
@ -418,7 +418,7 @@ CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface,
////////////////////////////////
JS::Value CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageTemplateModification::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(player);
@ -427,7 +427,7 @@ JS::Value CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface
return JS::ObjectValue(*obj);
}
CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageTemplateModification::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(player_id_t, player);
@ -438,7 +438,7 @@ CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterfa
////////////////////////////////
JS::Value CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageVisionRangeChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
@ -447,7 +447,7 @@ JS::Value CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface)
return JS::ObjectValue(*obj);
}
CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageVisionRangeChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -456,7 +456,7 @@ CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface
return new CMessageVisionRangeChanged(entity, oldRange, newRange);
}
JS::Value CMessageVisionSharingChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageVisionSharingChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(entity);
@ -465,7 +465,7 @@ JS::Value CMessageVisionSharingChanged::ToJSVal(ScriptInterface& scriptInterface
return JS::ObjectValue(*obj);
}
CMessage* CMessageVisionSharingChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageVisionSharingChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(entity_id_t, entity);
@ -476,27 +476,27 @@ CMessage* CMessageVisionSharingChanged::FromJSVal(ScriptInterface& scriptInterfa
////////////////////////////////
JS::Value CMessageMinimapPing::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageMinimapPing::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageMinimapPing::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
CMessage* CMessageMinimapPing::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
{
return new CMessageMinimapPing();
}
////////////////////////////////
JS::Value CMessageCinemaPathEnded::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageCinemaPathEnded::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(name);
return JS::ObjectValue(*obj);
}
CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageCinemaPathEnded::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(CStrW, name);
@ -505,13 +505,13 @@ CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, J
////////////////////////////////
JS::Value CMessageCinemaQueueEnded::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessageCinemaQueueEnded::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return JS::ObjectValue(*obj);
}
CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessageCinemaQueueEnded::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
return new CMessageCinemaQueueEnded();
@ -519,14 +519,14 @@ CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface,
////////////////////////////////////////////////////////////////
JS::Value CMessagePlayerColorChanged::ToJSVal(ScriptInterface& scriptInterface) const
JS::Value CMessagePlayerColorChanged::ToJSVal(const ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(player);
return JS::ObjectValue(*obj);
}
CMessage* CMessagePlayerColorChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val)
CMessage* CMessagePlayerColorChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(player_id_t, player);
@ -535,7 +535,7 @@ CMessage* CMessagePlayerColorChanged::FromJSVal(ScriptInterface& scriptInterface
////////////////////////////////////////////////////////////////
CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val)
CMessage* CMessageFromJSVal(int mtid, const ScriptInterface& scriptingInterface, JS::HandleValue val)
{
switch (mtid)
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,7 +22,7 @@
#include "simulation2/serialization/ISerializer.h"
#include "simulation2/serialization/IDeserializer.h"
CComponentTypeScript::CComponentTypeScript(ScriptInterface& scriptInterface, JS::HandleValue instance) :
CComponentTypeScript::CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance) :
m_ScriptInterface(scriptInterface), m_Instance(scriptInterface.GetJSRuntime(), instance)
{
// Cache the property detection for efficiency

View File

@ -31,7 +31,7 @@ class CComponentTypeScript
{
NONCOPYABLE(CComponentTypeScript);
public:
CComponentTypeScript(ScriptInterface& scriptInterface, JS::HandleValue instance);
CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance);
JS::Value GetInstance() const { return m_Instance.get(); }
@ -68,7 +68,7 @@ public:
}
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
JS::PersistentRootedValue m_Instance;
bool m_HasCustomSerialize;
bool m_HasCustomDeserialize;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -54,7 +54,7 @@ static u8 GetArrayType(js::Scalar::Type arrayType)
}
}
CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer) :
CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer) :
m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_ScriptBackrefs(scriptInterface.GetRuntime()),
m_SerializablePrototypes(new ObjectIdCache<std::wstring>(scriptInterface.GetRuntime())), m_ScriptBackrefsNext(1)
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -83,13 +83,13 @@ protected:
class CBinarySerializerScriptImpl
{
public:
CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer);
CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer);
void ScriptString(const char* name, JS::HandleString string);
void HandleScriptVal(JS::HandleValue val);
void SetSerializablePrototypes(shared_ptr<ObjectIdCache<std::wstring> > prototypes);
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
ISerializer& m_Serializer;
ObjectIdCache<u32> m_ScriptBackrefs;
@ -111,7 +111,7 @@ class CBinarySerializer : public ISerializer
{
NONCOPYABLE(CBinarySerializer);
public:
CBinarySerializer(ScriptInterface& scriptInterface) :
CBinarySerializer(const ScriptInterface& scriptInterface) :
m_ScriptImpl(new CBinarySerializerScriptImpl(scriptInterface, *this)),
m_RawStreamBuf(m_Impl),
m_RawStream(&m_RawStreamBuf)
@ -119,7 +119,7 @@ public:
}
template <typename A>
CBinarySerializer(ScriptInterface& scriptInterface, A& a) :
CBinarySerializer(const ScriptInterface& scriptInterface, A& a) :
m_ScriptImpl(new CBinarySerializerScriptImpl(scriptInterface, *this)),
m_Impl(a),
m_RawStreamBuf(m_Impl),

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -52,7 +52,7 @@ std::string canonfloat(T value, int prec)
return r;
}
CDebugSerializer::CDebugSerializer(ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo) :
CDebugSerializer::CDebugSerializer(const ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo) :
m_ScriptInterface(scriptInterface), m_Stream(stream), m_IsDebug(includeDebugInfo), m_Indent(0)
{
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -32,7 +32,7 @@ public:
* @param stream Stream to receive UTF-8 encoded output
* @param includeDebugInfo If true then additional non-deterministic data will be included in the output
*/
CDebugSerializer(ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo = true);
CDebugSerializer(const ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo = true);
void Comment(const std::string& comment);
void TextLine(const std::string& text);
@ -58,7 +58,7 @@ protected:
virtual void PutRaw(const char* name, const u8* data, size_t len);
private:
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
std::ostream& m_Stream;
bool m_IsDebug;
int m_Indent;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -19,7 +19,7 @@
#include "HashSerializer.h"
CHashSerializer::CHashSerializer(ScriptInterface& scriptInterface) :
CHashSerializer::CHashSerializer(const ScriptInterface& scriptInterface) :
CBinarySerializer<CHashSerializerImpl>(scriptInterface)
{
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -45,7 +45,7 @@ private:
class CHashSerializer : public CBinarySerializer<CHashSerializerImpl>
{
public:
CHashSerializer(ScriptInterface& scriptInterface);
CHashSerializer(const ScriptInterface& scriptInterface);
size_t GetHashLength();
const u8* ComputeHash();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -27,7 +27,7 @@
#include "lib/byte_order.h"
CStdDeserializer::CStdDeserializer(ScriptInterface& scriptInterface, std::istream& stream) :
CStdDeserializer::CStdDeserializer(const ScriptInterface& scriptInterface, std::istream& stream) :
m_ScriptInterface(scriptInterface), m_Stream(stream),
m_dummyObject(scriptInterface.GetJSRuntime())
{

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -28,7 +28,7 @@ class CStdDeserializer : public IDeserializer
{
NONCOPYABLE(CStdDeserializer);
public:
CStdDeserializer(ScriptInterface& scriptInterface, std::istream& stream);
CStdDeserializer(const ScriptInterface& scriptInterface, std::istream& stream);
virtual ~CStdDeserializer();
virtual void ScriptVal(const char* name, JS::MutableHandleValue out);
@ -57,7 +57,7 @@ private:
std::vector<JS::Heap<JSObject*> > m_ScriptBackrefs;
JS::PersistentRooted<JSObject*> m_dummyObject;
ScriptInterface& m_ScriptInterface;
const ScriptInterface& m_ScriptInterface;
std::istream& m_Stream;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -24,7 +24,7 @@ CStdSerializerImpl::CStdSerializerImpl(std::ostream& stream) :
{
}
CStdSerializer::CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream) :
CStdSerializer::CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream) :
CBinarySerializer<CStdSerializerImpl>(scriptInterface, stream)
{
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -59,7 +59,7 @@ private:
class CStdSerializer : public CBinarySerializer<CStdSerializerImpl>
{
public:
CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream);
CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream);
virtual std::ostream& GetStream();
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -42,7 +42,7 @@
}
#define DEFAULT_COMPONENT_ALLOCATOR(cname) \
static IComponent* Allocate(ScriptInterface&, JS::HandleValue) { return new CCmp##cname(); } \
static IComponent* Allocate(const ScriptInterface&, JS::HandleValue) { return new CCmp##cname(); } \
static void Deallocate(IComponent* cmp) { delete static_cast<CCmp##cname*> (cmp); } \
virtual int GetComponentTypeId() const \
{ \
@ -51,7 +51,7 @@
#define DEFAULT_SCRIPT_WRAPPER(cname) \
static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \
static IComponent* Allocate(ScriptInterface& scriptInterface, JS::HandleValue instance) \
static IComponent* Allocate(const ScriptInterface& scriptInterface, JS::HandleValue instance) \
{ \
return new CCmp##cname(scriptInterface, instance); \
} \
@ -59,7 +59,7 @@
{ \
delete static_cast<CCmp##cname*> (cmp); \
} \
CCmp##cname(ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \
CCmp##cname(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \
static std::string GetSchema() \
{ \
return "<a:component type='script-wrapper'/><empty/>"; \

View File

@ -40,9 +40,9 @@ public:
virtual int GetType() const { return mtid; }
virtual const char* GetScriptHandlerName() const { return handlerName.c_str(); }
virtual const char* GetScriptGlobalHandlerName() const { return globalHandlerName.c_str(); }
virtual JS::Value ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); }
virtual JS::Value ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); }
CMessageScripted(ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) :
CMessageScripted(const ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) :
mtid(mtid), handlerName("On" + name), globalHandlerName("OnGlobal" + name), msg(scriptInterface.GetJSRuntime(), msg)
{
}

View File

@ -49,7 +49,7 @@ public:
private:
// Component allocation types
typedef IComponent* (*AllocFunc)(ScriptInterface& scriptInterface, JS::HandleValue ctor);
typedef IComponent* (*AllocFunc)(const ScriptInterface& scriptInterface, JS::HandleValue ctor);
typedef void (*DeallocFunc)(IComponent*);
// ComponentTypes come in three types:
@ -303,11 +303,11 @@ public:
void SetRNGSeed(u32 seed);
// Various state serialization functions:
bool ComputeStateHash(std::string& outHash, bool quick);
bool DumpDebugState(std::ostream& stream, bool includeDebugInfo);
bool ComputeStateHash(std::string& outHash, bool quick) const;
bool DumpDebugState(std::ostream& stream, bool includeDebugInfo) const;
// FlushDestroyedComponents must be called before SerializeState (since the destruction queue
// won't get serialized)
bool SerializeState(std::ostream& stream);
bool SerializeState(std::ostream& stream) const;
bool DeserializeState(std::istream& stream);
std::string GenerateSchema() const;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -46,7 +46,7 @@ void DeserializeRNG(const std::string& str, boost::rand48& rng)
s >> rng;
}
bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugInfo)
bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugInfo) const
{
CDebugSerializer serializer(m_ScriptInterface, stream, includeDebugInfo);
@ -95,7 +95,7 @@ bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugIn
return true;
}
bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick)
bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) const
{
// Hash serialization: this includes the minimal data necessary to detect
// differences in the state, and ignores things like counts and names
@ -177,7 +177,7 @@ bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick)
* version), but it doesn't seem worth having a separate codepath for that.)
*/
bool CComponentManager::SerializeState(std::ostream& stream)
bool CComponentManager::SerializeState(std::ostream& stream) const
{
CStdSerializer serializer(m_ScriptInterface, stream);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -33,7 +33,7 @@ void IComponent::HandleMessage(const CMessage& UNUSED(msg), bool UNUSED(global))
{
}
bool IComponent::NewJSObject(ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleObject UNUSED(out)) const
bool IComponent::NewJSObject(const ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleObject UNUSED(out)) const
{
return false;
}

View File

@ -60,7 +60,7 @@ public:
* Returns false by default, indicating that a scripted wrapper of this IComponent is not supported.
* Derrived classes should return true if they implement such a wrapper.
*/
virtual bool NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const;
virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const;
virtual JS::Value GetJSInstance() const;
virtual int GetComponentTypeId() const = 0;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -21,7 +21,7 @@
#include "simulation2/system/IComponent.h"
#define DECLARE_INTERFACE_TYPE(iname) \
virtual bool NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; \
virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; \
static void InterfaceInit(ScriptInterface& scriptInterface); \
static int GetInterfaceId() { return IID_##iname; }

View File

@ -32,7 +32,7 @@
void ICmp##iname::InterfaceInit(ScriptInterface& scriptInterface) { \
scriptInterface.DefineCustomObjectType(&class_ICmp##iname, NULL, 0, NULL, methods_ICmp##iname, NULL, NULL); \
} \
bool ICmp##iname::NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const\
bool ICmp##iname::NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const\
{ \
out.set(scriptInterface.CreateCustomObject("ICmp" #iname)); \
return true; \

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -31,14 +31,14 @@ public:
virtual int GetType() const = 0;
virtual const char* GetScriptHandlerName() const = 0;
virtual const char* GetScriptGlobalHandlerName() const = 0;
virtual JS::Value ToJSVal(ScriptInterface&) const = 0;
JS::Value ToJSValCached(ScriptInterface&) const;
virtual JS::Value ToJSVal(const ScriptInterface&) const = 0;
JS::Value ToJSValCached(const ScriptInterface&) const;
private:
mutable std::unique_ptr<JS::PersistentRootedValue> m_Cached;
};
// TODO: GetType could be replaced with a plain member variable to avoid some
// virtual calls, if that turns out to be worthwhile
CMessage* CMessageFromJSVal(int mtid, ScriptInterface&, JS::HandleValue);
CMessage* CMessageFromJSVal(int mtid, const ScriptInterface&, JS::HandleValue);
#endif // INCLUDED_MESSAGE

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -135,7 +135,7 @@ namespace JSI_Sound
#endif
void RegisterScriptFunctions(ScriptInterface& scriptInterface)
void RegisterScriptFunctions(const ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<void, &StartMusic>("StartMusic");
scriptInterface.RegisterFunction<void, &StopMusic>("StopMusic");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,7 +23,7 @@ class ScriptInterface;
namespace JSI_Sound
{
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
void RegisterScriptFunctions(const ScriptInterface& scriptInterface);
}
#endif // #ifndef INCLUDED_SOUNDSCRIPTINTERFACE

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -135,9 +135,9 @@ namespace
}
}
void ScriptTestSetup(ScriptInterface& ifc)
void ScriptTestSetup(const ScriptInterface& scriptinterface)
{
ifc.RegisterFunction<void, std::wstring, script_TS_FAIL>("TS_FAIL");
scriptinterface.RegisterFunction<void, std::wstring, script_TS_FAIL>("TS_FAIL");
// Load the TS_* function definitions
// (We don't use VFS because tests might not have the normal VFS paths loaded)
@ -145,6 +145,6 @@ void ScriptTestSetup(ScriptInterface& ifc)
std::ifstream ifs(OsString(path).c_str());
ENSURE(ifs.good());
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
bool ok = ifc.LoadScript(L"test_setup.js", content);
bool ok = scriptinterface.LoadScript(L"test_setup.js", content);
ENSURE(ok);
}