From 72a6885a89954e1cee4c64beaabed7a6a2e4cb9e Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Sun, 20 Feb 2005 17:02:02 +0000 Subject: [PATCH] Docshell doesn't need to hold a pointer to the scriptcontext; the window does it. Bug 282807, r+sr=jst git-svn-id: svn://10.0.0.236/trunk@169528 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 14 +++++++------- mozilla/docshell/base/nsDocShell.h | 1 - mozilla/docshell/base/nsWebShell.cpp | 9 --------- mozilla/dom/src/base/nsGlobalWindow.cpp | 13 +++++++++++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 656a1b5bd0b..73aa578e208 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3405,10 +3405,6 @@ nsDocShell::Destroy() mScriptGlobal->SetGlobalObjectOwner(nsnull); mScriptGlobal = nsnull; } - if (mScriptContext) { - mScriptContext->SetOwner(nsnull); - mScriptContext = nsnull; - } mSessionHistory = nsnull; SetTreeOwner(nsnull); @@ -6959,7 +6955,7 @@ nsDocShell::GetRootScrollableView(nsIScrollableView ** aOutScrollView) NS_IMETHODIMP nsDocShell::EnsureScriptEnvironment() { - if (mScriptContext) + if (mScriptGlobal) return NS_OK; if (mIsBeingDestroyed) { @@ -6979,8 +6975,12 @@ nsDocShell::EnsureScriptEnvironment() SetGlobalObjectOwner(NS_STATIC_CAST (nsIScriptGlobalObjectOwner *, this)); - factory->NewScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext)); - NS_ENSURE_TRUE(mScriptContext, NS_ERROR_FAILURE); + nsCOMPtr context; + factory->NewScriptContext(mScriptGlobal, getter_AddRefs(context)); + NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); + + // Note that mScriptGlobal has taken a reference to the script + // context, so we don't have to. return NS_OK; } diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 615433c8dd8..5566f647fce 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -435,7 +435,6 @@ protected: nsCOMPtr mCurrentURI; nsCOMPtr mReferrerURI; nsCOMPtr mScriptGlobal; - nsCOMPtr mScriptContext; nsCOMPtr mSessionHistory; nsCOMPtr mGlobalHistory; nsCOMPtr mFind; diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 06a5da99c4b..0b2f1278a9d 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -188,15 +188,6 @@ nsWebShell::~nsWebShell() mContentViewer=nsnull; mDeviceContext=nsnull; - if (mScriptGlobal) { - mScriptGlobal->SetDocShell(nsnull); - mScriptGlobal = nsnull; - } - if (mScriptContext) { - mScriptContext->SetOwner(nsnull); - mScriptContext = nsnull; - } - InitFrameData(); #ifdef DEBUG diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 06689416569..e4c27ec7e04 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -278,7 +278,10 @@ nsGlobalWindow::CleanUp() ClearControllers(); mOpener = nsnull; // Forces Release - mContext = nsnull; // Forces Release + if (mContext) { + mContext->SetOwner(nsnull); + mContext = nsnull; // Forces Release + } mChromeEventHandler = nsnull; // Forces Release if (IsPopupSpamWindow()) { @@ -354,6 +357,9 @@ nsGlobalWindow::SetContext(nsIScriptContext* aContext) mJSObject = ::JS_GetGlobalObject(cx); } + if (mContext) { + mContext->SetOwner(nsnull); + } mContext = aContext; if (mContext) { @@ -718,7 +724,10 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell) mContext->GC(); - mContext = nsnull; // force release now + if (mContext) { + mContext->SetOwner(nsnull); + mContext = nsnull; // force release now + } mChromeEventHandler = nsnull; // force release now }