зеркало из https://github.com/mozilla/pjs.git
Ongoing work on mechanism for introducing global names into a script namespace
This commit is contained in:
Родитель
f2853da8d6
Коммит
e30512c816
|
@ -25,4 +25,7 @@ nsIScriptEventListener.h
|
|||
nsIDOMScriptObjectFactory.h
|
||||
nsIDOMNativeObjectRegistry.h
|
||||
nsDOMCID.h
|
||||
nsIScriptSecurityManager.h
|
||||
nsIScriptSecurityManager.h
|
||||
nsIScriptNameSetRegistry.h
|
||||
nsIScriptExternalNameSet.h
|
||||
nsIScriptNameSpaceManager.h
|
||||
|
|
|
@ -37,6 +37,9 @@ EXPORTS = \
|
|||
nsIDOMNativeObjectRegistry.h \
|
||||
nsDOMCID.h \
|
||||
nsIScriptSecurityManager.h \
|
||||
nsIScriptNameSetRegistry.h \
|
||||
nsIScriptExternalNameSet.h \
|
||||
nsIScriptNameSpaceManager.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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__ */
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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__ */
|
|
@ -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;
|
||||
}
|
|
@ -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__ */
|
Загрузка…
Ссылка в новой задаче