Fixed early initialization problem in script namespace management

This commit is contained in:
vidur%netscape.com 1998-12-30 02:46:36 +00:00
Родитель 3cd6a644b6
Коммит c534e7ce68
5 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -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,

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);