added the ability to save a script object for unrooting from the GC in this object's destructor. bug 43466 r=brendan,jst,vidur
git-svn-id: svn://10.0.0.236/trunk@77317 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -256,6 +256,7 @@ nsJSContext::DOMBranchCallback(JSContext *cx, JSScript *script)
|
||||
nsJSContext::nsJSContext(JSRuntime *aRuntime)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mRootedScriptObject = nsnull;
|
||||
mContext = ::JS_NewContext(aRuntime, gStackSize);
|
||||
if (mContext) {
|
||||
::JS_SetContextPrivate(mContext, (void *)this);
|
||||
@@ -310,6 +311,10 @@ nsJSContext::~nsJSContext()
|
||||
if (!mContext)
|
||||
return;
|
||||
|
||||
// if we were handed an object to remember to unroot now, do it
|
||||
if (mRootedScriptObject)
|
||||
::JS_RemoveRoot(mContext, &mRootedScriptObject);
|
||||
|
||||
/* Remove global object reference to window object, so it can be collected. */
|
||||
::JS_SetGlobalObject(mContext, nsnull);
|
||||
::JS_DestroyContext(mContext);
|
||||
@@ -1248,6 +1253,17 @@ nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSContext::SetRootedScriptObject(void *aObject)
|
||||
{
|
||||
NS_ASSERTION(mRootedScriptObject == nsnull, "two rooted script objects stored");
|
||||
mRootedScriptObject = aObject;
|
||||
if (::JS_AddNamedRoot(mContext, &mRootedScriptObject, "jscontext_savedroot"))
|
||||
return NS_OK;
|
||||
mRootedScriptObject = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSContext::GetScriptsEnabled(PRBool *aEnabled)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user