diff --git a/mozilla/dom/public/nsIScriptContext.h b/mozilla/dom/public/nsIScriptContext.h index 1f162842058..cb0464cc3c1 100644 --- a/mozilla/dom/public/nsIScriptContext.h +++ b/mozilla/dom/public/nsIScriptContext.h @@ -326,6 +326,11 @@ public: */ NS_IMETHOD GetProcessingScriptTag(PRBool * aResult) =0; NS_IMETHOD SetProcessingScriptTag(PRBool aResult) =0; + + /** + * Tell the context whether or not to GC when destroyed. + */ + NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction) = 0; }; #endif // nsIScriptContext_h__ diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 53060711447..cb005056624 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -193,8 +193,6 @@ GlobalWindowImpl::~GlobalWindowImpl() { if (!--gRefCnt) { NS_IF_RELEASE(gEntropyCollector); - - NS_IF_RELEASE(sXPConnect); } mDocument = nsnull; // Forces Release @@ -278,6 +276,19 @@ NS_IMETHODIMP GlobalWindowImpl::SetContext(nsIScriptContext* aContext) mContext = aContext; + if (mContext) { + nsCOMPtr parent; + GetParent(getter_AddRefs(parent)); + + if (parent && parent != NS_STATIC_CAST(nsIDOMWindow *, this)) { + // This window is a [i]frame, don't bother GC'ing when the + // frame's context is destroyed since a GC will happen when the + // frameset or host document is destroyed anyway. + + mContext->SetGCOnDestruction(PR_FALSE); + } + } + return NS_OK; } diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index e398db27f7a..7020d8c21f9 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -350,7 +350,7 @@ nsJSContext::JSOptionChangedCallback(const char *pref, void *data) return 0; } -nsJSContext::nsJSContext(JSRuntime *aRuntime) +nsJSContext::nsJSContext(JSRuntime *aRuntime) : mGCOnDestruction(PR_TRUE) { NS_INIT_REFCNT(); @@ -420,7 +420,7 @@ nsJSContext::~nsJSContext() // Let xpconnect destroy the JSContext when it thinks the time is right. nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); if (xpc) { - xpc->ReleaseJSContext(mContext, PR_FALSE); + xpc->ReleaseJSContext(mContext, !mGCOnDestruction); } else { ::JS_DestroyContext(mContext); } @@ -1496,6 +1496,14 @@ nsJSContext::SetProcessingScriptTag(PRBool aFlag) return NS_OK; } +NS_IMETHODIMP +nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction) +{ + mGCOnDestruction = aGCOnDestruction; + + return NS_OK; +} + NS_IMETHODIMP nsJSContext::ScriptExecuted() { diff --git a/mozilla/dom/src/base/nsJSEnvironment.h b/mozilla/dom/src/base/nsJSEnvironment.h index 62a0e5ba6cc..3d626c7aeed 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.h +++ b/mozilla/dom/src/base/nsJSEnvironment.h @@ -124,6 +124,8 @@ public: NS_IMETHOD GetProcessingScriptTag(PRBool * aResult); NS_IMETHOD SetProcessingScriptTag(PRBool aResult); + NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction); + NS_DECL_NSIXPCSCRIPTNOTIFY protected: nsresult InitClasses(); @@ -142,6 +144,7 @@ private: PRPackedBool mIsInitialized; PRPackedBool mScriptsEnabled; + PRPackedBool mGCOnDestruction; PRUint32 mBranchCallbackCount; PRUint32 mDefaultJSOptions;