зеркало из https://github.com/mozilla/pjs.git
Bug 552516 - Don't create a temporary context for the new sandbox object. r=igor
--HG-- extra : rebase_source : 78b20a13d174f1ddf0b47556e9ea39fbe724c2cb
This commit is contained in:
Родитель
ea5e8d7433
Коммит
8b48b15f08
|
@ -3217,16 +3217,11 @@ xpc_CreateSandboxObject(JSContext * cx, jsval * vp, nsISupports *prinOrSop)
|
|||
if(NS_FAILED(rv))
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
|
||||
XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
|
||||
if (!tempcx)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
AutoJSRequestWithNoCallContext req(tempcx);
|
||||
JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
|
||||
JSObject *sandbox = JS_NewObjectWithGivenProto(cx, &SandboxClass,
|
||||
nsnull, nsnull);
|
||||
if (!sandbox)
|
||||
return NS_ERROR_XPC_UNEXPECTED;
|
||||
|
||||
JS_SetGlobalObject(tempcx, sandbox);
|
||||
JSAutoTempValueRooter tvr(cx, sandbox);
|
||||
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(prinOrSop));
|
||||
|
||||
|
@ -3398,6 +3393,7 @@ class ContextHolder : public nsISupports
|
|||
{
|
||||
public:
|
||||
ContextHolder(JSContext *aOuterCx, JSObject *aSandbox);
|
||||
virtual ~ContextHolder();
|
||||
|
||||
JSContext * GetJSContext()
|
||||
{
|
||||
|
@ -3408,15 +3404,15 @@ public:
|
|||
|
||||
private:
|
||||
static JSBool ContextHolderOperationCallback(JSContext *cx);
|
||||
|
||||
XPCAutoJSContext mJSContext;
|
||||
|
||||
JSContext* mJSContext;
|
||||
JSContext* mOrigCx;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS0(ContextHolder)
|
||||
|
||||
ContextHolder::ContextHolder(JSContext *aOuterCx, JSObject *aSandbox)
|
||||
: mJSContext(JS_NewContext(JS_GetRuntime(aOuterCx), 1024), JS_FALSE),
|
||||
: mJSContext(JS_NewContext(JS_GetRuntime(aOuterCx), 1024)),
|
||||
mOrigCx(aOuterCx)
|
||||
{
|
||||
if(mJSContext)
|
||||
|
@ -3431,6 +3427,12 @@ ContextHolder::ContextHolder(JSContext *aOuterCx, JSObject *aSandbox)
|
|||
}
|
||||
}
|
||||
|
||||
ContextHolder::~ContextHolder()
|
||||
{
|
||||
if(mJSContext)
|
||||
JS_DestroyContextNoGC(mJSContext);
|
||||
}
|
||||
|
||||
JSBool
|
||||
ContextHolder::ContextHolderOperationCallback(JSContext *cx)
|
||||
{
|
||||
|
|
|
@ -399,34 +399,6 @@ 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;
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
****************************************************************************
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче