Bug 577684 - Jetpack should push the JS context on to the XPConnect stack when running message receivers, r=mrbkap
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIVariant.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace jetpack {
|
||||
@@ -135,10 +136,31 @@ JetpackParent::EvalScript(const nsAString& aScript)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class AutoCXPusher
|
||||
{
|
||||
public:
|
||||
AutoCXPusher(JSContext* cx)
|
||||
: mCXStack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"))
|
||||
{
|
||||
if (mCXStack)
|
||||
mCXStack->Push(cx);
|
||||
}
|
||||
~AutoCXPusher()
|
||||
{
|
||||
if (mCXStack)
|
||||
mCXStack->Pop(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIJSContextStack> mCXStack;
|
||||
JSContext* mCX;
|
||||
};
|
||||
|
||||
bool
|
||||
JetpackParent::RecvSendMessage(const nsString& messageName,
|
||||
const nsTArray<Variant>& data)
|
||||
{
|
||||
AutoCXPusher cxp(mContext);
|
||||
JSAutoRequest request(mContext);
|
||||
return JetpackActorCommon::RecvMessage(mContext, messageName, data, NULL);
|
||||
}
|
||||
@@ -148,6 +170,7 @@ JetpackParent::RecvCallMessage(const nsString& messageName,
|
||||
const nsTArray<Variant>& data,
|
||||
nsTArray<Variant>* results)
|
||||
{
|
||||
AutoCXPusher cxp(mContext);
|
||||
JSAutoRequest request(mContext);
|
||||
return JetpackActorCommon::RecvMessage(mContext, messageName, data, results);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user