1
0
forked from 0ad/0ad

Add missing JSAutoRequest calls. (hopefully all of them have been spotted now)

Patch by echotangoecho, refs #4053

This was SVN commit r18730.
This commit is contained in:
Nicolas Auvray 2016-09-18 09:34:45 +00:00
parent 184d64cdc8
commit caef42084d
8 changed files with 40 additions and 9 deletions

View File

@ -117,6 +117,8 @@ void CGUIManager::PopPageCB(shared_ptr<ScriptInterface::StructuredClone> args)
shared_ptr<ScriptInterface> scriptInterface = m_PageStack.back().gui->GetScriptInterface();
JSContext* cx = scriptInterface->GetContext();
JSAutoRequest rq(cx);
JS::RootedValue initDataVal(cx);
if (!initDataClone)
{

View File

@ -292,7 +292,11 @@ void CNetTurnManager::AddCommand(int client, int player, JS::HandleValue data, u
}
m_Simulation2.GetScriptInterface().FreezeObject(data, true);
m_QueuedCommands[turn - (m_CurrentTurn+1)][client].emplace_back(player, m_Simulation2.GetScriptInterface().GetContext(), data);
JSContext* cx = m_Simulation2.GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
m_QueuedCommands[turn - (m_CurrentTurn+1)][client].emplace_back(player, cx, data);
}
void CNetTurnManager::FinishedAllCommands(u32 turn, u32 turnLength)
@ -556,10 +560,13 @@ void CNetReplayTurnManager::DoTurn(u32 turn)
m_TurnLength = m_ReplayTurnLengths[turn];
JSContext* cx = m_Simulation2.GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
// Simulate commands for that turn
for (const std::pair<player_id_t, std::string>& p : m_ReplayCommands[turn])
{
JS::RootedValue command(m_Simulation2.GetScriptInterface().GetContext());
JS::RootedValue command(cx);
m_Simulation2.GetScriptInterface().ParseJSON(p.second, &command);
AddCommand(m_ClientId, p.first, command, m_CurrentTurn + 1);
}

View File

@ -185,7 +185,11 @@ bool CGame::StartVisualReplay(const std::string& replayPath)
std::string line;
std::getline(*m_ReplayStream, line);
JS::RootedValue attribs(scriptInterface.GetContext());
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue attribs(cx);
scriptInterface.ParseJSON(line, &attribs);
StartGame(&attribs, "");

View File

@ -91,8 +91,11 @@ JS::Value JSI_VFS::BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const
int flags = recurse ? vfs::DIR_RECURSIVE : 0;
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
JSAutoRequest rq(cx);
// build array in the callback function
BuildDirEntListState state(pCxPrivate->pScriptInterface->GetContext());
BuildDirEntListState state(cx);
vfs::ForEachFile(g_VFS, path, BuildDirEntListCB, (uintptr_t)&state, filter, flags);
return OBJECT_TO_JSVAL(state.filename_array);

View File

@ -298,6 +298,7 @@ public:
ENSURE(pCxPrivate->pCBData);
CAIWorker* self = static_cast<CAIWorker*> (pCxPrivate->pCBData);
JSContext* cx(self->m_ScriptInterface->GetContext());
JSAutoRequest rq(cx);
CFixedVector2D pos, goalPos;
std::vector<CFixedVector2D> waypoints;
@ -327,6 +328,7 @@ public:
ENSURE(pCxPrivate->pCBData);
CAIWorker* self = static_cast<CAIWorker*> (pCxPrivate->pCBData);
JSContext* cx(self->m_ScriptInterface->GetContext());
JSAutoRequest rq(cx);
JS::RootedValue retVal(cx);
self->m_ScriptInterface->ToJSVal<Grid<u16> >(cx, &retVal, self->m_LongPathfinder.GetConnectivityGrid(passClass));
@ -521,6 +523,7 @@ public:
m_GameState = gameState;
JSContext* cx = m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
if (dirtinessInformations.dirty)
{
@ -770,13 +773,17 @@ public:
// Require unique prototype and name (for reverse lookup)
// TODO: this is yucky - see comment in Deserialize()
ENSURE(proto.isObject() && "A serializable prototype has to be an object!");
JS::RootedObject obj(m_ScriptInterface->GetContext(), &proto.toObject());
JSContext* cx = m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
JS::RootedObject obj(cx, &proto.toObject());
if (m_SerializablePrototypes->has(obj) || m_DeserializablePrototypes.find(name) != m_DeserializablePrototypes.end())
{
LOGERROR("RegisterSerializablePrototype called with same prototype multiple times: p=%p n='%s'", (void *)obj.get(), utf8_from_wstring(name));
return;
}
m_SerializablePrototypes->add(m_ScriptInterface->GetContext(), obj, name);
m_SerializablePrototypes->add(cx, obj, name);
m_DeserializablePrototypes[name] = JS::Heap<JSObject*>(obj);
}

View File

@ -82,6 +82,8 @@ public:
virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd)
{
JSContext* cx = GetSimContext().GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
m_LocalQueue.emplace_back(SimulationCommand(player, cx, cmd));
}

View File

@ -465,7 +465,10 @@ u32 CBinarySerializerScriptImpl::GetScriptBackrefTag(JS::HandleObject obj)
if (m_ScriptBackrefs.find(obj, tag))
return tag;
m_ScriptBackrefs.add(m_ScriptInterface.GetContext(), obj, m_ScriptBackrefsNext);
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
m_ScriptBackrefs.add(cx, obj, m_ScriptBackrefsNext);
m_ScriptBackrefsNext++;
// Return a non-tag number so callers know they need to serialize the object

View File

@ -486,6 +486,9 @@ void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString ou
#error TODO: probably need to convert JS strings from little-endian
#endif
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
bool isLatin1;
Bool("isLatin1", isLatin1);
if (isLatin1)
@ -493,7 +496,7 @@ void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString ou
std::vector<JS::Latin1Char> str;
ReadStringLatin1(name, str);
out.set(JS_NewStringCopyN(m_ScriptInterface.GetContext(), (const char*)str.data(), str.size()));
out.set(JS_NewStringCopyN(cx, (const char*)str.data(), str.size()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewStringCopyN failed");
}
@ -502,7 +505,7 @@ void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString ou
utf16string str;
ReadStringUTF16(name, str);
out.set(JS_NewUCStringCopyN(m_ScriptInterface.GetContext(), (const char16_t*)str.data(), str.length()));
out.set(JS_NewUCStringCopyN(cx, (const char16_t*)str.data(), str.length()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewUCStringCopyN failed");
}