Separated class intialization from name registration in namespace management code

This commit is contained in:
vidur%netscape.com 1998-12-30 21:35:35 +00:00
parent 9b2f69e89a
commit 566459d539
7 changed files with 65 additions and 1 deletions

View File

@ -45,7 +45,14 @@ class nsIScriptContext;
class nsIScriptExternalNameSet : public nsISupports {
public:
/**
* Called for each new name set
* Called to tell the name set to do any class initialization
* it needs to
*/
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext) = 0;
/**
* Called to tell the name set to add its names to the
* namespace manager of the context.
*/
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext) = 0;
};

View File

@ -56,6 +56,14 @@ public:
*/
NS_IMETHOD RemoveExternalNameSet(nsIScriptExternalNameSet* aNameSet) = 0;
/**
* Intialize classes associated with the name sets.
*
* @param aScriptContext the script context within which to initialize
* @result NS_OK if successful
*/
NS_IMETHOD InitializeClasses(nsIScriptContext* aContext) = 0;
/**
* Populate the specified script context with all of the
* name sets in the registry. Will generally be called when the

View File

@ -154,6 +154,24 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
return res;
}
nsresult
nsJSContext::InitializeExternalClasses()
{
nsresult result = NS_OK;
nsIScriptNameSetRegistry* registry;
result = nsServiceManager::GetService(kCScriptNameSetRegistryCID,
kIScriptNameSetRegistryIID,
(nsISupports **)&registry);
if (NS_OK == result) {
result = registry->InitializeClasses(this);
nsServiceManager::ReleaseService(kCScriptNameSetRegistryCID,
registry);
}
return result;
}
NS_IMETHODIMP
nsJSContext::InitClasses()
{
@ -168,6 +186,7 @@ nsJSContext::InitClasses()
NS_OK == NS_InitAttrClass(this, nsnull) &&
NS_OK == NS_InitNamedNodeMapClass(this, nsnull) &&
NS_OK == NS_InitNodeListClass(this, nsnull) &&
NS_OK == InitializeExternalClasses() &&
// XXX Temporarily here. This shouldn't be hardcoded.
NS_OK == NS_InitHTMLImageElementClass(this, nsnull)) {
res = NS_OK;

View File

@ -52,6 +52,8 @@ public:
NS_IMETHOD GC();
NS_IMETHOD GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr);
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr);
nsresult InitializeExternalClasses();
};
class nsJSEnvironment {

View File

@ -65,6 +65,26 @@ nsScriptNameSetRegistry::RemoveExternalNameSet(nsIScriptExternalNameSet* aNameSe
}
}
NS_IMETHODIMP
nsScriptNameSetRegistry::InitializeClasses(nsIScriptContext* aContext)
{
nsresult result = NS_OK;
if (nsnull != aContext) {
PRInt32 i, count = mNameSets.Count();
for (i = 0; i < count; i++) {
nsIScriptExternalNameSet* ns = (nsIScriptExternalNameSet*)mNameSets.ElementAt(i);
if (nsnull != ns) {
result = ns->InitializeClasses(aContext);
if (NS_OK != result) {
break;
}
}
}
}
return result;
}
NS_IMETHODIMP
nsScriptNameSetRegistry::PopulateNameSpace(nsIScriptContext* aContext)
{

View File

@ -33,6 +33,7 @@ class nsScriptNameSetRegistry : public nsIScriptNameSetRegistry {
NS_IMETHOD AddExternalNameSet(nsIScriptExternalNameSet* aNameSet);
NS_IMETHOD RemoveExternalNameSet(nsIScriptExternalNameSet* aNameSet);
NS_IMETHOD InitializeClasses(nsIScriptContext* aContext);
NS_IMETHOD PopulateNameSpace(nsIScriptContext* aScriptContext);
protected:

View File

@ -288,6 +288,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext);
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext);
};
@ -302,6 +303,12 @@ LayoutScriptNameSet::~LayoutScriptNameSet()
NS_IMPL_ISUPPORTS(LayoutScriptNameSet, kIScriptExternalNameSetIID);
NS_IMETHODIMP
LayoutScriptNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
{
return NS_OK;
}
NS_IMETHODIMP
LayoutScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext)
{