mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-14 06:55:36 +00:00
Exact stack rooting for structured cloning functions.
Refs #2415 Refs #2462 This was SVN commit r15597.
This commit is contained in:
@@ -152,11 +152,14 @@ public:
|
||||
static std::vector<SimulationCommand> CloneCommandsFromOtherContext(ScriptInterface& oldScript, ScriptInterface& newScript,
|
||||
const std::vector<SimulationCommand>& commands)
|
||||
{
|
||||
JSContext* cxOld = oldScript.GetContext();
|
||||
JSAutoRequest rqOld(cxOld);
|
||||
|
||||
std::vector<SimulationCommand> newCommands = commands;
|
||||
for (size_t i = 0; i < newCommands.size(); ++i)
|
||||
{
|
||||
newCommands[i].data = CScriptValRooted(newScript.GetContext(),
|
||||
newScript.CloneValueFromOtherContext(oldScript, newCommands[i].data.get()));
|
||||
JS::RootedValue tmpOldCommand(cxOld, newCommands[i].data.get()); // TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
|
||||
newCommands[i].data = CScriptValRooted(newScript.GetContext(), newScript.CloneValueFromOtherContext(oldScript, tmpOldCommand));
|
||||
}
|
||||
return newCommands;
|
||||
}
|
||||
@@ -356,9 +359,16 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
|
||||
|
||||
// Load the trigger scripts after we have loaded the simulation.
|
||||
{
|
||||
JSContext* cx = secondaryComponentManager.GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::RootedValue mapSettingsCloned(cx, secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext(m_ComponentManager.GetScriptInterface(), m_MapSettings.get()));
|
||||
JSContext* cx1 = m_ComponentManager.GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq1(cx1);
|
||||
// TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
|
||||
JS::RootedValue tmpMapSettings(cx1, m_MapSettings.get());
|
||||
|
||||
JSContext* cx2 = secondaryComponentManager.GetScriptInterface().GetContext();
|
||||
JSAutoRequest rq2(cx2);
|
||||
JS::RootedValue mapSettingsCloned(cx2,
|
||||
secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext(
|
||||
m_ComponentManager.GetScriptInterface(), tmpMapSettings));
|
||||
ENSURE(LoadTriggerScripts(secondaryComponentManager, mapSettingsCloned));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user