diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp index c29d656ac8..c0e7ed60c1 100644 --- a/source/graphics/MapGenerator.cpp +++ b/source/graphics/MapGenerator.cpp @@ -163,13 +163,18 @@ bool CMapGeneratorWorker::LoadLibrary(ScriptInterface::CxPrivate* pCxPrivate, st return self->LoadScripts(name); } -void CMapGeneratorWorker::ExportMap(ScriptInterface::CxPrivate* pCxPrivate, CScriptValRooted data) +void CMapGeneratorWorker::ExportMap(ScriptInterface::CxPrivate* pCxPrivate, CScriptValRooted data1) { CMapGeneratorWorker* self = static_cast(pCxPrivate->pCBData); + + JSContext* cx = self->m_ScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue data(cx, data1.get()); // Copy results CScopeLock lock(self->m_WorkerMutex); - self->m_MapData = self->m_ScriptInterface->WriteStructuredClone(data.get()); + self->m_MapData = self->m_ScriptInterface->WriteStructuredClone(data); self->m_Progress = 0; } diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index ccd85094ef..5392b58383 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -71,14 +71,19 @@ bool CGUIManager::HasPages() return !m_PageStack.empty(); } -void CGUIManager::SwitchPage(const CStrW& pageName, ScriptInterface* srcScriptInterface, CScriptVal initData) +void CGUIManager::SwitchPage(const CStrW& pageName, ScriptInterface* srcScriptInterface, CScriptVal initData1) { + JSContext* cx = srcScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue initData(cx, initData1.get()); + // The page stack is cleared (including the script context where initData came from), // therefore we have to clone initData. shared_ptr initDataClone; - if (initData.get() != JSVAL_VOID) + if (!initData.isUndefined()) { - initDataClone = srcScriptInterface->WriteStructuredClone(initData.get()); + initDataClone = srcScriptInterface->WriteStructuredClone(initData); } m_PageStack.clear(); PushPage(pageName, initDataClone); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 0a54384b0e..c1a0dd1522 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -86,9 +86,14 @@ namespace { // Note that the initData argument may only contain clonable data. // Functions aren't supported for example! // TODO: Use LOGERROR to print a friendly error message when the requirements aren't met instead of failing with debug_warn when cloning. -void PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, std::wstring name, CScriptVal initData) +void PushGuiPage(ScriptInterface::CxPrivate* pCxPrivate, std::wstring name, CScriptVal initData1) { - g_GUI->PushPage(name, pCxPrivate->pScriptInterface->WriteStructuredClone(initData.get())); + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue initData(cx, initData1.get()); + + g_GUI->PushPage(name, pCxPrivate->pScriptInterface->WriteStructuredClone(initData)); } void SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, std::wstring name, CScriptVal initData) @@ -104,9 +109,14 @@ void PopGuiPage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) // Note that the args argument may only contain clonable data. // Functions aren't supported for example! // TODO: Use LOGERROR to print a friendly error message when the requirements aren't met instead of failing with debug_warn when cloning. -void PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, CScriptVal args) +void PopGuiPageCB(ScriptInterface::CxPrivate* pCxPrivate, CScriptVal args1) { - g_GUI->PopPageCB(pCxPrivate->pScriptInterface->WriteStructuredClone(args.get())); + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue args(cx, args1.get()); + + g_GUI->PopPageCB(pCxPrivate->pScriptInterface->WriteStructuredClone(args)); } CScriptVal GuiInterfaceCall(ScriptInterface::CxPrivate* pCxPrivate, std::wstring name, CScriptVal data1) @@ -284,16 +294,26 @@ CScriptVal StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring n return guiContextMetadata.get(); } -void SaveGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring filename, std::wstring description, CScriptVal GUIMetadata) +void SaveGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring filename, std::wstring description, CScriptVal GUIMetadata1) { - shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata.get()); + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue GUIMetadata(cx, GUIMetadata1.get()); + + shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); if (SavedGames::Save(filename, description, *g_Game->GetSimulation2(), GUIMetadataClone, g_Game->GetPlayerID()) < 0) LOGERROR(L"Failed to save game"); } -void SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, std::wstring prefix, std::wstring description, CScriptVal GUIMetadata) +void SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, std::wstring prefix, std::wstring description, CScriptVal GUIMetadata1) { - shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata.get()); + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue GUIMetadata(cx, GUIMetadata1.get()); + + shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone, g_Game->GetPlayerID()) < 0) LOGERROR(L"Failed to save game"); } diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 83c2fe9694..63e633756a 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -1433,7 +1433,7 @@ ScriptInterface::StructuredClone::~StructuredClone() JS_ClearStructuredClone(m_Data, m_Size); } -shared_ptr ScriptInterface::WriteStructuredClone(jsval v) +shared_ptr ScriptInterface::WriteStructuredClone(JS::HandleValue v) { JSAutoRequest rq(m->m_cx); u64* data = NULL; diff --git a/source/scriptinterface/ScriptInterface.h b/source/scriptinterface/ScriptInterface.h index 68bc19ff4b..19fa57ea67 100644 --- a/source/scriptinterface/ScriptInterface.h +++ b/source/scriptinterface/ScriptInterface.h @@ -388,7 +388,7 @@ public: size_t m_Size; }; - shared_ptr WriteStructuredClone(jsval v); + shared_ptr WriteStructuredClone(JS::HandleValue v); void ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret); /** diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index 115ac0e893..25353daae6 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -286,20 +286,26 @@ public: self->LoadScripts(name); } - static void PostCommand(ScriptInterface::CxPrivate* pCxPrivate, int playerid, CScriptValRooted cmd) + static void PostCommand(ScriptInterface::CxPrivate* pCxPrivate, int playerid, CScriptValRooted cmd1) { ENSURE(pCxPrivate->pCBData); CAIWorker* self = static_cast (pCxPrivate->pCBData); + + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + // TODO: Get Handle parameter directly with SpiderMonkey 31 + JS::RootedValue cmd(cx, cmd1.get()); + self->PostCommand(playerid, cmd); } - void PostCommand(int playerid, CScriptValRooted cmd) + void PostCommand(int playerid, JS::HandleValue cmd) { for (size_t i=0; im_Player == playerid) { - m_Players[i]->m_Commands.push_back(m_ScriptInterface->WriteStructuredClone(cmd.get())); + m_Players[i]->m_Commands.push_back(m_ScriptInterface->WriteStructuredClone(cmd)); return; } } @@ -913,14 +919,17 @@ public: virtual void TryLoadSharedComponent() { ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); + JSContext* cx = scriptInterface.GetContext(); + JSAutoRequest rq(cx); + // load the technology templates CmpPtr cmpTechTemplateManager(GetSystemEntity()); ENSURE(cmpTechTemplateManager); // Get the game state from AIInterface - CScriptVal techTemplates = cmpTechTemplateManager->GetAllTechs(); + JS::RootedValue techTemplates(cx, cmpTechTemplateManager->GetAllTechs().get()); - m_Worker.RegisterTechTemplates(scriptInterface.WriteStructuredClone(techTemplates.get())); + m_Worker.RegisterTechTemplates(scriptInterface.WriteStructuredClone(techTemplates)); m_Worker.TryLoadSharedComponent(true); } @@ -956,7 +965,7 @@ public: LoadPathfinderClasses(state); - m_Worker.RunGamestateInit(scriptInterface.WriteStructuredClone(state.get()), *passabilityMap, *territoryMap); + m_Worker.RunGamestateInit(scriptInterface.WriteStructuredClone(state), *passabilityMap, *territoryMap); } virtual void StartComputation() diff --git a/source/simulation2/serialization/BinarySerializer.cpp b/source/simulation2/serialization/BinarySerializer.cpp index b173bb902d..d8b471b108 100644 --- a/source/simulation2/serialization/BinarySerializer.cpp +++ b/source/simulation2/serialization/BinarySerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify