From 52fe23a466631fed46a6bdd080f370ba73249667 Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Fri, 17 Dec 1999 00:08:28 +0000 Subject: [PATCH] Bug 21364. Break parent and proto pointers after compiling shared event handler. shaver mostly did this. r=brendan. Also, fix extra addref of global object, thanks mscott! --- dom/src/base/nsJSEnvironment.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 053ee3fcddb4..90d52fa7e3a6 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -180,6 +180,8 @@ nsJSContext::~nsJSContext() if (NS_SUCCEEDED(rv)) xpc->AbandonJSContext(mContext); + /* Remove global object reference to window object, so it can be collected. */ + JS_SetGlobalObject(mContext, nsnull); JS_DestroyContext(mContext); } @@ -220,7 +222,7 @@ nsJSContext::EvaluateString(const nsString& aScript, } else { // norris TODO: Using GetGlobalObject to get principals is broken? - nsCOMPtr global = GetGlobalObject(); + nsCOMPtr global = dont_AddRef(GetGlobalObject()); if (!global) return NS_ERROR_FAILURE; nsCOMPtr globalData = do_QueryInterface(global, &rv); @@ -505,6 +507,9 @@ nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName, const nsString& return NS_ERROR_FAILURE; if (aHandler) *aHandler = (void*) JS_GetFunctionObject(fun); + + /* Break scope link to avoid entraining compilation scope. */ + JS_SetParent(mContext, (JSObject *)*aHandler, nsnull); return NS_OK; }