Exact stack rooting for structured cloning functions.

Refs #2415
Refs #2462

This was SVN commit r15597.
This commit is contained in:
Yves
2014-08-01 20:55:16 +00:00
parent 7dbbb4e419
commit 608c27fe10
8 changed files with 104 additions and 54 deletions
+15 -5
View File
@@ -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));
}