From c5bcb7ded785e9c1f0ad48bd8e74ce5e21eef2d5 Mon Sep 17 00:00:00 2001 From: "vidur%netscape.com" Date: Wed, 30 Dec 1998 02:46:36 +0000 Subject: [PATCH] Fixed early initialization problem in script namespace management --- dom/public/nsIScriptContext.h | 9 +++++++++ dom/public/nsIScriptExternalNameSet.h | 2 +- dom/src/base/nsJSEnvironment.cpp | 15 +++++++++++++++ dom/src/base/nsJSEnvironment.h | 2 ++ dom/src/base/nsJSUtils.cpp | 4 ++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dom/public/nsIScriptContext.h b/dom/public/nsIScriptContext.h index cf5f6f3a1cc..acd02591472 100644 --- a/dom/public/nsIScriptContext.h +++ b/dom/public/nsIScriptContext.h @@ -85,6 +85,15 @@ public: **/ NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject) = 0; + /** + * Check to see if context is as yet intialized. Used to prevent + * reentrancy issues during the initialization process. + * + * @return NS_OK if initialized, NS_COMFALSE if not + * + */ + NS_IMETHOD IsContextInitialized() = 0; + /** * Add a reference to a script object. For garbage collected systems * the address of a slot to be used as a root is also provided. For diff --git a/dom/public/nsIScriptExternalNameSet.h b/dom/public/nsIScriptExternalNameSet.h index 4d210e499b2..101408ab4ce 100644 --- a/dom/public/nsIScriptExternalNameSet.h +++ b/dom/public/nsIScriptExternalNameSet.h @@ -45,7 +45,7 @@ class nsIScriptContext; class nsIScriptExternalNameSet : public nsISupports { public: /** - * Called for each new + * Called for each new name set */ NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext) = 0; }; diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 97ad09534f3..ee6f3d62db0 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -61,10 +61,12 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime) mContext = JS_NewContext(aRuntime, gStackSize); JS_SetContextPrivate(mContext, (void *)this); mNameSpaceManager = nsnull; + mIsInitialized = PR_FALSE; } nsJSContext::~nsJSContext() { + NS_IF_RELEASE(mNameSpaceManager); JS_DestroyContext(mContext); } @@ -171,10 +173,23 @@ nsJSContext::InitClasses() res = NS_OK; } + mIsInitialized = PR_TRUE; + NS_RELEASE(global); return res; } +NS_IMETHODIMP +nsJSContext::IsContextInitialized() +{ + if (mIsInitialized) { + return NS_OK; + } + else { + return NS_COMFALSE; + } +} + NS_IMETHODIMP nsJSContext::AddNamedReference(void *aSlot, void *aScriptObject, diff --git a/dom/src/base/nsJSEnvironment.h b/dom/src/base/nsJSEnvironment.h index 385a9af109e..2c051fedfdd 100644 --- a/dom/src/base/nsJSEnvironment.h +++ b/dom/src/base/nsJSEnvironment.h @@ -28,6 +28,7 @@ class nsJSContext : public nsIScriptContext { private: JSContext *mContext; nsIScriptNameSpaceManager* mNameSpaceManager; + PRBool mIsInitialized; public: nsJSContext(JSRuntime *aRuntime); @@ -44,6 +45,7 @@ public: NS_IMETHOD_(void*) GetNativeContext(); NS_IMETHOD InitClasses(); NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject); + NS_IMETHOD IsContextInitialized(); NS_IMETHOD AddNamedReference(void *aSlot, void *aScriptObject, const char *aName); NS_IMETHOD RemoveReference(void *aSlot, void *aScriptObject); diff --git a/dom/src/base/nsJSUtils.cpp b/dom/src/base/nsJSUtils.cpp index c4e15a66541..97db723df1f 100644 --- a/dom/src/base/nsJSUtils.cpp +++ b/dom/src/base/nsJSUtils.cpp @@ -268,6 +268,10 @@ nsJSUtils::nsGlobalResolve(JSContext* aContext, nsIID classID; nsISupports* native; + if (NS_COMFALSE == scriptContext->IsContextInitialized()) { + return JS_TRUE; + } + result = scriptContext->GetNameSpaceManager(&manager); if (NS_OK == result) { result = manager->LookupName(name, PR_FALSE, classID);