From 6ebc36ca5d12cf745afd511ef3eff3aaa160f3ad Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sat, 26 Aug 2000 23:32:56 +0000 Subject: [PATCH] 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 --- mozilla/dom/src/base/nsJSEnvironment.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) {