mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 19:33:18 +00:00
bug 321522: The sandbox object needs to come from a new context, not the old
context. r=shaver sr=brendan
This commit is contained in:
parent
93383ac1ed
commit
b694b9110c
@ -2246,7 +2246,11 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
|
||||
if(NS_FAILED(rv))
|
||||
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
||||
|
||||
JSObject *sandbox = JS_NewObject(cx, &SandboxClass, nsnull, nsnull);
|
||||
XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
|
||||
if (!tempcx)
|
||||
return ThrowAndFail(NS_ERROR_OUT_OF_MEMORY, cx, _retval);
|
||||
|
||||
JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
|
||||
if (!sandbox)
|
||||
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
||||
|
||||
|
@ -388,6 +388,34 @@ private:
|
||||
static void operator delete(void* /*memory*/) {}
|
||||
};
|
||||
|
||||
// A helper class to deal with temporary JS contexts. It destroys the context
|
||||
// when it goes out of scope.
|
||||
class XPCAutoJSContext
|
||||
{
|
||||
public:
|
||||
XPCAutoJSContext(JSContext *aContext, PRBool aGCOnDestroy)
|
||||
: mContext(aContext), mGCOnDestroy(aGCOnDestroy)
|
||||
{
|
||||
}
|
||||
|
||||
~XPCAutoJSContext()
|
||||
{
|
||||
if(!mContext)
|
||||
return;
|
||||
|
||||
if(mGCOnDestroy)
|
||||
JS_DestroyContext(mContext);
|
||||
else
|
||||
JS_DestroyContextNoGC(mContext);
|
||||
}
|
||||
|
||||
operator JSContext * () {return mContext;}
|
||||
|
||||
private:
|
||||
JSContext *mContext;
|
||||
PRBool mGCOnDestroy;
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
****************************************************************************
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user