Fixing bug 90765. Hold a strong reference to the global object's wrapper to avoid users of that wrapper to cause rooting and unrooting of the global object every time the global object wrapper is addreffed. r=dbaron@fas.harvard.edu, sr=jband@netscape.com

git-svn-id: svn://10.0.0.236/trunk@106824 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jst%netscape.com 2001-10-31 08:39:09 +00:00
parent b27e4fa386
commit 02e8ea3ff2
2 changed files with 18 additions and 5 deletions

View File

@ -417,6 +417,9 @@ nsJSContext::~nsJSContext()
this);
}
// Release mGlobalWrapperRef before the context is destroyed
mGlobalWrapperRef = nsnull;
// Let xpconnect destroy the JSContext when it thinks the time is right.
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
if (xpc) {
@ -1103,12 +1106,12 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
JSObject *global = ::JS_GetGlobalObject(mContext);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
// If there's already a global object in mContext we won't tell
// XPConnect to wrap aGlobalObject since it's already wrapped.
if (!global) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(mContext, aGlobalObject,
NS_GET_IID(nsISupports),
PR_FALSE,
@ -1125,8 +1128,6 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
nsCOMPtr<nsIClassInfo> ci(do_QueryInterface(aGlobalObject));
if (ci) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->WrapNative(mContext, global, aGlobalObject,
NS_GET_IID(nsISupports),
getter_AddRefs(holder));
@ -1140,6 +1141,11 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
}
}
// Hold a strong reference to the wrapper for the global to avoid
// rooting and unrooting the global object every time its AddRef()
// or Release() methods are called
mGlobalWrapperRef = holder;
rv = InitClasses(); // this will complete global object initialization
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -145,10 +145,17 @@ private:
PRPackedBool mIsInitialized;
PRPackedBool mScriptsEnabled;
PRPackedBool mGCOnDestruction;
PRPackedBool mProcessingScriptTag;
PRUint32 mBranchCallbackCount;
PRUint32 mDefaultJSOptions;
PRBool mProcessingScriptTag;
// mGlobalWrapperRef is used only to hold a strong reference to the
// global object wrapper while the nsJSContext is alive. This cuts
// down on the number of rooting and unrooting calls XPConnect has
// to make when the global object is touched in JS.
nsCOMPtr<nsISupports> mGlobalWrapperRef;
static int PR_CALLBACK JSOptionChangedCallback(const char *pref, void *data);