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
+8 -8
View File
@@ -1451,12 +1451,14 @@ void ScriptInterface::ForceGC()
JS_GC(this->GetJSRuntime());
}
jsval ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, jsval val)
JS::Value ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val)
{
PROFILE("CloneValueFromOtherContext");
shared_ptr<StructuredClone> structuredClone = otherContext.WriteStructuredClone(val);
jsval clone = ReadStructuredClone(structuredClone);
return clone;
JSAutoRequest rq(m->m_cx);
JS::RootedValue out(m->m_cx);
shared_ptr<StructuredClone> structuredClone = otherContext.WriteStructuredClone(val);
ReadStructuredClone(structuredClone, &out);
return out.get();
}
ScriptInterface::StructuredClone::StructuredClone() :
@@ -1487,10 +1489,8 @@ shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClo
return ret;
}
jsval ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr)
void ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr, JS::MutableHandleValue ret)
{
JSAutoRequest rq(m->m_cx);
jsval ret = JSVAL_VOID;
JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, &ret, NULL, NULL);
return ret;
JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, ret.address(), NULL, NULL);
}
+2 -2
View File
@@ -322,7 +322,7 @@ public:
* Complex values (functions, XML, etc) won't be cloned correctly, but basic
* types and cyclic references should be fine.
*/
jsval CloneValueFromOtherContext(ScriptInterface& otherContext, jsval val);
JS::Value CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val);
/**
* Convert a jsval to a C++ type. (This might trigger GC.)
@@ -393,7 +393,7 @@ public:
};
shared_ptr<StructuredClone> WriteStructuredClone(jsval v);
jsval ReadStructuredClone(const shared_ptr<StructuredClone>& ptr);
void ReadStructuredClone(const shared_ptr<StructuredClone>& ptr, JS::MutableHandleValue ret);
/**
* Converts |a| if needed and assigns it to |handle|.