diff --git a/mozilla/dom/public/MANIFEST b/mozilla/dom/public/MANIFEST index 9daeb0c6d50..9179c8408ef 100644 --- a/mozilla/dom/public/MANIFEST +++ b/mozilla/dom/public/MANIFEST @@ -25,4 +25,7 @@ nsIScriptEventListener.h nsIDOMScriptObjectFactory.h nsIDOMNativeObjectRegistry.h nsDOMCID.h -nsIScriptSecurityManager.h \ No newline at end of file +nsIScriptSecurityManager.h +nsIScriptNameSetRegistry.h +nsIScriptExternalNameSet.h +nsIScriptNameSpaceManager.h diff --git a/mozilla/dom/public/Makefile.in b/mozilla/dom/public/Makefile.in index 57a53bad4d5..9999f472509 100644 --- a/mozilla/dom/public/Makefile.in +++ b/mozilla/dom/public/Makefile.in @@ -37,6 +37,9 @@ EXPORTS = \ nsIDOMNativeObjectRegistry.h \ nsDOMCID.h \ nsIScriptSecurityManager.h \ + nsIScriptNameSetRegistry.h \ + nsIScriptExternalNameSet.h \ + nsIScriptNameSpaceManager.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win index 8ee93894c98..63921f9fbea 100644 --- a/mozilla/dom/public/makefile.win +++ b/mozilla/dom/public/makefile.win @@ -20,10 +20,19 @@ IGNORE_MANIFEST=1 DIRS=base coreDom coreEvents events html css DEFINES=-D_IMPL_NS_DOM -EXPORTS=nsIScriptContext.h nsIJSScriptObject.h nsIScriptObjectOwner.h \ - nsIScriptGlobalObject.h nsIScriptContextOwner.h \ - nsIScriptEventListener.h nsIDOMScriptObjectFactory.h \ - nsIDOMNativeObjectRegistry.h nsDOMCID.h nsIScriptSecurityManager.h +EXPORTS=nsIScriptContext.h \ + nsIJSScriptObject.h \ + nsIScriptObjectOwner.h \ + nsIScriptGlobalObject.h \ + nsIScriptContextOwner.h \ + nsIScriptEventListener.h \ + nsIDOMScriptObjectFactory.h \ + nsIDOMNativeObjectRegistry.h \ + nsDOMCID.h \ + nsIScriptSecurityManager.h \ + nsIScriptNameSetRegistry.h \ + nsIScriptExternalNameSet.h \ + nsIScriptNameSpaceManager.h MODULE=dom diff --git a/mozilla/dom/public/nsDOMCID.h b/mozilla/dom/public/nsDOMCID.h index 6f0a90de10c..377705964e0 100644 --- a/mozilla/dom/public/nsDOMCID.h +++ b/mozilla/dom/public/nsDOMCID.h @@ -33,4 +33,9 @@ 0x651074a0, 0x4cd4, 0x11d2, \ {0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59 } } +#define NS_DOM_SCRIPT_NAMESET_REGISTRY_CID \ + { /* 45f27d10-987b-11d2-bd40-00105aa45e89 */ \ + 0x45f27d10, 0x987b, 0x11d2, \ + {0xbd, 0x40, 0x00, 0x10, 0x5a, 0xa4, 0x5e, 0x89} } + #endif /* nsDOMCID_h__ */ diff --git a/mozilla/dom/public/nsIScriptContext.h b/mozilla/dom/public/nsIScriptContext.h index d799f079fdd..cf5f6f3a1cc 100644 --- a/mozilla/dom/public/nsIScriptContext.h +++ b/mozilla/dom/public/nsIScriptContext.h @@ -25,10 +25,11 @@ class nsIScriptGlobalObject; class nsIScriptSecurityManager; +class nsIScriptNameSpaceManager; #define NS_ISCRIPTCONTEXT_IID \ { /* 8f6bca7d-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca7d, 0xce42, 0x11d1, \ + 0x8f6bca7d, 0xce42, 0x11d1, \ {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } /** @@ -50,29 +51,29 @@ public: * @return true if the script was valid and got executed * **/ - virtual PRBool EvaluateString(const nsString& aScript, - const char *aURL, - PRUint32 aLineNo, - nsString& aRetValue, - PRBool* aIsUndefined) = 0; + NS_IMETHOD_(PRBool) EvaluateString(const nsString& aScript, + const char *aURL, + PRUint32 aLineNo, + nsString& aRetValue, + PRBool* aIsUndefined) = 0; /** * Return the global object. * **/ - virtual nsIScriptGlobalObject* GetGlobalObject() = 0; + NS_IMETHOD_(nsIScriptGlobalObject*) GetGlobalObject() = 0; /** * Return the native script context * **/ - virtual void* GetNativeContext() = 0; + NS_IMETHOD_(void*) GetNativeContext() = 0; /** * Init all DOM classes. * **/ - virtual nsresult InitClasses() = 0; + NS_IMETHOD InitClasses() = 0; /** * Init this context. @@ -82,7 +83,7 @@ public: * @return NS_OK if context initialization was successful * **/ - virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject) = 0; + NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject) = 0; /** * Add a reference to a script object. For garbage collected systems @@ -95,7 +96,7 @@ public: * * @return NS_OK if the method is successful */ - virtual nsresult AddNamedReference(void *aSlot, void *aScriptObject, + NS_IMETHOD AddNamedReference(void *aSlot, void *aScriptObject, const char *aName) = 0; /** @@ -107,7 +108,7 @@ public: * * @return NS_OK if the method is successful */ - virtual nsresult RemoveReference(void *aSlot, void *aScriptObject) = 0; + NS_IMETHOD RemoveReference(void *aSlot, void *aScriptObject) = 0; /** * For garbage collected systems, do a synchronous collection pass. @@ -115,7 +116,13 @@ public: * * @return NS_OK if the method is successful */ - virtual nsresult GC() = 0; + NS_IMETHOD GC() = 0; + + /** + * Get the name space manager for this context. + * @return NS_OK if the method is successful + */ + NS_IMETHOD GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr) = 0; /** * Get the security manager for this context. diff --git a/mozilla/dom/public/nsIScriptNameSetRegistry.h b/mozilla/dom/public/nsIScriptNameSetRegistry.h index c9f85338c23..8531ad8f779 100644 --- a/mozilla/dom/public/nsIScriptNameSetRegistry.h +++ b/mozilla/dom/public/nsIScriptNameSetRegistry.h @@ -24,8 +24,8 @@ #include "nsString.h" #include "nsISupports.h" -#define NS_ISCRIPTNAMESETREGISTRY_IID \ - {0xa6cf90d9, 0x15b3, 0x11d2, \ +#define NS_ISCRIPTNAMESETREGISTRY_IID \ + {0xa6cf90d9, 0x15b3, 0x11d2, \ {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} class nsIScriptExternalNameSet; diff --git a/mozilla/dom/public/nsIScriptNameSpaceManager.h b/mozilla/dom/public/nsIScriptNameSpaceManager.h index 4ebfbffd4ce..bf609db25a3 100644 --- a/mozilla/dom/public/nsIScriptNameSpaceManager.h +++ b/mozilla/dom/public/nsIScriptNameSpaceManager.h @@ -66,11 +66,17 @@ public: * a factory. * * @param aName the name to use as a key for the lookup + * @param aIsConstructor PR_TRUE if we're looking for + * a constructor. PR_FALSE if we're looking for + * a global symbol. * @param aCID out parameter that returns the class ID * that corresponds to the name - * @result NS_OK if successful + * @result NS_OK if the lookup succeeded. NS_COMFALSE + * if the lookup failed. */ - NS_IMETHOD GetClassID(const nsString& aName, nsIID& aCID) = 0; + NS_IMETHOD LookupName(const nsString& aName, + PRBool aIsConstructor, + nsIID& aCID) = 0; }; #endif /* nsIScriptNameSpaceManager_h__ */ diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index ef8d929a7f9..03193008e0a 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -63,11 +63,12 @@ nsJSContext::~nsJSContext() NS_IMPL_ISUPPORTS(nsJSContext, kIScriptContextIID); -PRBool nsJSContext::EvaluateString(const nsString& aScript, - const char *aURL, - PRUint32 aLineNo, - nsString& aRetValue, - PRBool* aIsUndefined) +NS_IMETHODIMP_(PRBool) +nsJSContext::EvaluateString(const nsString& aScript, + const char *aURL, + PRUint32 aLineNo, + nsString& aRetValue, + PRBool* aIsUndefined) { jsval val; @@ -92,7 +93,8 @@ PRBool nsJSContext::EvaluateString(const nsString& aScript, return ret; } -nsIScriptGlobalObject* nsJSContext::GetGlobalObject() +NS_IMETHODIMP_(nsIScriptGlobalObject*) +nsJSContext::GetGlobalObject() { JSObject *global = JS_GetGlobalObject(mContext); nsIScriptGlobalObject *script_global = nsnull; @@ -109,13 +111,15 @@ nsIScriptGlobalObject* nsJSContext::GetGlobalObject() } } -void* nsJSContext::GetNativeContext() +NS_IMETHODIMP_(void*) +nsJSContext::GetNativeContext() { return (void *)mContext; } -nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) +NS_IMETHODIMP +nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) { nsresult result = NS_ERROR_FAILURE; nsIScriptObjectOwner *owner; @@ -141,7 +145,8 @@ nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) return res; } -nsresult nsJSContext::InitClasses() +NS_IMETHODIMP +nsJSContext::InitClasses() { nsresult res = NS_ERROR_FAILURE; nsIScriptGlobalObject *global = GetGlobalObject(); @@ -163,7 +168,7 @@ nsresult nsJSContext::InitClasses() return res; } -nsresult +NS_IMETHODIMP nsJSContext::AddNamedReference(void *aSlot, void *aScriptObject, const char *aName) @@ -176,7 +181,7 @@ nsJSContext::AddNamedReference(void *aSlot, } } -nsresult +NS_IMETHODIMP nsJSContext::RemoveReference(void *aSlot, void *aScriptObject) { JSObject *obj = (JSObject *)aScriptObject; @@ -189,13 +194,19 @@ nsJSContext::RemoveReference(void *aSlot, void *aScriptObject) } } -nsresult +NS_IMETHODIMP nsJSContext::GC() { JS_GC(mContext); return NS_OK; } +NS_IMETHODIMP +nsJSContext::GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr) +{ + return NS_OK; +} + NS_IMETHODIMP nsJSContext::GetSecurityManager(nsIScriptSecurityManager** aInstancePtr) { diff --git a/mozilla/dom/src/base/nsJSEnvironment.h b/mozilla/dom/src/base/nsJSEnvironment.h index f93deaca986..c6bec9882b9 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.h +++ b/mozilla/dom/src/base/nsJSEnvironment.h @@ -33,19 +33,20 @@ public: NS_DECL_ISUPPORTS - virtual PRBool EvaluateString(const nsString& aScript, - const char *aURL, - PRUint32 aLineNo, - nsString& aRetValue, - PRBool* aIsUndefined); - virtual nsIScriptGlobalObject* GetGlobalObject(); - virtual void* GetNativeContext(); - virtual nsresult InitClasses(); - virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject); - virtual nsresult AddNamedReference(void *aSlot, void *aScriptObject, + NS_IMETHOD_(PRBool) EvaluateString(const nsString& aScript, + const char *aURL, + PRUint32 aLineNo, + nsString& aRetValue, + PRBool* aIsUndefined); + NS_IMETHOD_(nsIScriptGlobalObject*) GetGlobalObject(); + NS_IMETHOD_(void*) GetNativeContext(); + NS_IMETHOD InitClasses(); + NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject); + NS_IMETHOD AddNamedReference(void *aSlot, void *aScriptObject, const char *aName); - virtual nsresult RemoveReference(void *aSlot, void *aScriptObject); - virtual nsresult GC(); + NS_IMETHOD RemoveReference(void *aSlot, void *aScriptObject); + NS_IMETHOD GC(); + NS_IMETHOD GetNameSpaceManager(nsIScriptNameSpaceManager** aInstancePtr); NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr); }; diff --git a/mozilla/dom/src/base/nsScriptNameSpaceManager.cpp b/mozilla/dom/src/base/nsScriptNameSpaceManager.cpp new file mode 100644 index 00000000000..ef6af37c3df --- /dev/null +++ b/mozilla/dom/src/base/nsScriptNameSpaceManager.cpp @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsScriptNameSpaceManager.h" +#include "prmem.h" + +typedef struct { + nsIID mCID; + PRBool mIsConstructor; +} nsGlobalNameStruct; + +nsScriptNameSpaceManager::nsScriptNameSpaceManager() +{ + NS_INIT_REFCNT(); + mGlobalNames = nsnull; +} + +PRIntn +nsScriptNameSpaceManager::RemoveNames(PLHashEntry *he, PRIntn i, void *arg) +{ + char *name = (char*)he->key; + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)he->value; + + delete [] name; + PR_DELETE(gn); + + return HT_ENUMERATE_REMOVE; +} + +nsScriptNameSpaceManager::~nsScriptNameSpaceManager() +{ + if (nsnull != mGlobalNames) { + PL_HashTableEnumerateEntries(mGlobalNames, RemoveNames, nsnull); + PL_HashTableDestroy(mGlobalNames); + mGlobalNames = nsnull; + } +} + +static NS_DEFINE_IID(kIScriptNameSpaceManager, NS_ISCRIPTNAMESPACEMANAGER_IID); + +NS_IMPL_ISUPPORTS(nsScriptNameSpaceManager, kIScriptNameSpaceManager); + +NS_IMETHODIMP +nsScriptNameSpaceManager::RegisterGlobalName(const nsString& aName, + const nsIID& aCID, + PRBool aIsConstructor) +{ + if (nsnull == mGlobalNames) { + mGlobalNames = PL_NewHashTable(4, PL_HashString, PL_CompareStrings, + PL_CompareValues, nsnull, nsnull); + } + + char* name = aName.ToNewCString(); + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)PR_NEW(nsGlobalNameStruct); + if (nsnull == gn) { + return NS_ERROR_OUT_OF_MEMORY; + } + gn->mCID = aCID; + gn->mIsConstructor = aIsConstructor; + + PL_HashTableAdd(mGlobalNames, name, (void *)gn); + + return NS_OK; +} + +NS_IMETHODIMP +nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName) +{ + if (nsnull != mGlobalNames) { + char* name = aName.ToNewCString(); + PLHashNumber hn = PL_HashString(name); + PLHashEntry** hep = PL_HashTableRawLookup(mGlobalNames, + hn, + name); + PLHashEntry* entry = *hep; + + if (nsnull != entry) { + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)entry->value; + char* hname = (char*)entry->key;; + + delete gn; + PL_HashTableRemove(mGlobalNames, name); + delete [] hname; + } + + delete[] name; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsScriptNameSpaceManager::LookupName(const nsString& aName, + PRBool aIsConstructor, + nsIID& aCID) +{ + if (nsnull != mGlobalNames) { + char* name = aName.ToNewCString(); + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)PL_HashTableLookup(mGlobalNames, name); + delete [] name; + + if ((nsnull != gn) && (gn->mIsConstructor == aIsConstructor)) { + aCID = gn->mCID; + return NS_OK; + } + } + + return NS_COMFALSE; +} diff --git a/mozilla/dom/src/base/nsScriptNameSpaceManager.h b/mozilla/dom/src/base/nsScriptNameSpaceManager.h new file mode 100644 index 00000000000..44c49e977d7 --- /dev/null +++ b/mozilla/dom/src/base/nsScriptNameSpaceManager.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#ifndef nsScriptNameSetRegistry_h__ +#define nsScriptNameSetRegistry_h__ + +#include "nsIScriptNameSpaceManager.h" +#include "plhash.h" + +class nsScriptNameSpaceManager : public nsIScriptNameSpaceManager { + public: + nsScriptNameSpaceManager(); + virtual ~nsScriptNameSpaceManager(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD RegisterGlobalName(const nsString& aName, + const nsIID& aCID, + PRBool aIsConstructor); + NS_IMETHOD UnregisterGlobalName(const nsString& aName); + NS_IMETHOD LookupName(const nsString& aName, + PRBool aIsConstructor, + nsIID& aCID); + + protected: + static PRIntn RemoveNames(PLHashEntry *he, PRIntn i, void *arg); + + PLHashTable* mGlobalNames; +}; + +#endif /* nsScriptNameSetRegistry_h__ */ diff --git a/mozilla/dom/src/build/Makefile.in b/mozilla/dom/src/build/Makefile.in index f44da940e71..ae865c1abe4 100644 --- a/mozilla/dom/src/build/Makefile.in +++ b/mozilla/dom/src/build/Makefile.in @@ -32,7 +32,12 @@ MODULE=dom REQUIRES=xpcom raptor -CPPSRCS=nsDOMFactory.cpp nsHTMLTagsEnums.cpp +CPPSRCS=nsDOMFactory.cpp \ + nsHTMLTagsEnums.cpp \ + nsScriptNameSetRegistry.cpp \ + nsScriptNameSpaceManager.cpp \ + $(NULL) + INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/raptor \ -I$(PUBLIC)/dom -I$(PUBLIC)/js -I$(srcdir)/../base -I$(PUBLIC)/jsurl diff --git a/mozilla/dom/src/build/makefile.win b/mozilla/dom/src/build/makefile.win index 747b601b42a..8aee7b9a2b7 100644 --- a/mozilla/dom/src/build/makefile.win +++ b/mozilla/dom/src/build/makefile.win @@ -22,10 +22,15 @@ DEFINES=-D_IMPL_NS_DOM MODULE=raptor REQUIRES=xpcom raptor dom -CPPSRCS = nsDOMFactory.cpp \ - nsHTMLTagsEnums.cpp +CPPSRCS = nsDOMFactory.cpp \ + nsHTMLTagsEnums.cpp \ + nsScriptNameSetRegistry.cpp \ + nsScriptNameSpaceManager.cpp -CPP_OBJS = .\$(OBJDIR)\nsDOMFactory.obj .\$(OBJDIR)\nsHTMLTagsEnums.obj +CPP_OBJS = .\$(OBJDIR)\nsDOMFactory.obj \ + .\$(OBJDIR)\nsHTMLTagsEnums.obj \ + .\$(OBJDIR)\nsScriptNameSetRegistry.obj \ + .\$(OBJDIR)\nsScriptNameSpaceManager.obj LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ -I$(PUBLIC)\dom -I$(PUBLIC)\js -I..\base -I$(PUBLIC)\jsurl diff --git a/mozilla/dom/src/build/nsScriptNameSetRegistry.cpp b/mozilla/dom/src/build/nsScriptNameSetRegistry.cpp new file mode 100644 index 00000000000..9052584f362 --- /dev/null +++ b/mozilla/dom/src/build/nsScriptNameSetRegistry.cpp @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + + +#include "nsScriptNameSetRegistry.h" +#include "nsIScriptExternalNameSet.h" + +nsScriptNameSetRegistry::nsScriptNameSetRegistry() +{ + NS_INIT_REFCNT(); +} + +nsScriptNameSetRegistry::~nsScriptNameSetRegistry() +{ + PRInt32 i, count = mNameSets.Count(); + + for(i = 0; i < count; i++) { + nsIScriptExternalNameSet* ns = (nsIScriptExternalNameSet*)mNameSets.ElementAt(i); + + NS_RELEASE(ns); + } + mNameSets.Clear(); +} + +static NS_DEFINE_IID(kIScriptNameSetRegistry, NS_ISCRIPTNAMESETREGISTRY_IID); + +NS_IMPL_ISUPPORTS(nsScriptNameSetRegistry, kIScriptNameSetRegistry); + +NS_IMETHODIMP +nsScriptNameSetRegistry::AddExternalNameSet(nsIScriptExternalNameSet* aNameSet) +{ + if (-1 == mNameSets.IndexOf(aNameSet)) { + NS_ADDREF(aNameSet); + mNameSets.AppendElement(aNameSet); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsScriptNameSetRegistry::RemoveExternalNameSet(nsIScriptExternalNameSet* aNameSet) +{ + if (mNameSets.RemoveElement(aNameSet)) { + NS_RELEASE(aNameSet); + return NS_OK; + } + else { + return NS_ERROR_INVALID_ARG; + } +} diff --git a/mozilla/dom/src/build/nsScriptNameSetRegistry.h b/mozilla/dom/src/build/nsScriptNameSetRegistry.h new file mode 100644 index 00000000000..8f640dcdbfe --- /dev/null +++ b/mozilla/dom/src/build/nsScriptNameSetRegistry.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#ifndef nsScriptNameSetRegistry_h__ +#define nsScriptNameSetRegistry_h__ + +#include "nsIScriptNameSetRegistry.h" +#include "nsVoidArray.h" + +class nsScriptNameSetRegistry : public nsIScriptNameSetRegistry { + public: + nsScriptNameSetRegistry(); + virtual ~nsScriptNameSetRegistry(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD AddExternalNameSet(nsIScriptExternalNameSet* aNameSet); + NS_IMETHOD RemoveExternalNameSet(nsIScriptExternalNameSet* aNameSet); + + protected: + nsVoidArray mNameSets; +}; + +#endif /* nsScriptNameSetRegistry_h__ */ diff --git a/mozilla/dom/src/build/nsScriptNameSpaceManager.cpp b/mozilla/dom/src/build/nsScriptNameSpaceManager.cpp new file mode 100644 index 00000000000..ef6af37c3df --- /dev/null +++ b/mozilla/dom/src/build/nsScriptNameSpaceManager.cpp @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsScriptNameSpaceManager.h" +#include "prmem.h" + +typedef struct { + nsIID mCID; + PRBool mIsConstructor; +} nsGlobalNameStruct; + +nsScriptNameSpaceManager::nsScriptNameSpaceManager() +{ + NS_INIT_REFCNT(); + mGlobalNames = nsnull; +} + +PRIntn +nsScriptNameSpaceManager::RemoveNames(PLHashEntry *he, PRIntn i, void *arg) +{ + char *name = (char*)he->key; + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)he->value; + + delete [] name; + PR_DELETE(gn); + + return HT_ENUMERATE_REMOVE; +} + +nsScriptNameSpaceManager::~nsScriptNameSpaceManager() +{ + if (nsnull != mGlobalNames) { + PL_HashTableEnumerateEntries(mGlobalNames, RemoveNames, nsnull); + PL_HashTableDestroy(mGlobalNames); + mGlobalNames = nsnull; + } +} + +static NS_DEFINE_IID(kIScriptNameSpaceManager, NS_ISCRIPTNAMESPACEMANAGER_IID); + +NS_IMPL_ISUPPORTS(nsScriptNameSpaceManager, kIScriptNameSpaceManager); + +NS_IMETHODIMP +nsScriptNameSpaceManager::RegisterGlobalName(const nsString& aName, + const nsIID& aCID, + PRBool aIsConstructor) +{ + if (nsnull == mGlobalNames) { + mGlobalNames = PL_NewHashTable(4, PL_HashString, PL_CompareStrings, + PL_CompareValues, nsnull, nsnull); + } + + char* name = aName.ToNewCString(); + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)PR_NEW(nsGlobalNameStruct); + if (nsnull == gn) { + return NS_ERROR_OUT_OF_MEMORY; + } + gn->mCID = aCID; + gn->mIsConstructor = aIsConstructor; + + PL_HashTableAdd(mGlobalNames, name, (void *)gn); + + return NS_OK; +} + +NS_IMETHODIMP +nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName) +{ + if (nsnull != mGlobalNames) { + char* name = aName.ToNewCString(); + PLHashNumber hn = PL_HashString(name); + PLHashEntry** hep = PL_HashTableRawLookup(mGlobalNames, + hn, + name); + PLHashEntry* entry = *hep; + + if (nsnull != entry) { + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)entry->value; + char* hname = (char*)entry->key;; + + delete gn; + PL_HashTableRemove(mGlobalNames, name); + delete [] hname; + } + + delete[] name; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsScriptNameSpaceManager::LookupName(const nsString& aName, + PRBool aIsConstructor, + nsIID& aCID) +{ + if (nsnull != mGlobalNames) { + char* name = aName.ToNewCString(); + nsGlobalNameStruct* gn = (nsGlobalNameStruct*)PL_HashTableLookup(mGlobalNames, name); + delete [] name; + + if ((nsnull != gn) && (gn->mIsConstructor == aIsConstructor)) { + aCID = gn->mCID; + return NS_OK; + } + } + + return NS_COMFALSE; +} diff --git a/mozilla/dom/src/build/nsScriptNameSpaceManager.h b/mozilla/dom/src/build/nsScriptNameSpaceManager.h new file mode 100644 index 00000000000..44c49e977d7 --- /dev/null +++ b/mozilla/dom/src/build/nsScriptNameSpaceManager.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#ifndef nsScriptNameSetRegistry_h__ +#define nsScriptNameSetRegistry_h__ + +#include "nsIScriptNameSpaceManager.h" +#include "plhash.h" + +class nsScriptNameSpaceManager : public nsIScriptNameSpaceManager { + public: + nsScriptNameSpaceManager(); + virtual ~nsScriptNameSpaceManager(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD RegisterGlobalName(const nsString& aName, + const nsIID& aCID, + PRBool aIsConstructor); + NS_IMETHOD UnregisterGlobalName(const nsString& aName); + NS_IMETHOD LookupName(const nsString& aName, + PRBool aIsConstructor, + nsIID& aCID); + + protected: + static PRIntn RemoveNames(PLHashEntry *he, PRIntn i, void *arg); + + PLHashTable* mGlobalNames; +}; + +#endif /* nsScriptNameSetRegistry_h__ */