Index: source/network/NetClient.h =================================================================== --- source/network/NetClient.h +++ source/network/NetClient.h @@ -159,7 +159,7 @@ * Get the script interface associated with this network client, * which is equivalent to the one used by the CGame in the constructor. */ - ScriptInterface& GetScriptInterface(); + const ScriptInterface& GetScriptInterface(); /** * Send a message to the server. @@ -189,7 +189,7 @@ */ void LoadFinished(); - void SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface); + void SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface); void SendAssignPlayerMessage(const int playerID, const CStr& guid); Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -269,7 +269,7 @@ return r; } -ScriptInterface& CNetClient::GetScriptInterface() +const ScriptInterface& CNetClient::GetScriptInterface() { return m_Game->GetSimulation2()->GetScriptInterface(); } @@ -328,7 +328,7 @@ SetCurrState(NCS_UNCONNECTED); } -void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface) +void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface) { CGameSetupMessage gameSetup(scriptInterface); gameSetup.m_Data = attrs; Index: source/network/NetClientTurnManager.cpp =================================================================== --- source/network/NetClientTurnManager.cpp +++ source/network/NetClientTurnManager.cpp @@ -135,7 +135,7 @@ LOGERROR("Out-Of-Sync on turn %d\nPlayers: %s\nDumping state to %s", turn, playerNamesString.str().c_str(), oosdumpPath.string8()); - ScriptInterface& scriptInterface = m_NetClient.GetScriptInterface(); + const ScriptInterface& scriptInterface = m_NetClient.GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); Index: source/network/NetServer.h =================================================================== --- source/network/NetServer.h +++ source/network/NetServer.h @@ -126,7 +126,7 @@ * The changes will be asynchronously propagated to all clients. * @param attrs game attributes, in the script context of scriptInterface */ - void UpdateGameAttributes(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface); + void UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface); /** * Set the turn length to a fixed value. @@ -221,7 +221,7 @@ /** * Get the script context used for game attributes. */ - ScriptInterface& GetScriptInterface(); + const ScriptInterface& GetScriptInterface(); /** * Set the turn length to a fixed value. Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -845,7 +845,7 @@ Broadcast(&message, { NSS_PREGAME, NSS_JOIN_SYNCING, NSS_INGAME }); } -ScriptInterface& CNetServerWorker::GetScriptInterface() +const ScriptInterface& CNetServerWorker::GetScriptInterface() { return *m_ScriptInterface; } @@ -1068,7 +1068,7 @@ // Ignore messages sent by one player on behalf of another player // unless cheating is enabled bool cheatsEnabled = false; - ScriptInterface& scriptInterface = server.GetScriptInterface(); + const ScriptInterface& scriptInterface = server.GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); JS::RootedValue settings(cx); @@ -1502,7 +1502,7 @@ m_Worker->m_StartGameQueue.push_back(true); } -void CNetServer::UpdateGameAttributes(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface) +void CNetServer::UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface) { // Pass the attributes as JSON, since that's the easiest safe // cross-thread way of passing script data Index: source/ps/Game.cpp =================================================================== --- source/ps/Game.cpp +++ source/ps/Game.cpp @@ -173,7 +173,6 @@ debug_printf("Starting to replay %s\n", replayPath.string8().c_str()); m_IsVisualReplay = true; - ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); SetTurnManager(new CReplayTurnManager(*m_Simulation2, GetReplayLogger())); @@ -186,6 +185,7 @@ std::string line; std::getline(*m_ReplayStream, line); + const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -203,7 +203,7 @@ **/ void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState) { - ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); + const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); Index: source/ps/TemplateLoader.h =================================================================== --- source/ps/TemplateLoader.h +++ source/ps/TemplateLoader.h @@ -19,7 +19,6 @@ #define INCLUDED_TEMPLATELOADER #include "simulation2/system/ParamNode.h" -#include "scriptinterface/ScriptInterface.h" enum ETemplatesType { Index: source/scriptinterface/ScriptInterface.h =================================================================== --- source/scriptinterface/ScriptInterface.h +++ source/scriptinterface/ScriptInterface.h @@ -134,9 +134,7 @@ JSObject* CreateCustomObject(const std::string & typeName) const; void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs); - JS::Value GetGlobalObject(); - - JSClass* GetGlobalClass(); + JS::Value GetGlobalObject() const; /** * Set the named property on the global object. Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -596,17 +596,12 @@ return ok; } -JS::Value ScriptInterface::GetGlobalObject() +JS::Value ScriptInterface::GetGlobalObject() const { JSAutoRequest rq(m->m_cx); return JS::ObjectValue(*JS::CurrentGlobalOrNull(m->m_cx)); } -JSClass* ScriptInterface::GetGlobalClass() -{ - return &global_class; -} - bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool replace) { JSAutoRequest rq(m->m_cx); Index: source/simulation2/Simulation2.cpp =================================================================== --- source/simulation2/Simulation2.cpp +++ source/simulation2/Simulation2.cpp @@ -359,7 +359,7 @@ const bool serializationTestHash = true; // set true to save and compare hash of state SerializationTestState primaryStateBefore; - ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface(); + const ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface(); const bool startRejoinTest = (int64_t) m_RejoinTestTurn == m_TurnNumber; if (startRejoinTest) @@ -949,7 +949,7 @@ std::string CSimulation2::GetAIData() { - ScriptInterface& scriptInterface = GetScriptInterface(); + const ScriptInterface& scriptInterface = GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface)); Index: source/simulation2/components/CCmpAIManager.cpp =================================================================== --- source/simulation2/components/CCmpAIManager.cpp +++ source/simulation2/components/CCmpAIManager.cpp @@ -1045,7 +1045,7 @@ virtual void TryLoadSharedComponent() { - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -1063,7 +1063,7 @@ virtual void RunGamestateInit() { - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -1104,7 +1104,7 @@ ForceLoadEntityTemplates(); - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -1169,7 +1169,7 @@ if (!cmpCommandQueue) return; - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); JS::RootedValue clonedCommandVal(cx); @@ -1238,7 +1238,7 @@ if (!cmpPathfinder) return; - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); Index: source/simulation2/components/CCmpCommandQueue.cpp =================================================================== --- source/simulation2/components/CCmpCommandQueue.cpp +++ source/simulation2/components/CCmpCommandQueue.cpp @@ -105,7 +105,7 @@ virtual void FlushTurn(const std::vector& commands) { - ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); Index: source/simulation2/system/ComponentTest.h =================================================================== --- source/simulation2/system/ComponentTest.h +++ source/simulation2/system/ComponentTest.h @@ -59,7 +59,7 @@ m_ComponentManager.LoadComponentTypes(); } - ScriptInterface& GetScriptInterface() + const ScriptInterface& GetScriptInterface() { return m_ComponentManager.GetScriptInterface(); } Index: source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -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 @@ -89,7 +89,7 @@ InitGame(); // Random map - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -116,7 +116,7 @@ InitGame(); - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -149,7 +149,7 @@ { InitGame(); - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx);