diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index 6125ca6a544..ffa8dbda8bc 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -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) {