From 140a853e4f8fa4ee123bbcfd3d5c6490ae146923 Mon Sep 17 00:00:00 2001 From: vidur Date: Tue, 23 Jun 1998 18:43:06 +0000 Subject: [PATCH] Added autogeneration of XPCOM headers and JavaScript stub classes. Added better masking of JS-specific structures in generic interfaces. Creation of a scripting global object interface. git-svn-id: svn://10.0.0.236/trunk@4313 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 16 +- mozilla/content/base/src/nsDocument.h | 7 +- mozilla/dom/public/Makefile | 6 +- mozilla/dom/public/coreDom/Makefile | 22 +- mozilla/dom/public/coreDom/makefile.win | 7 +- mozilla/dom/public/coreDom/nsIDOMAttribute.h | 141 +-- .../dom/public/coreDom/nsIDOMAttributeList.h | 52 + mozilla/dom/public/coreDom/nsIDOMComment.h | 23 +- mozilla/dom/public/coreDom/nsIDOMDOM.h | 46 + mozilla/dom/public/coreDom/nsIDOMDocument.h | 245 +---- .../public/coreDom/nsIDOMDocumentContext.h | 45 + .../public/coreDom/nsIDOMDocumentFragment.h | 46 + mozilla/dom/public/coreDom/nsIDOMElement.h | 114 +- mozilla/dom/public/coreDom/nsIDOMNode.h | 145 +-- .../dom/public/coreDom/nsIDOMNodeIterator.h | 56 + mozilla/dom/public/coreDom/nsIDOMPI.h | 27 +- mozilla/dom/public/coreDom/nsIDOMText.h | 100 +- .../dom/public/coreDom/nsIDOMTreeIterator.h | 61 ++ mozilla/dom/public/idl/Attribute.idl | 2 +- mozilla/dom/public/idl/AttributeList.idl | 2 +- mozilla/dom/public/idl/Document.idl | 2 +- mozilla/dom/public/idl/Element.idl | 8 +- mozilla/dom/public/idl/Node.idl | 6 +- mozilla/dom/public/idl/NodeIterator.idl | 12 +- mozilla/dom/public/idl/Window.idl | 4 + mozilla/dom/public/idl/makefile.win | 6 +- mozilla/dom/public/makefile.win | 3 +- mozilla/dom/public/nsIDOMWindow.h | 44 + mozilla/dom/public/nsIJSScriptObject.h | 50 + mozilla/dom/public/nsIScriptContext.h | 21 +- mozilla/dom/public/nsIScriptGlobalObject.h | 45 + mozilla/dom/public/nsIScriptObjectOwner.h | 36 +- mozilla/dom/src/Makefile | 2 + mozilla/dom/src/makefile.win | 11 +- mozilla/dom/src/nsGlobalWindow.cpp | 213 ++++ mozilla/dom/src/nsJSAttribute.cpp | 380 ++++--- mozilla/dom/src/nsJSAttributeList.cpp | 667 +++++++----- mozilla/dom/src/nsJSComment.cpp | 337 ++++++ mozilla/dom/src/nsJSDOM.cpp | 405 +++++++ mozilla/dom/src/nsJSDocument.cpp | 996 ++++++++++++++---- mozilla/dom/src/nsJSDocumentContext.cpp | 357 +++++++ mozilla/dom/src/nsJSDocumentFragment.cpp | 360 +++++++ mozilla/dom/src/nsJSElement.cpp | 920 ++++++++++------ mozilla/dom/src/nsJSEnvironment.cpp | 113 +- mozilla/dom/src/nsJSEnvironment.h | 14 +- mozilla/dom/src/nsJSNode.cpp | 994 ++++++++++------- mozilla/dom/src/nsJSNodeIterator.cpp | 731 ++++++++----- mozilla/dom/src/nsJSPI.cpp | 367 +++++++ mozilla/dom/src/nsJSText.cpp | 688 ++++++++---- mozilla/dom/src/nsJSTreeIterator.cpp | 708 +++++++++++++ mozilla/dom/src/nsJSWindow.cpp | 259 +++-- mozilla/dom/tests/js/DumpHTML.js | Bin 2025 -> 2083 bytes mozilla/dom/tools/IdlVariable.cpp | 5 + mozilla/dom/tools/JSStubGen.cpp | 169 ++- mozilla/dom/tools/Makefile.win | 1 + mozilla/dom/tools/XPCOMGen.cpp | 46 +- mozilla/dom/tools/XPCOMGen.h | 1 + mozilla/dom/tools/geniid.pl | 3 +- mozilla/layout/base/src/nsDocument.cpp | 16 +- mozilla/layout/base/src/nsDocument.h | 7 +- mozilla/layout/html/base/src/Makefile | 2 +- mozilla/layout/html/base/src/makefile.win | 4 +- .../layout/html/base/src/nsDOMAttributes.cpp | 10 +- .../layout/html/base/src/nsDOMAttributes.h | 7 +- .../layout/html/base/src/nsDOMIterator.cpp | 33 +- mozilla/layout/html/base/src/nsDOMIterator.h | 4 +- .../layout/html/base/src/nsHTMLContainer.cpp | 13 +- .../layout/html/base/src/nsHTMLContainer.h | 2 +- .../layout/html/base/src/nsHTMLContent.cpp | 16 +- mozilla/layout/html/base/src/nsHTMLContent.h | 2 +- .../layout/html/base/src/nsHTMLTagContent.cpp | 28 +- .../layout/html/base/src/nsHTMLTagContent.h | 4 +- mozilla/layout/html/base/src/nsRootPart.cpp | 14 + .../layout/html/base/src/nsTextContent.cpp | 36 +- mozilla/layout/html/document/src/Makefile | 2 +- mozilla/layout/html/document/src/makefile.win | 2 +- mozilla/layout/html/forms/src/Makefile | 2 +- mozilla/layout/html/forms/src/makefile.win | 4 +- mozilla/layout/html/style/src/Makefile | 2 +- mozilla/layout/html/style/src/makefile.win | 4 +- mozilla/layout/html/table/src/Makefile | 2 +- mozilla/layout/html/table/src/makefile.win | 4 +- mozilla/layout/html/tests/Makefile | 3 +- mozilla/layout/html/tests/makefile.win | 2 +- 84 files changed, 7652 insertions(+), 2720 deletions(-) create mode 100644 mozilla/dom/public/coreDom/nsIDOMAttributeList.h create mode 100644 mozilla/dom/public/coreDom/nsIDOMDOM.h create mode 100644 mozilla/dom/public/coreDom/nsIDOMDocumentContext.h create mode 100644 mozilla/dom/public/coreDom/nsIDOMDocumentFragment.h create mode 100644 mozilla/dom/public/coreDom/nsIDOMNodeIterator.h create mode 100644 mozilla/dom/public/coreDom/nsIDOMTreeIterator.h create mode 100644 mozilla/dom/public/idl/Window.idl create mode 100644 mozilla/dom/public/nsIDOMWindow.h create mode 100644 mozilla/dom/public/nsIJSScriptObject.h create mode 100644 mozilla/dom/public/nsIScriptGlobalObject.h create mode 100644 mozilla/dom/src/nsGlobalWindow.cpp create mode 100644 mozilla/dom/src/nsJSComment.cpp create mode 100644 mozilla/dom/src/nsJSDOM.cpp create mode 100644 mozilla/dom/src/nsJSDocumentContext.cpp create mode 100644 mozilla/dom/src/nsJSDocumentFragment.cpp create mode 100644 mozilla/dom/src/nsJSPI.cpp create mode 100644 mozilla/dom/src/nsJSTreeIterator.cpp diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 03a2adbd9a0..bcaebfc7148 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -25,6 +25,7 @@ #include "nsIPresShell.h" #include "nsIDocumentObserver.h" #include "nsEventListenerManager.h" +#include "nsIScriptGlobalObject.h" #include "nsSelection.h" #include "nsIDOMText.h" @@ -436,15 +437,17 @@ void nsDocument::ContentHasBeenRemoved(nsIContent* aContainer, } } -nsresult nsDocument::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; + nsIScriptGlobalObject *global = aContext->GetGlobalObject(); if (nsnull == mScriptObject) { - res = NS_NewScriptDocument(aContext, this, nsnull, (JSObject**)&mScriptObject); + res = NS_NewScriptDocument(aContext, this, global, (void**)&mScriptObject); } *aScriptObject = mScriptObject; + NS_RELEASE(global); return res; } @@ -474,14 +477,15 @@ nsresult nsDocument::GetChildNodes(nsIDOMNodeIterator **aIterator) return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsDocument::HasChildNodes() +nsresult nsDocument::HasChildNodes(PRBool *aReturn) { if (nsnull != mRootContent) { - return NS_OK; + *aReturn = PR_TRUE; } else { - return NS_ERROR_FAILURE; + *aReturn = PR_FALSE; } + return NS_OK; } nsresult nsDocument::GetFirstChild(nsIDOMNode **aNode) @@ -664,7 +668,7 @@ nsresult nsDocument::CreateAttributeList(nsIDOMAttributeList **aAttributesList) return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsDocument::CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator) +nsresult nsDocument::CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator) { //XXX TBI return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 48590dfa9ff..4602cece179 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -22,6 +22,7 @@ #include "nsVoidArray.h" #include "nsIDOMDocument.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptContext.h" #include "nsIDOMEventCapturer.h" class nsISelection; @@ -161,14 +162,14 @@ public: public: - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD ResetScriptObject(); // nsIDOMDocument interface NS_IMETHOD GetNodeType(PRInt32 *aType); NS_IMETHOD GetParentNode(nsIDOMNode **aNode); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode); NS_IMETHOD GetNextSibling(nsIDOMNode **aNode); @@ -194,7 +195,7 @@ public: nsIDOMNode *value, nsIDOMAttribute **aAttribute); NS_IMETHOD CreateAttributeList(nsIDOMAttributeList **aAttributesList); - NS_IMETHOD CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator); + NS_IMETHOD CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator); NS_IMETHOD GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator); // nsIDOMEventCapturer interface diff --git a/mozilla/dom/public/Makefile b/mozilla/dom/public/Makefile index 4c82bcbdc3b..20e5ad6e735 100644 --- a/mozilla/dom/public/Makefile +++ b/mozilla/dom/public/Makefile @@ -23,9 +23,11 @@ DEFINES = -D_IMPL_NS_DOM EXPORTS = \ nsIScriptContext.h \ - nsIScriptObject.h \ + nsIJSScriptObject.h \ nsIScriptObjectOwner.h \ - $(NULL) + nsIScriptGlobalObject.h \ + nsIDOMWindow.h \ + $(NULL) MODULE = dom diff --git a/mozilla/dom/public/coreDom/Makefile b/mozilla/dom/public/coreDom/Makefile index 60576682b39..f477fadb630 100644 --- a/mozilla/dom/public/coreDom/Makefile +++ b/mozilla/dom/public/coreDom/Makefile @@ -20,15 +20,19 @@ DEPTH=../../.. DEFINES = -D_IMPL_NS_DOM EXPORTS = \ - nsDOM.h \ - nsIDOMAttribute.h \ - nsIDOMComment.h \ - nsIDOMDocument.h \ - nsIDOMElement.h \ - nsIDOMIterators.h \ - nsIDOMNode.h \ - nsIDOMPI.h \ - nsIDOMText.h \ + nsIDOMAttribute.h \ + nsIDOMAttributeList.h \ + nsIDOMComment.h \ + nsIDOMDOM.h \ + nsIDOMDocument.h \ + nsIDOMDocumentContext.h \ + nsIDOMDocumentFragment.h \ + nsIDOMElement.h \ + nsIDOMNode.h \ + nsIDOMNodeIterator.h \ + nsIDOMPI.h \ + nsIDOMText.h \ + nsIDOMTreeIterator.h $(NULL) MODULE = dom diff --git a/mozilla/dom/public/coreDom/makefile.win b/mozilla/dom/public/coreDom/makefile.win index 3c57bcd179a..af07c493c28 100644 --- a/mozilla/dom/public/coreDom/makefile.win +++ b/mozilla/dom/public/coreDom/makefile.win @@ -19,9 +19,10 @@ DEPTH=..\..\.. IGNORE_MANIFEST=1 DEFINES=-D_IMPL_NS_DOM -EXPORTS=nsDOM.h nsIDOMAttribute.h nsIDOMComment.h nsIDOMDocument.h \ - nsIDOMElement.h nsIDOMIterators.h nsIDOMNode.h nsIDOMPI.h \ - nsIDOMText.h +EXPORTS=nsIDOMAttribute.h nsIDOMAttributeList.h nsIDOMComment.h \ + nsIDOMDOM.h nsIDOMDocument.h nsIDOMDocumentContext.h \ + nsIDOMDocumentFragment.h nsIDOMElement.h nsIDOMNode.h \ + nsIDOMNodeIterator.h nsIDOMPI.h nsIDOMText.h nsIDOMTreeIterator.h MODULE=dom include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/dom/public/coreDom/nsIDOMAttribute.h b/mozilla/dom/public/coreDom/nsIDOMAttribute.h index 9d7a3def530..e402fdc8af9 100644 --- a/mozilla/dom/public/coreDom/nsIDOMAttribute.h +++ b/mozilla/dom/public/coreDom/nsIDOMAttribute.h @@ -15,150 +15,37 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMAttribute_h__ #define nsIDOMAttribute_h__ -#include "nsDOM.h" #include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" -// forward declaration -class nsIDOMNode; +class nsIDOMAttribute; #define NS_IDOMATTRIBUTE_IID \ -{ /* 8f6bca77-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca77, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } +{ 0x6f7652e0, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } -/** - * The Attribute object represents an attribute in an Element object. Typically the - * allowable values for the attribute are defined in a document type definition. - *

- * The attribute's effective value is determined as follows: if this attribute has - * been explicitly assigned any value, that value is the attribute's effective value; - * otherwise, if there is a declaration for this attribute, and that declaration - * includes a default value, then that default value is the attribute's effective value; - * otherwise, the attribute has no effective value.) Note, in particular, that an - * effective value of the null string would be returned as a Text node instance whose - * toString method will return a zero length string (as will toString invoked directly - * on this Attribute instance). If the attribute has no effective value, then this - * method will return null. Note the toString method on the Attribute instance can - * also be used to retrieve the string version of the attribute's value(s). - */ class nsIDOMAttribute : public nsISupports { public: - /** - * Return the name of this attribute. - * - * @param aName [out] The attribute name - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetName(nsString &aName) = 0; - /** - * Return the value of this attribute. - * - * @param aName [out] The attribute value - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetValue(nsString &aName) = 0; + NS_IMETHOD GetValue(nsString& aValue)=0; + NS_IMETHOD SetValue(nsString& aValue)=0; - /** - * Set the value of this attribute. - * - * @param aName [in] The attribute value - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetValue(nsString &aName) = 0; + NS_IMETHOD GetSpecified(PRBool* aSpecified)=0; + NS_IMETHOD SetSpecified(PRBool aSpecified)=0; - /** - * If this attribute was explicitly given a value in the original document, - * this will be true; otherwise, it will be false. - * - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetSpecified() = 0; + NS_IMETHOD GetName(nsString& aReturn)=0; - /** - * Set the specified value - * - * @param specified [in] The specified value - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetSpecified(PRBool specified) = 0; - - /** - * Returns the attribute as a string. Character and general entity - * references will have been replaced with their values in the returned string. - * - * @param aString [out] The attribute as a string - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD ToString(nsString &aString) = 0; + NS_IMETHOD ToString(nsString& aReturn)=0; }; -#define NS_IDOMATTRIBUTELIST_IID \ -{ /* 8f6bca78-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca78, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } - -/** - * AttributeList objects are used to represent collections of Attribute objects - * which can be accessed by name. The Attribute objects contained in a AttributeList - * may also be accessed by ordinal index. In most cases, AttributeList objects are - * created from Element objects. - */ -class nsIDOMAttributeList : public nsISupports { -public: - /** - * Retrieve an Attribute instance from the list by its name. If it's not present, - * null is returned. - * - * @param aAttrName [in] The name of atrribute - * @param aAttribute [out] The returned attribute - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetAttribute(nsString &aAttrName, nsIDOMAttribute** aAttribute) = 0; - - /** - * Add a new attribute to the end of the list and associate it with the given name. - * If the name already exists, the previous Attribute object is replaced, and returned. - * If no object of the same name exists, null is returned, and the named Attribute - * is added to the end of the AttributeList object; that is, it is accessible via - * the item method using the index one less than the value returned by getLength. - * - * @param aAttribute [in] The attribute to set - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetAttribute(nsIDOMAttribute *attr) = 0; - - /** - * Removes the Attribute instance named name from the list and returns it. - * - * @param aAttrName [in] The name of atrribute - * @param aAttribute [out] The removed attribute - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Remove(nsString &attrName, nsIDOMAttribute** aAttribute) = 0; - - /** - * Returns the (zero-based) indexth Attribute item in the collection. - * - * @param aIndex [in] The index in the list of attributes - * @param aAttribute [out] The attribute at that index - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute) = 0; - - /** - * Returns the number of Attributes in the AttributeList instance. - * - * @param aLength [out] The attribute list length - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetLength(PRUint32 *aLength) = 0; -}; +extern nsresult NS_InitAttributeClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn); #endif // nsIDOMAttribute_h__ - diff --git a/mozilla/dom/public/coreDom/nsIDOMAttributeList.h b/mozilla/dom/public/coreDom/nsIDOMAttributeList.h new file mode 100644 index 00000000000..90c4d252fc1 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMAttributeList.h @@ -0,0 +1,52 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMAttributeList_h__ +#define nsIDOMAttributeList_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMAttributeList; +class nsIDOMAttribute; + +#define NS_IDOMATTRIBUTELIST_IID \ +{ 0x6f7652e1, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMAttributeList : public nsISupports { +public: + + NS_IMETHOD GetAttribute(nsString& aAttrName, nsIDOMAttribute** aReturn)=0; + + NS_IMETHOD SetAttribute(nsIDOMAttribute* aAttr)=0; + + NS_IMETHOD Remove(nsString& aAttrName, nsIDOMAttribute** aReturn)=0; + + NS_IMETHOD Item(PRUint32 aIndex, nsIDOMAttribute** aReturn)=0; + + NS_IMETHOD GetLength(PRUint32* aReturn)=0; +}; + +extern nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptAttributeList(nsIScriptContext *aContext, nsIDOMAttributeList *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMAttributeList_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMComment.h b/mozilla/dom/public/coreDom/nsIDOMComment.h index 7edc57703b3..fa31976b182 100644 --- a/mozilla/dom/public/coreDom/nsIDOMComment.h +++ b/mozilla/dom/public/coreDom/nsIDOMComment.h @@ -15,24 +15,31 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMComment_h__ #define nsIDOMComment_h__ -#include "nsDOM.h" +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" #include "nsIDOMNode.h" +class nsIDOMComment; + #define NS_IDOMCOMMENT_IID \ -{ /* 8f6bca7a-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca7a, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } +{ 0x6f7652e2, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } class nsIDOMComment : public nsIDOMNode { public: - //attribute UniString data; - NS_IMETHOD GetData(nsString &aData) = 0; - NS_IMETHOD SetData(nsString &aData) = 0; + + NS_IMETHOD GetData(nsString& aData)=0; + NS_IMETHOD SetData(nsString& aData)=0; }; -#endif // nsIDOMComment_h__ +extern nsresult NS_InitCommentClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMComment_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMDOM.h b/mozilla/dom/public/coreDom/nsIDOMDOM.h new file mode 100644 index 00000000000..209c29b307e --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMDOM.h @@ -0,0 +1,46 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMDOM_h__ +#define nsIDOMDOM_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMDocument; +class nsIDOMDOM; + +#define NS_IDOMDOM_IID \ +{ 0x6f7652e6, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMDOM : public nsISupports { +public: + + NS_IMETHOD CreateDocument(nsString& aType, nsIDOMDocument** aReturn)=0; + + NS_IMETHOD HasFeature(nsString& aFeature, PRBool* aReturn)=0; +}; + +extern nsresult NS_InitDOMClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMDOM_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMDocument.h b/mozilla/dom/public/coreDom/nsIDOMDocument.h index 8ab0ceeb3b1..fb634bf8021 100644 --- a/mozilla/dom/public/coreDom/nsIDOMDocument.h +++ b/mozilla/dom/public/coreDom/nsIDOMDocument.h @@ -15,242 +15,65 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMDocument_h__ #define nsIDOMDocument_h__ -#include "nsDOM.h" #include "nsISupports.h" -#include "nsIDOMNode.h" +#include "nsString.h" +#include "nsIScriptContext.h" +#include "nsIDOMDocumentFragment.h" -// forward declaration -class nsIDOMDocument; -class nsIDOMElement; -class nsIDOMText; -class nsIDOMComment; -class nsIDOMPI; -class nsIDOMAttribute; class nsIDOMAttributeList; +class nsIDOMElement; +class nsIDOMPI; class nsIDOMNodeIterator; +class nsIDOMDocument; class nsIDOMTreeIterator; - -#define NS_IDOMDOCUMENTCONTEXT_IID \ -{ /* 8f6bca71-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca71, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } - -/** - * The DocumentContext object represents information that is not strictly related - * to a document's content; rather, it provides the information about where the - * document came from, and any additional meta-data about the document - */ -class nsIDOMDocumentContext : public nsISupports { -public: - /** - * Return the root node of a Document Object Model. - * - * @param aDocument [out] The root node of a Document Object Model - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetDocument(nsIDOMDocument **aDocument) = 0; - - /** - * Set the root node of a Document Object Model. - * - * @param aDocument [in] The root node of a Document Object Model - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetDocument(nsIDOMDocument *aDocument) = 0; -}; - -#define NS_IDOMDOCUMENTFRAGMENT_IID \ -{ /* 8f6bca72-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca72, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } - -/** - * DocumentFragment is the "lightweight" or "minimal" document object, or the - * handle for a "fragment" as returned by the Range operations, and it - * (as the superclass of Document) anchors the XML/HTML tree in a full-fledged document - */ -class nsIDOMDocumentFragment : public nsIDOMNode { -public: - /** - * Return the Document object associated with this DocumentFragment - * - * @param aDocument [out] The main Document - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetMasterDoc(nsIDOMDocument **aDocument) = 0; - - /** - * Set the Document object associated with this DocumentFragment - * - * @param aDocument [in] The main Document - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetMasterDoc(nsIDOMDocument *aDocument) = 0; -}; +class nsIDOMAttribute; +class nsIDOMNode; +class nsIDOMText; +class nsIDOMDocumentContext; +class nsIDOMComment; #define NS_IDOMDOCUMENT_IID \ -{ /* 8f6bca73-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca73, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } +{ 0x6f7652e3, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } -/** - * The Document object represents the entire HTML or XML document. Conceptually, - * it is the root of the document tree, and provides the primary access to the - * document's data. Since Document inherits from DocumentFragment, its children are - * contents of the Document, e.g., the root Element, the XML prolog, any processing - * instructions and or comments, etc. - *

Since Elements, Text nodes, Comments, PIs, etc. cannot exist outside a Document, - * the Document interface also anchors the "factory" methods that create these objects. - */ class nsIDOMDocument : public nsIDOMDocumentFragment { -public: - /** - * For XML, this provides access to the Document Type Definition (see DocumentType) - * associated with this XML document. For HTML documents and XML documents without - * a document type definition this returns the value null. - * - * @param aDocType [out] The document type - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetDocumentType(nsIDOMNode **aDocType) = 0; +public: - /** - * For XML, this sets the Document Type Definition (see DocumentType) - * associated with this XML document. For HTML documents and XML documents without - * a document type definition this is a noop. - * - * @param aDocType [in] The document type - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetDocumentType(nsIDOMNode *aNode) = 0; - - /** - * This is a "convenience" function to jump directly to the child node - * that is the root element of the document - * - * @param aElement [out] The root element - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetDocumentElement(nsIDOMElement **aElement) = 0; + NS_IMETHOD GetDocumentType(nsIDOMNode** aDocumentType)=0; + NS_IMETHOD SetDocumentType(nsIDOMNode* aDocumentType)=0; - /** - * This is a "convenience" function to set the child node - * that is the root element of the document - * - * @param aElement [out] The root element - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetDocumentElement(nsIDOMElement *aElement) = 0; + NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement)=0; + NS_IMETHOD SetDocumentElement(nsIDOMElement* aDocumentElement)=0; - /** - * Return the DocumentContext - * - * @param aContext [out] The DocumentContext - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetDocumentContext(nsIDOMDocumentContext **aDocContext) = 0; + NS_IMETHOD GetDocumentContext(nsIDOMDocumentContext** aDocumentContext)=0; + NS_IMETHOD SetDocumentContext(nsIDOMDocumentContext* aDocumentContext)=0; - /** - * Set the DocumentContext - * - * @param aContext [in] The DocumentContext - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetDocumentContext(nsIDOMDocumentContext *aContext) = 0; + NS_IMETHOD CreateDocumentContext(nsIDOMDocumentContext** aReturn)=0; - /** - * Create and return a new DocumentContext. - * - * @param aDocContext [out] The new context - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateDocumentContext(nsIDOMDocumentContext **aDocContext) = 0; + NS_IMETHOD CreateElement(nsString& aTagName, nsIDOMAttributeList* aAttributes, nsIDOMElement** aReturn)=0; - /** - * Create an element based on the tagName. Note that the instance returned may - * implement an interface derived from Element. The attributes parameter can be - * null if no attributes are specified for the new Element - * - * @param aTagName [in] The name of the element type to instantiate - * @param aAttributes [in] The set of attributes for the element - * @param aElement [out] The new element - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateElement(nsString &aTagName, - nsIDOMAttributeList *aAttributes, - nsIDOMElement **aElement) = 0; + NS_IMETHOD CreateTextNode(nsString& aData, nsIDOMText** aReturn)=0; - /** - * Create and return a new Text node. - * - * @param aData [in] The data for the node - * @param aTextNode [out] The new text node - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateTextNode(nsString &aData, nsIDOMText** aTextNode) = 0; + NS_IMETHOD CreateComment(nsString& aData, nsIDOMComment** aReturn)=0; - /** - * Create a Comment node given the specified string - * - * @param aData [in] The data for the node - * @param aComment [out] The new Comment object. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateComment(nsString &aData, nsIDOMComment **aComment) = 0; + NS_IMETHOD CreatePI(nsString& aName, nsString& aData, nsIDOMPI** aReturn)=0; - /** - * Create a PI node given the specified name and data strings. - * - * @param aName [in] The name part of the PI. - * @param aData [in] The data for the node. - * @param aPI [out] The new PI object - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI) = 0; + NS_IMETHOD CreateAttribute(nsString& aName, nsIDOMNode* aValue, nsIDOMAttribute** aReturn)=0; - /** - * Create an Attribute of the given name and specified value. Note that the - * Attribute instance can then be set on an Element using the setAttribute method - * - * @param aName [in] The name of the attribute - * @param value [in] The value of the attribute. - * @param aAttribute [out] A new Attribute object. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateAttribute(nsString &aName, - nsIDOMNode *value, - nsIDOMAttribute **aAttribute) = 0; - - /** - * Create an empty AttributeList - * - * @param aAttributesList [out] The new AttributeList - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateAttributeList(nsIDOMAttributeList **aAttributesList) = 0; + NS_IMETHOD CreateAttributeList(nsIDOMAttributeList** aReturn)=0; - /** - * Create a TreeIterator anchored on a given node. - * - * @param aNode [in] The "root" node of this tree iterator. - * @param aTreeIterator [out] A new TreeIterator object. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator) = 0; + NS_IMETHOD CreateTreeIterator(nsIDOMNode* aNode, nsIDOMTreeIterator** aReturn)=0; - /** - * Returns an iterator through all subordinate Elements with a given tag name. - * - * @param aTagname [in] The name of the tag to match on - * @param aIterator [out] A new NodeIterator object. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator) = 0; + NS_IMETHOD GetElementsByTagName(nsString& aTagname, nsIDOMNodeIterator** aReturn)=0; }; -#endif // nsIDOMDocument_h__ +extern nsresult NS_InitDocumentClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMDocument_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMDocumentContext.h b/mozilla/dom/public/coreDom/nsIDOMDocumentContext.h new file mode 100644 index 00000000000..2e90453f012 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMDocumentContext.h @@ -0,0 +1,45 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMDocumentContext_h__ +#define nsIDOMDocumentContext_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMDocument; +class nsIDOMDocumentContext; + +#define NS_IDOMDOCUMENTCONTEXT_IID \ +{ 0x6f7652e4, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMDocumentContext : public nsISupports { +public: + + NS_IMETHOD GetDocument(nsIDOMDocument** aDocument)=0; + NS_IMETHOD SetDocument(nsIDOMDocument* aDocument)=0; +}; + +extern nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptDocumentContext(nsIScriptContext *aContext, nsIDOMDocumentContext *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMDocumentContext_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMDocumentFragment.h b/mozilla/dom/public/coreDom/nsIDOMDocumentFragment.h new file mode 100644 index 00000000000..14c36d9dad6 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMDocumentFragment.h @@ -0,0 +1,46 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMDocumentFragment_h__ +#define nsIDOMDocumentFragment_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" +#include "nsIDOMNode.h" + +class nsIDOMDocument; +class nsIDOMDocumentFragment; + +#define NS_IDOMDOCUMENTFRAGMENT_IID \ +{ 0x6f7652e5, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMDocumentFragment : public nsIDOMNode { +public: + + NS_IMETHOD GetMasterDoc(nsIDOMDocument** aMasterDoc)=0; + NS_IMETHOD SetMasterDoc(nsIDOMDocument* aMasterDoc)=0; +}; + +extern nsresult NS_InitDocumentFragmentClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMDocumentFragment_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMElement.h b/mozilla/dom/public/coreDom/nsIDOMElement.h index 4f30cca0d54..b42a62618a5 100644 --- a/mozilla/dom/public/coreDom/nsIDOMElement.h +++ b/mozilla/dom/public/coreDom/nsIDOMElement.h @@ -15,119 +15,51 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMElement_h__ #define nsIDOMElement_h__ -#include "nsDOM.h" +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" #include "nsIDOMNode.h" -// forward declaration -class nsIDOMAttribute; class nsIDOMAttributeList; +class nsIDOMElement; class nsIDOMNodeIterator; +class nsIDOMAttribute; #define NS_IDOMELEMENT_IID \ -{ /* 8f6bca79-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca79, 0xce42, 0x11d1, \ - {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } +{ 0x6f7652e7, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } -/** - * By far the vast majority (apart from text) of node types that authors will generally - * encounter when traversing a document will be Element nodes. These objects represent - * both the element itself, as well as any contained nodes. - */ class nsIDOMElement : public nsIDOMNode { public: - /** - * This method returns the string that is the element's name - * - * @param newChild [out] The tag name - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetTagName(nsString &aName) = 0; - /** - * The attributes for this element. - * - * @param aAttributeList [out] The AttributeList - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetAttributes(nsIDOMAttributeList **aAttributeList) = 0; + NS_IMETHOD GetTagName(nsString& aReturn)=0; - /** - * Retrieves an attribute value by name from an Element object. - * NOTE: the name of this function will change to GetAttribute in a subsequent - * release - * - * @param aName [in] The attribute name - * @param aValue [out] The attribute value as a string - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetDOMAttribute(nsString &aName, nsString &aValue) = 0; + NS_IMETHOD GetAttributes(nsIDOMAttributeList** aReturn)=0; - /** - * Set an attribute value from an Element object. - * NOTE: the name of this function will change to SetAttribute in a subsequent - * release - * - * @param aName [in] The attribute name - * @param aValue [in] The attribute value as a string - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetDOMAttribute(nsString &aName, nsString &aValue) = 0; + NS_IMETHOD GetDOMAttribute(nsString& aName, nsString& aReturn)=0; - /** - * Remove the specified attribute - * - * @param aName [in] The attribute name - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD RemoveAttribute(nsString &aName) = 0; + NS_IMETHOD SetDOMAttribute(nsString& aName, nsString& aValue)=0; - /** - * Retrieves an Attribute node by name from an Element object. - * - * @param aName [in] The name of the attribute to retrieve - * @param aAttribute [out] The attribute with the given name - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetAttributeNode(nsString &aName, nsIDOMAttribute **aAttribute) = 0; + NS_IMETHOD RemoveAttribute(nsString& aName)=0; - /** - * Set an Attribute node by name from an Element object. - * - * @param aAttribute [in] The attribute to set - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetAttributeNode(nsIDOMAttribute *aAttribute) = 0; + NS_IMETHOD GetAttributeNode(nsString& aName, nsIDOMAttribute** aReturn)=0; - /** - * Removes the specified attribute/value pair from an Element node object. - * - * @param aAttribute [in] The attribute to remove - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD RemoveAttributeNode(nsIDOMAttribute *aAttribute) = 0; + NS_IMETHOD SetAttributeNode(nsIDOMAttribute* aNewAttr)=0; - /** - * Returns an iterator through all subordinate elements with a given tag name. - * - * @param aName [in] The name of the tag to match on - * @param aIterator [out] The iterator - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetElementsByTagName(nsString &aName,nsIDOMNodeIterator **aIterator) = 0; + NS_IMETHOD RemoveAttributeNode(nsIDOMAttribute* aOldAttr)=0; - /** - * Puts all Tet nodes in the sub-tree underneath this Element into a "normal" - * form where only markup (e.g., tags, comments, PIs, CDATASections, and and - * entity references separates Text nodes. - * - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Normalize() = 0; + NS_IMETHOD GetElementsByTagName(nsString& aTagname, nsIDOMNodeIterator** aReturn)=0; + + NS_IMETHOD Normalize()=0; }; -#endif // nsIDOMElement_h__ +extern nsresult NS_InitElementClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMElement_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMNode.h b/mozilla/dom/public/coreDom/nsIDOMNode.h index c1c2be76f51..c6136a755d5 100644 --- a/mozilla/dom/public/coreDom/nsIDOMNode.h +++ b/mozilla/dom/public/coreDom/nsIDOMNode.h @@ -15,139 +15,56 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMNode_h__ #define nsIDOMNode_h__ -#include "nsDOM.h" #include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" -// forward declaration class nsIDOMNodeIterator; +class nsIDOMNode; #define NS_IDOMNODE_IID \ -{ /* 8f6bca74-ce42-11d1-b724-00600891d8c9 */ \ -0x8f6bca74, 0xce42, 0x11d1, \ -{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } +{ 0x6f7652e8, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } -/** - * The Node object is the primary datatype for the entire Document - * Object Model. It represents a single node in the document - * tree. Nodes may have, but are not required to have, an arbitrary - * number of child nodes. */ class nsIDOMNode : public nsISupports { public: - // NodeType - enum NodeType { - DOCUMENT = 1, - ELEMENT = 2, - ATTRIBUTE = 3, - PI = 4, - COMMENT = 5, - TEXT = 6 + enum { + DOCUMENT = 1, + ELEMENT = 2, + ATTRIBUTE = 3, + PI = 4, + COMMENT = 5, + TEXT = 6 }; - /** - * Returns an indication of the underlying Node object's type. - * - * @param aType [out] The type of the node. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetNodeType(PRInt32 *aType) = 0; + NS_IMETHOD GetNodeType(PRInt32* aReturn)=0; - /** - * Returns the parent of the given Node instance. If this node is - * the root of the document object tree, or if the node has not been - * added to a document tree, null is returned. - * - * @param aNode [out] The parent of the node. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetParentNode(nsIDOMNode **aNode) = 0; + NS_IMETHOD GetParentNode(nsIDOMNode** aReturn)=0; - /** - * Returns a NodeIterator object that will enumerate all children - * of this node. If there are no children, an iterator that will - * return no nodes is returned. The content of the returned - * NodeIterator is "live" in the sense that changes to the children - * of the Node object that it was created from will be immediately - * reflected in the nodes returned by the iterator; it is not a - * static snapshot of the content of the Node. Similarly, changes - * made to the nodes returned by the iterator will be immediately - * reflected in the tree, including the set of children of the Node - * that the NodeIterator was created from. - * - * @param aIterator [out] An iterator through the children of the node. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator) = 0; - - /** - * Returns true if the node has any children, false if the node has - * no children at all. - * - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD HasChildNodes() = 0; + NS_IMETHOD GetChildNodes(nsIDOMNodeIterator** aReturn)=0; - /** - * Returns the first child of a node. If there is no such node, - * null is returned. - * - * @param aNode [out] The first child of the node, or null. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetFirstChild(nsIDOMNode **aNode) = 0; - - /** - * Returns the node immediately preceding the current node in a - * breadth-first traversal of the tree. If there is no such node, - * null is returned. - * - * @param aNode [out] The the node immediately preceeding, or null. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode) = 0; + NS_IMETHOD HasChildNodes(PRBool* aReturn)=0; - /** - * Returns the node immediately following the current node in a - * breadth-first traversal of the tree. If there is no such node, - * null is returned. - * - * @param aNode [out] The node immediately following, or null. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetNextSibling(nsIDOMNode **aNode) = 0; - - /** - * Inserts a child node (newChildbefore the existing child node refChild. - * If refChild is null, insert newChild at the end of the list of children. - * - * @param newChild [in] The node to be inserted - * @param refChild [in] The node before which the new node will be inserted - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild) = 0; - - /** - * Replaces the child node oldChild with newChild in the set of - * children of the given node, and return the oldChild node. - * - * @param newChild [in] The node to be inserted - * @param oldChild [in] The node to be replaced - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild) = 0; + NS_IMETHOD GetFirstChild(nsIDOMNode** aReturn)=0; - /** - * Removes the child node indicated by oldChild from the list of - * children and returns it. - * - * @param oldChild [in] The node to be deleted - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD RemoveChild(nsIDOMNode *oldChild) = 0; + NS_IMETHOD GetPreviousSibling(nsIDOMNode** aReturn)=0; + + NS_IMETHOD GetNextSibling(nsIDOMNode** aReturn)=0; + + NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)=0; + + NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)=0; + + NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild)=0; }; -#endif // nsIDOMNode_h__ +extern nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMNode_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMNodeIterator.h b/mozilla/dom/public/coreDom/nsIDOMNodeIterator.h new file mode 100644 index 00000000000..c6218791f39 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMNodeIterator.h @@ -0,0 +1,56 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMNodeIterator_h__ +#define nsIDOMNodeIterator_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMNodeIterator; +class nsIDOMNode; + +#define NS_IDOMNODEITERATOR_IID \ +{ 0x6f7652e9, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMNodeIterator : public nsISupports { +public: + + NS_IMETHOD GetLength(PRUint32* aReturn)=0; + + NS_IMETHOD GetCurrentNode(nsIDOMNode** aReturn)=0; + + NS_IMETHOD GetNextNode(nsIDOMNode** aReturn)=0; + + NS_IMETHOD GetPreviousNode(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToFirst(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToLast(nsIDOMNode** aReturn)=0; + + NS_IMETHOD MoveTo(PRInt32 aN, nsIDOMNode** aReturn)=0; +}; + +extern nsresult NS_InitNodeIteratorClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptNodeIterator(nsIScriptContext *aContext, nsIDOMNodeIterator *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMNodeIterator_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMPI.h b/mozilla/dom/public/coreDom/nsIDOMPI.h index 8cb21423ed8..04c5b4148d8 100644 --- a/mozilla/dom/public/coreDom/nsIDOMPI.h +++ b/mozilla/dom/public/coreDom/nsIDOMPI.h @@ -15,23 +15,34 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMPI_h__ #define nsIDOMPI_h__ -#include "nsDOM.h" +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" #include "nsIDOMNode.h" +class nsIDOMPI; + +#define NS_IDOMPI_IID \ +{ 0x6f7652ea, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } class nsIDOMPI : public nsIDOMNode { public: - //attribute UniString name; - virtual UniString GetName() = 0; - virtual void SetName(UniString name) = 0; - //attribute UniString data; - virtual UniString GetData() = 0; - virtual void SetData(UniString data) = 0; + + NS_IMETHOD GetName(nsString& aName)=0; + NS_IMETHOD SetName(nsString& aName)=0; + + NS_IMETHOD GetData(nsString& aData)=0; + NS_IMETHOD SetData(nsString& aData)=0; }; -#endif // nsIDOMPI_h__ +extern nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptPI(nsIScriptContext *aContext, nsIDOMPI *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMPI_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMText.h b/mozilla/dom/public/coreDom/nsIDOMText.h index 356d67d06d5..e313b54e51a 100644 --- a/mozilla/dom/public/coreDom/nsIDOMText.h +++ b/mozilla/dom/public/coreDom/nsIDOMText.h @@ -15,106 +15,42 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMText_h__ #define nsIDOMText_h__ -#include "nsDOM.h" +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" #include "nsIDOMNode.h" -// forward declaration class nsIDOMElement; +class nsIDOMText; -/* 8f6bca7b-ce42-11d1-b724-00600891d8c9 */ #define NS_IDOMTEXT_IID \ -{ 0x8f6bca7b, 0xce42, 0x11d1, {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9}} +{ 0x6f7652eb, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } -/** - * The Text object contains the non-markup content of an Element. If - * there is no markup inside an Element's content, the text will be - * contained in a single Text object that is the child of the - * Element. Any markup will parse into child elements that are - * siblings of the Text nodes on either side of it, and whose content - * will be represented as Text node children of the markup element. - */ class nsIDOMText : public nsIDOMNode { public: - /** - * Return the actual content of the text node. Text nodes contain - * just plain text, without markup and without entities, both of - * which are represented as separate objects in the DOM. - * - * @param aString [out] The text data - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD GetData(nsString& aString) = 0; - /** - * Set the actual content of the text node. Text nodes contain just - * plain text, without markup and without entities, both of which - * are represented as separate objects in the DOM. - * - * @param aString [in] The text data - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD SetData(const nsString& aString) = 0; + NS_IMETHOD GetData(nsString& aData)=0; + NS_IMETHOD SetData(nsString& aData)=0; - /** - * Append the string to the end of the character data in this Text node - * - * @param aData [in] The data to append - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Append(const nsString& aData) = 0; + NS_IMETHOD Append(nsString& aData)=0; - /** - * Insert the string at the specified character offset. - * - * @param offset [in] The offset - * @param aData [in] The data to insert - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Insert(PRInt32 offset, const nsString& aData) = 0; + NS_IMETHOD Insert(PRInt32 aOffset, nsString& aData)=0; - /** - * Delete the specified characters range - * - * @param offset [in] The offset where deletion starts - * @param count [out] The number of chracters to delete - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Delete(PRInt32 offset, PRInt32 count) = 0; + NS_IMETHOD Delete(PRInt32 aOffset, PRInt32 aCount)=0; - /** - * Replace the characters starting at the specified character offset with - * the specified string. - * - * @param offset [in] Offset at which to start replacing - * @param count [in] Number of characters to replace - * @param aData [in] String to replace previous content with. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Replace(PRInt32 offset, PRInt32 count, - const nsString& aData) = 0; + NS_IMETHOD Replace(PRInt32 aOffset, PRInt32 aCount, nsString& aData)=0; - /** - * Insert the specified element in the tree as a sibling of the - * Text node. The result of this operation may be the creation of - * up to 2 new Text nodes: the character data specified by the - * offset and count will form one Text node that will become the - * child of the inserted element and the remainder of the character - * data (after the offset and count) will form another Text node - * become a sibling of the original Text node. - * - * @param element [in] Element to insert into the tree. - * @param offset [in] Offset at which to insert. - * @param count [in] Number of characters to copy to child Text - * node of element. - * @return NS_OK iff the function succeeds, otherwise an error code - */ - NS_IMETHOD Splice(nsIDOMElement* element, PRInt32 offset, - PRInt32 count) = 0; + NS_IMETHOD Splice(nsIDOMElement* aElement, PRInt32 aOffset, PRInt32 aCount)=0; }; -#endif // nsIDOMText_h__ +extern nsresult NS_InitTextClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMText_h__ diff --git a/mozilla/dom/public/coreDom/nsIDOMTreeIterator.h b/mozilla/dom/public/coreDom/nsIDOMTreeIterator.h new file mode 100644 index 00000000000..5089ed2f373 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMTreeIterator.h @@ -0,0 +1,61 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMTreeIterator_h__ +#define nsIDOMTreeIterator_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" +#include "nsIDOMNodeIterator.h" + +class nsIDOMTreeIterator; +class nsIDOMNode; + +#define NS_IDOMTREEITERATOR_IID \ +{ 0x6f7652ec, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMTreeIterator : public nsIDOMNodeIterator { +public: + + NS_IMETHOD NumChildren(PRUint32* aReturn)=0; + + NS_IMETHOD NumPreviousSiblings(PRUint32* aReturn)=0; + + NS_IMETHOD NumNextSiblings(PRUint32* aReturn)=0; + + NS_IMETHOD ToParent(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToPreviousSibling(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToNextSibling(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToFirstChild(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToLastChild(nsIDOMNode** aReturn)=0; + + NS_IMETHOD ToNthChild(PRInt32 aN, nsIDOMNode** aReturn)=0; +}; + +extern nsresult NS_InitTreeIteratorClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM NS_NewScriptTreeIterator(nsIScriptContext *aContext, nsIDOMTreeIterator *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMTreeIterator_h__ diff --git a/mozilla/dom/public/idl/Attribute.idl b/mozilla/dom/public/idl/Attribute.idl index 1d07db9e789..ae1a07c56b6 100644 --- a/mozilla/dom/public/idl/Attribute.idl +++ b/mozilla/dom/public/idl/Attribute.idl @@ -1,6 +1,6 @@ interface Attribute { wstring getName(); - wstring getValue(); + attribute wstring value; attribute boolean specified; wstring toString(); }; diff --git a/mozilla/dom/public/idl/AttributeList.idl b/mozilla/dom/public/idl/AttributeList.idl index a716e137fe3..0a7c287389f 100644 --- a/mozilla/dom/public/idl/AttributeList.idl +++ b/mozilla/dom/public/idl/AttributeList.idl @@ -1,6 +1,6 @@ interface AttributeList { Attribute getAttribute(in wstring attrName); - Attribute setAttribute(in Attribute attr); + void setAttribute(in Attribute attr); Attribute remove(in wstring attrName) interface NoSuchAttributeException {}; Attribute item(in unsigned long index) interface NoSuchAttributeException {}; diff --git a/mozilla/dom/public/idl/Document.idl b/mozilla/dom/public/idl/Document.idl index 8a6676d2645..978b2d1d536 100644 --- a/mozilla/dom/public/idl/Document.idl +++ b/mozilla/dom/public/idl/Document.idl @@ -1,7 +1,7 @@ interface Document : DocumentFragment { attribute Node documentType; attribute Element documentElement; - attribute DocumentContext contextInfo; + attribute DocumentContext documentContext; DocumentContext createDocumentContext(); Element createElement(in wstring tagName, in AttributeList attributes); diff --git a/mozilla/dom/public/idl/Element.idl b/mozilla/dom/public/idl/Element.idl index 88eef2e2e2f..759afb574bb 100644 --- a/mozilla/dom/public/idl/Element.idl +++ b/mozilla/dom/public/idl/Element.idl @@ -1,14 +1,14 @@ interface Element : Node { wstring getTagName(); - NodeIterator getAttributes(); - wstring getAttribute(in wstring name); - void setAttribute(in string name, + AttributeList getAttributes(); + wstring getDOMAttribute(in wstring name); + void setDOMAttribute(in string name, in string value); void removeAttribute(in wstring name); Attribute getAttributeNode(in wstring name); void setAttributeNode(in Attribute newAttr); void removeAttributeNode(in Attribute oldAttr); - void getElementsByTagName(in wstring tagname); + NodeIterator getElementsByTagName(in wstring tagname); void normalize(); }; diff --git a/mozilla/dom/public/idl/Node.idl b/mozilla/dom/public/idl/Node.idl index 927d01abbd5..a33f79569d5 100644 --- a/mozilla/dom/public/idl/Node.idl +++ b/mozilla/dom/public/idl/Node.idl @@ -14,12 +14,12 @@ Node getFirstChild(); Node getPreviousSibling(); Node getNextSibling(); - Node insertBefore(in Node newChild, + void insertBefore(in Node newChild, in Node refChild) interface NotMyChildException {}; - Node replaceChild(in Node newChild, + void replaceChild(in Node newChild, in Node oldChild) interface NotMyChildException {}; - Node removeChild(in Node oldChild) interface NotMyChildException {}; + void removeChild(in Node oldChild) interface NotMyChildException {}; }; diff --git a/mozilla/dom/public/idl/NodeIterator.idl b/mozilla/dom/public/idl/NodeIterator.idl index c6a4cf19fd1..b6edbfdd76f 100644 --- a/mozilla/dom/public/idl/NodeIterator.idl +++ b/mozilla/dom/public/idl/NodeIterator.idl @@ -1,11 +1,9 @@ interface NodeIterator { unsigned long getLength(); - unsigned long getCurrentPos(); - boolean atFirst(); - boolean atLast(); - Node toNextNode(); - Node toPrevNode(); - Node toFirstNode(); - Node toLastNode(); + Node getCurrentNode(); + Node getNextNode(); + Node getPreviousNode(); + Node toFirst(); + Node toLast(); Node moveTo(in int n); }; diff --git a/mozilla/dom/public/idl/Window.idl b/mozilla/dom/public/idl/Window.idl new file mode 100644 index 00000000000..df4118fb5ac --- /dev/null +++ b/mozilla/dom/public/idl/Window.idl @@ -0,0 +1,4 @@ + interface Window { + readonly attribute Document document; + void dump(in wstring str); + }; diff --git a/mozilla/dom/public/idl/makefile.win b/mozilla/dom/public/idl/makefile.win index 664f35830ae..c568639dbcb 100644 --- a/mozilla/dom/public/idl/makefile.win +++ b/mozilla/dom/public/idl/makefile.win @@ -35,8 +35,8 @@ IDLSRCS = \ Text.idl \ TreeIterator.idl -XPCOM_DESTDIR=$(DEPTH)\dom\test -JSSTUB_DESTDIR=$(DEPTH)\dom\test +XPCOM_DESTDIR=$(DEPTH)\dom\public\coreDom +JSSTUB_DESTDIR=$(DEPTH)\dom\src GENXDIR=genx GENJSDIR=genjs @@ -56,7 +56,7 @@ export:: $(GENXDIR) $(GENJSDIR) $(IDLSRCS) @echo +++ make: generating xpcom headers $(IDLC) -d $(GENXDIR) -x $(IDLSRCS) @echo +++ make: generating interface ids - $(MOZ_TOOLS)\perl5\perl.exe $(GENIID) $(GENXDIR) + $(PERL) $(GENIID) $(GENXDIR) @echo +++ make: generating JavaScript stubs $(IDLC) -d $(GENJSDIR) -j $(IDLSRCS) diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win index f6229067adc..c548e2aa3c2 100644 --- a/mozilla/dom/public/makefile.win +++ b/mozilla/dom/public/makefile.win @@ -20,7 +20,8 @@ IGNORE_MANIFEST=1 DIRS=coreDom coreEvents events DEFINES=-D_IMPL_NS_DOM -EXPORTS=nsIScriptContext.h nsIScriptObject.h nsIScriptObjectOwner.h +EXPORTS=nsIScriptContext.h nsIJSScriptObject.h nsIScriptObjectOwner.h \ + nsIScriptGlobalObject.h nsIDOMWindow.h MODULE=dom diff --git a/mozilla/dom/public/nsIDOMWindow.h b/mozilla/dom/public/nsIDOMWindow.h new file mode 100644 index 00000000000..a7ce4012fc9 --- /dev/null +++ b/mozilla/dom/public/nsIDOMWindow.h @@ -0,0 +1,44 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIDOMWindow_h__ +#define nsIDOMWindow_h__ + +#include "nsISupports.h" +#include "nsString.h" + +class nsIDOMDocument; +class nsIDOMWindow; + +#define NS_IDOMWINDOW_IID \ +{ 0x6f7652ed, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMWindow : public nsISupports { +public: + + NS_IMETHOD GetDocument(nsIDOMDocument** aDocument)=0; + + NS_IMETHOD Dump(nsString& aStr)=0; +}; + +extern nsresult NS_InitWindowClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobalObject); + +extern "C" NS_DOM NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn); + +#endif // nsIDOMWindow_h__ diff --git a/mozilla/dom/public/nsIJSScriptObject.h b/mozilla/dom/public/nsIJSScriptObject.h new file mode 100644 index 00000000000..54f6aeec1e3 --- /dev/null +++ b/mozilla/dom/public/nsIJSScriptObject.h @@ -0,0 +1,50 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIJSScriptObject_h__ +#define nsIJSScriptObject_h__ + +#include "nsISupports.h" +#include "jsapi.h" + +#define NS_IJSSCRIPTOBJECT_IID \ +{ /* 8f6bca7c-ce42-11d1-b724-00600891d8c9 */ \ +0x8f6bca7c, 0xce42, 0x11d1, \ + {0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} } + +/** + * A java script specific interface. + *

+ * It's implemented by an object that has to execute specific java script + * behavior like the array semantic. + *

+ * It is used by the script runtime to collect information about an object + */ +class nsIJSScriptObject : public nsISupports { +public: + virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp) = 0; + virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp) = 0; + virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp) = 0; + virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp) = 0; + virtual PRBool EnumerateProperty(JSContext *aContext) = 0; + virtual PRBool Resolve(JSContext *aContext, jsval aID) = 0; + virtual PRBool Convert(JSContext *aContext, jsval aID) = 0; + virtual void Finalize(JSContext *aContext) = 0; +}; + +#endif // nsIJSScriptObject_h__ diff --git a/mozilla/dom/public/nsIScriptContext.h b/mozilla/dom/public/nsIScriptContext.h index ebface5eb77..bd8a741c305 100644 --- a/mozilla/dom/public/nsIScriptContext.h +++ b/mozilla/dom/public/nsIScriptContext.h @@ -23,7 +23,7 @@ #include "nsISupports.h" #include "jsapi.h" -class nsIWebWidget; +class nsIScriptGlobalObject; #define NS_ISCRIPTCONTEXT_IID \ { /* 8f6bca7d-ce42-11d1-b724-00600891d8c9 */ \ @@ -50,46 +50,43 @@ public: * **/ virtual PRBool EvaluateString(const char *aScript, - PRUint32 aScriptSize, - jsval *aRetValue) = 0; + PRUint32 aScriptSize, + jsval *aRetValue) = 0; /** * Return the global object. * **/ - virtual JSObject* GetGlobalObject() = 0; + virtual nsIScriptGlobalObject* GetGlobalObject() = 0; /** - * Return the JSContext + * Return the native script context * **/ - virtual JSContext* GetContext() = 0; + virtual void* GetNativeContext() = 0; /** * Init all DOM classes. * **/ - virtual nsresult InitAllClasses() = 0; + virtual nsresult InitClasses() = 0; /** * Init this context. - *

- * The dependency with nsIWebWidget will disappear soon. A more general "global object" - * interface should be defined. nsIWebWidget is too specific. * * @param aGlobalObject the gobal object * * @return NS_OK if context initialization was successful * **/ - virtual nsresult InitContext(nsIWebWidget *aGlobalObject) = 0; + virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject) = 0; }; /** * Return a new Context * */ -extern "C" NS_DOM NS_CreateContext(nsIWebWidget *aGlobal, nsIScriptContext **aContext); +extern "C" NS_DOM NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext); #endif // nsIScriptContext_h__ diff --git a/mozilla/dom/public/nsIScriptGlobalObject.h b/mozilla/dom/public/nsIScriptGlobalObject.h new file mode 100644 index 00000000000..0f26db27a23 --- /dev/null +++ b/mozilla/dom/public/nsIScriptGlobalObject.h @@ -0,0 +1,45 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIScriptGlobalObject_h__ +#define nsIScriptGlobalObject_h__ + +#include "nsISupports.h" +#include "nsIScriptContext.h" + +class nsIScriptContext; +class nsIDOMDocument; + +#define NS_ISCRIPTGLOBALOBJECT_IID \ +{ 0x2b16fc80, 0xfa41, 0x11d1, \ +{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3} } + +/** + * The JavaScript specific global object. This often used to store + * per-window global state. + */ + +class nsIScriptGlobalObject : public nsISupports { +public: + NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext)=0; + NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument)=0; +}; + +extern "C" NS_DOM NS_NewScriptGlobalObject(nsIScriptGlobalObject **aGlobal); + +#endif diff --git a/mozilla/dom/public/nsIScriptObjectOwner.h b/mozilla/dom/public/nsIScriptObjectOwner.h index 3081c878dec..ea4155cc186 100644 --- a/mozilla/dom/public/nsIScriptObjectOwner.h +++ b/mozilla/dom/public/nsIScriptObjectOwner.h @@ -21,9 +21,7 @@ #include "nscore.h" #include "nsISupports.h" - -typedef struct JSContext JSContext; -typedef struct JSObject JSObject; +#include "nsIScriptContext.h" class nsIScriptContext; @@ -54,7 +52,7 @@ public: * @return nsresult NS_OK if the script object is successfully returned * **/ - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject) = 0; + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) = 0; /** * Nuke the current script object. @@ -64,34 +62,4 @@ public: NS_IMETHOD ResetScriptObject() = 0; }; -class nsIDOMDocument; -extern "C" NS_DOM nsresult NS_NewScriptDocument(JSContext *aContext, - nsIDOMDocument *aDocument, - JSObject *aParent, - JSObject **aJSObject); -class nsIDOMElement; -extern "C" NS_DOM nsresult NS_NewScriptElement(JSContext *aContext, - nsIDOMElement *aElement, - JSObject *aParent, - JSObject **aJSObject); -class nsIDOMText; -extern "C" NS_DOM nsresult NS_NewScriptText(JSContext *aContext, - nsIDOMText *aText, - JSObject *aParent, - JSObject **aJSObject); -class nsIDOMNodeIterator; -extern "C" NS_DOM nsresult NS_NewScriptNodeIterator(JSContext *aContext, - nsIDOMNodeIterator *aNodeIterator, - JSObject *aParent, - JSObject **aJSObject); -class nsIDOMAttribute; -extern "C" NS_DOM nsresult NS_NewScriptAttribute(JSContext *aContext, - nsIDOMAttribute *aAttribute, - JSObject *aParent, - JSObject **aJSObject); -class nsIDOMAttributeList; -extern "C" NS_DOM nsresult NS_NewScriptAttributeList(JSContext *aContext, - nsIDOMAttributeList *aAttributeList, - JSObject *aParent, - JSObject **aJSObject); #endif // nsIScriptObjectOwner_h__ diff --git a/mozilla/dom/src/Makefile b/mozilla/dom/src/Makefile index a7f09013cc9..5da1eb77440 100644 --- a/mozilla/dom/src/Makefile +++ b/mozilla/dom/src/Makefile @@ -25,12 +25,14 @@ CPPSRCS = \ nsJSEnvironment.cpp \ nsJSNode.cpp \ nsJSDocument.cpp \ + nsJSDocumentFragment.cpp\ nsJSElement.cpp \ nsJSText.cpp \ nsJSNodeIterator.cpp\ nsJSAttribute.cpp \ nsJSAttributeList.cpp\ nsJSWindow.cpp\ + nsGlobalWindow.cpp \ $(NULL) MODULE = raptor diff --git a/mozilla/dom/src/makefile.win b/mozilla/dom/src/makefile.win index 85c6f95af46..e4edae55512 100644 --- a/mozilla/dom/src/makefile.win +++ b/mozilla/dom/src/makefile.win @@ -27,12 +27,14 @@ CPPSRCS = \ nsJSEnvironment.cpp \ nsJSNode.cpp \ nsJSDocument.cpp \ + nsJSDocumentFragment.cpp\ nsJSElement.cpp \ nsJSText.cpp \ - nsJSNodeIterator.cpp\ + nsJSNodeIterator.cpp \ nsJSAttribute.cpp \ - nsJSAttributeList.cpp\ - nsJSWindow.cpp\ + nsJSAttributeList.cpp \ + nsJSWindow.cpp \ + nsGlobalWindow.cpp \ $(NULL) MODULE=raptor @@ -42,7 +44,8 @@ REQUIRES=xpcom raptor js CPP_OBJS= .\$(OBJDIR)\nsJSEnvironment.obj .\$(OBJDIR)\nsJSNode.obj .\$(OBJDIR)\nsJSDocument.obj \ .\$(OBJDIR)\nsJSElement.obj .\$(OBJDIR)\nsJSText.obj \ .\$(OBJDIR)\nsJSNodeIterator.obj .\$(OBJDIR)\nsJSAttribute.obj \ - .\$(OBJDIR)\nsJSAttributeList.obj .\$(OBJDIR)\nsJSWindow.obj + .\$(OBJDIR)\nsJSAttributeList.obj .\$(OBJDIR)\nsJSWindow.obj \ + .\$(OBJDIR)\nsGlobalWindow.obj .\$(OBJDIR)\nsJSDocumentFragment.obj LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor -I$(XPDIST)\public\dom -I$(XPDIST)\public\js diff --git a/mozilla/dom/src/nsGlobalWindow.cpp b/mozilla/dom/src/nsGlobalWindow.cpp new file mode 100644 index 00000000000..f117d8c5936 --- /dev/null +++ b/mozilla/dom/src/nsGlobalWindow.cpp @@ -0,0 +1,213 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nscore.h" +#include "nsIFactory.h" +#include "nsISupports.h" +#include "nsIScriptContext.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" +#include "nsIDOMDocument.h" +#include "nsHashtable.h" + +#include "jsapi.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID); + +// Global object for scripting +class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow +{ +public: + GlobalWindowImpl(); + ~GlobalWindowImpl(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD ResetScriptObject(); + + NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext); + NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument); + + NS_IMETHOD GetDocument(nsIDOMDocument** aDocument); + NS_IMETHOD Dump(nsString& aStr); + +protected: + nsIScriptContext *mContext; + void *mScriptObject; + nsIDOMDocument *mDocument; +}; + +GlobalWindowImpl::GlobalWindowImpl() +{ + mContext = nsnull; + mScriptObject = nsnull; + mDocument = nsnull; +} + +GlobalWindowImpl::~GlobalWindowImpl() +{ + if (nsnull != mScriptObject) { + JS_RemoveRoot((JSContext *)mContext->GetNativeContext(), &mScriptObject); + mScriptObject = nsnull; + } + + if (nsnull != mContext) { + NS_RELEASE(mContext); + } + + if (nsnull != mDocument) { + NS_RELEASE(mDocument); + } +} + +NS_IMPL_ADDREF(GlobalWindowImpl) +NS_IMPL_RELEASE(GlobalWindowImpl) + +nsresult +GlobalWindowImpl::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIScriptObjectOwnerIID)) { + *aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIScriptGlobalObjectIID)) { + *aInstancePtrResult = (void*) ((nsIScriptGlobalObject*)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIDOMWindowIID)) { + *aInstancePtrResult = (void*) ((nsIDOMWindow*)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtrResult = (void*)(nsISupports*)(nsIScriptGlobalObject*)this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +nsresult +GlobalWindowImpl::ResetScriptObject() +{ + mScriptObject = nsnull; + return NS_OK; +} + +nsresult +GlobalWindowImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) +{ + NS_PRECONDITION(nsnull != aScriptObject, "null arg"); + nsresult res = NS_OK; + if (nsnull == mScriptObject) { + res = NS_NewScriptWindow(aContext, this, nsnull, &mScriptObject); + JS_AddNamedRoot((JSContext *)aContext->GetNativeContext(), + &mScriptObject, "window_object"); + } + + *aScriptObject = mScriptObject; + return res; +} + +NS_IMETHODIMP_(void) +GlobalWindowImpl::SetContext(nsIScriptContext *aContext) +{ + if (mContext) { + NS_RELEASE(mContext); + } + + mContext = aContext; + NS_ADDREF(mContext); +} + +NS_IMETHODIMP_(void) +GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument) +{ + if (nsnull != mDocument) { + if (nsnull != mScriptObject) { + JS_ClearScope((JSContext *)mContext->GetNativeContext(), + (JSObject *)mScriptObject); + } + + NS_RELEASE(mDocument); + } + + mDocument = aDocument; + + if (nsnull != mDocument) { + NS_ADDREF(mDocument); + + if (nsnull != mContext) { + mContext->InitContext(this); + } + } + else { + JS_GC((JSContext *)mContext->GetNativeContext()); + } +} + +NS_IMETHODIMP +GlobalWindowImpl::GetDocument(nsIDOMDocument** aDocument) +{ + *aDocument = mDocument; + NS_ADDREF(mDocument); + + return NS_OK; +} + +NS_IMETHODIMP +GlobalWindowImpl::Dump(nsString& aStr) +{ + char *cstr = aStr.ToNewCString(); + + if (nsnull != cstr) { + printf("%s", cstr); + delete [] cstr; + } + + return NS_OK; +} + +extern "C" NS_DOM +NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult) +{ + if (nsnull == aResult) { + return NS_ERROR_NULL_POINTER; + } + + *aResult = NULL; + + GlobalWindowImpl *global = new GlobalWindowImpl(); + if (nsnull == global) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return global->QueryInterface(kIScriptGlobalObjectIID, (void **)aResult); +} diff --git a/mozilla/dom/src/nsJSAttribute.cpp b/mozilla/dom/src/nsJSAttribute.cpp index 4b5abf5c304..20110ab835d 100644 --- a/mozilla/dom/src/nsJSAttribute.cpp +++ b/mozilla/dom/src/nsJSAttribute.cpp @@ -15,194 +15,324 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMAttribute.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMAttribute.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID); + +NS_DEF_PTR(nsIDOMAttribute); // // Attribute property ids // -enum attribute_slot { - ATTRIBUTE_VALUE = -1, - ATTRIBUTE_SPECIFIED = -2 +enum Attribute_slots { + ATTRIBUTE_VALUE = -11, + ATTRIBUTE_SPECIFIED = -12 }; /***********************************************************************/ - // -// Attribute properties getter +// Attribute Properties Getter // PR_STATIC_CALLBACK(JSBool) GetAttributeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMAttribute *attribute = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != attribute, "null pointer"); + nsIDOMAttribute *a = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case ATTRIBUTE_VALUE: { - nsAutoString string; - if (NS_OK == attribute->GetValue(string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string.GetUnicode(), string.Length()); + nsAutoString prop; + if (NS_OK == a->GetValue(prop)) { + JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length()); + // set the return value *vp = STRING_TO_JSVAL(jsstring); } - + else { + return JS_FALSE; + } break; } case ATTRIBUTE_SPECIFIED: { - if (NS_OK == attribute->GetSpecified()) { - *vp = JSVAL_TRUE; + PRBool prop; + if (NS_OK == a->GetSpecified(&prop)) { + *vp = BOOLEAN_TO_JSVAL(prop); } else { - *vp = JSVAL_FALSE; + return JS_FALSE; } - break; } default: - nsIScriptObject *object; - if (NS_OK == attribute->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; } + } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// Attribute properties setter +// Attribute Properties Setter // PR_STATIC_CALLBACK(JSBool) SetAttributeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMAttribute *attribute = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attribute, "null pointer"); + nsIDOMAttribute *a = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case ATTRIBUTE_VALUE: { - if (JSVAL_IS_STRING(*vp)) { - JSString *jsstring = JSVAL_TO_STRING(*vp); - nsAutoString string = JS_GetStringChars(jsstring); - attribute->SetValue(string); + nsAutoString prop; + JSString *jsstring; + if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) { + prop.SetString(JS_GetStringChars(jsstring)); } + else { + prop.SetString((const char *)nsnull); + } + + a->SetValue(prop); + break; } case ATTRIBUTE_SPECIFIED: { - if (JSVAL_IS_BOOLEAN(*vp)) { - attribute->SetSpecified(JSVAL_TO_BOOLEAN(*vp)); + PRBool prop; + JSBool temp; + if (JSVAL_IS_BOOLEAN(*vp) && JS_ValueToBoolean(cx, *vp, &temp)) { + prop = (PRBool)temp; } + else { + return JS_FALSE; + } + + a->SetSpecified(prop); + break; } default: - nsIScriptObject *object; - if (NS_OK == attribute->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; } + } } } - return JS_TRUE; + return PR_TRUE; } + // // Attribute finalizer // PR_STATIC_CALLBACK(void) FinalizeAttribute(JSContext *cx, JSObject *obj) { - nsIDOMAttribute *attribute = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + nsIDOMAttribute *a = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); - if (nsnull != attribute) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attribute->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - attribute->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// Attribute enumerate // PR_STATIC_CALLBACK(JSBool) -GetName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateAttribute(JSContext *cx, JSObject *obj) { - nsIDOMAttribute *attribute = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attribute, "null pointer"); - nsAutoString string; - if (NS_OK == attribute->GetName(string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string.GetUnicode(), string.Length()); - *rval = STRING_TO_JSVAL(jsstring); + nsIDOMAttribute *a = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } } return JS_TRUE; } + +// +// Attribute resolve +// PR_STATIC_CALLBACK(JSBool) -ToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ResolveAttribute(JSContext *cx, JSObject *obj, jsval id) { - nsIDOMAttribute *attribute = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attribute, "null pointer"); - nsAutoString string; - if (NS_OK == attribute->ToString(string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string.GetUnicode(), string.Length()); - *rval = STRING_TO_JSVAL(jsstring); + nsIDOMAttribute *a = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } } return JS_TRUE; } + +// +// Native method GetName +// +PR_STATIC_CALLBACK(JSBool) +AttributeGetName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttribute *nativeThis = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetName(nativeRet)) { + return JS_FALSE; + } + + JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length()); + // set the return value + *rval = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToString +// +PR_STATIC_CALLBACK(JSBool) +AttributeToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttribute *nativeThis = (nsIDOMAttribute*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToString(nativeRet)) { + return JS_FALSE; + } + + JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length()); + // set the return value + *rval = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM Attribute +// class for Attribute // -JSClass attribute = { +JSClass AttributeClass = { "Attribute", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetAttributeProperty, + JS_PropertyStub, + JS_PropertyStub, + GetAttributeProperty, SetAttributeProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateAttribute, + ResolveAttribute, + JS_ConvertStub, FinalizeAttribute }; + // // Attribute class properties // -static JSPropertySpec attributeProperties[] = +static JSPropertySpec AttributeProperties[] = { - {"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE}, - {"specified", ATTRIBUTE_SPECIFIED, JSPROP_ENUMERATE}, + {"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE}, + {"specified", ATTRIBUTE_SPECIFIED, JSPROP_ENUMERATE}, {0} }; + // // Attribute class methods // -static JSFunctionSpec attributeMethods[] = { - {"getName", GetName, 0}, - {"toString", ToString, 0}, +static JSFunctionSpec AttributeMethods[] = +{ + {"getName", AttributeGetName, 0}, + {"toString", AttributeToString, 0}, {0} }; + // // Attribute constructor // @@ -212,79 +342,93 @@ Attribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Attribute static property ids -// // -// Attribute static properties +// Attribute class initialization // - -// -// Attribute static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitAttributeClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitAttributeClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - NULL, // parent proto - &attribute, // JSClass - Attribute, // JSNative ctor - 0, // ctor args - attributeProperties, // proto props - attributeMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Attribute", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &AttributeClass, // JSClass + Attribute, // JSNative ctor + 0, // ctor args + AttributeProperties, // proto props + AttributeMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// Attribute instance property ids -// // -// Attribute instance properties +// Method for creating a new Attribute JavaScript object // - -// -// New a attribute object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptAttribute(JSContext *aContext, nsIDOMAttribute *aAttribute, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aAttribute && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptAttribute"); JSObject *proto; - NS_InitAttributeClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitAttributeClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &attribute, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &AttributeClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aAttribute); - aAttribute->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSAttributeList.cpp b/mozilla/dom/src/nsJSAttributeList.cpp index dbc27051bcf..06c641ae70d 100644 --- a/mozilla/dom/src/nsJSAttributeList.cpp +++ b/mozilla/dom/src/nsJSAttributeList.cpp @@ -15,279 +15,448 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMAttribute.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMAttributeList.h" +#include "nsIDOMAttribute.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kIDOMAttributeIID, NS_IDOMATTRIBUTE_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID); +static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID); + +NS_DEF_PTR(nsIDOMAttributeList); +NS_DEF_PTR(nsIDOMAttribute); + /***********************************************************************/ - // -// AttributeList properties getter +// AttributeList Properties Getter // PR_STATIC_CALLBACK(JSBool) GetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != attributeList, "null pointer"); + nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == attributeList->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// AttributeList properties setter +// AttributeList Properties Setter // PR_STATIC_CALLBACK(JSBool) SetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); + nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == attributeList->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } + // -// Document finalizer +// AttributeList finalizer // PR_STATIC_CALLBACK(void) FinalizeAttributeList(JSContext *cx, JSObject *obj) { - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - - if (nsnull != attributeList) { + nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attributeList->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - attributeList->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// AttributeList enumerate // PR_STATIC_CALLBACK(JSBool) -GetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateAttributeList(JSContext *cx, JSObject *obj) { - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - nsIDOMAttribute *attribute; - if (NS_OK == attributeList->GetAttribute(string1, &attribute)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attribute->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(attribute); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -SetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_OBJECT(argv[0])) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); - - nsIDOMAttribute *attribute1 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMAttributeIID, (void**)&attribute1)) { - if (NS_OK == attributeList->SetAttribute(attribute1)) { - // set the return value - *rval = argv[0]; - } - NS_RELEASE(attribute1); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - nsIDOMAttribute *attribute1 = nsnull; - if (NS_OK == attributeList->Remove(string1, &attribute1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attribute1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(attribute1); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_INT(argv[0])) { - PRInt32 pos = JSVAL_TO_INT(argv[0]); - - // call the function - nsIDOMAttribute *attribute1 = nsnull; - if (NS_OK == attributeList->Item(pos, &attribute1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attribute1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(attribute1); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMAttributeList *attributeList = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != attributeList, "null pointer"); + nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); - PRUint32 length; - - // call the function - if (NS_OK == attributeList->GetLength(&length)) { - - // set the return value - *rval = INT_TO_JSVAL((PRInt32)length); + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } } return JS_TRUE; } + +// +// AttributeList resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveAttributeList(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method GetAttribute +// +PR_STATIC_CALLBACK(JSBool) +AttributeListGetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttribute* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->GetAttribute(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method SetAttribute +// +PR_STATIC_CALLBACK(JSBool) +AttributeListSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttributePtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kIAttributeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->SetAttribute(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Remove +// +PR_STATIC_CALLBACK(JSBool) +AttributeListRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttribute* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->Remove(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Item +// +PR_STATIC_CALLBACK(JSBool) +AttributeListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttribute* nativeRet; + PRUint32 b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->Item(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetLength +// +PR_STATIC_CALLBACK(JSBool) +AttributeListGetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRUint32 nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetLength(&nativeRet)) { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM AttributeList +// class for AttributeList // -JSClass attributeList = { +JSClass AttributeListClass = { "AttributeList", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetAttributeListProperty, + JS_PropertyStub, + JS_PropertyStub, + GetAttributeListProperty, SetAttributeListProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateAttributeList, + ResolveAttributeList, + JS_ConvertStub, FinalizeAttributeList }; -// -// AttributeList property ids -// // // AttributeList class properties // +static JSPropertySpec AttributeListProperties[] = +{ + {0} +}; + // // AttributeList class methods // -static JSFunctionSpec attributeListMethods[] = { - {"getAttribute", GetAttribute, 1}, - {"setAttribute", SetAttribute, 1}, - {"remove", Remove, 1}, - {"item", Item, 1}, - {"getLength", GetLength, 0}, +static JSFunctionSpec AttributeListMethods[] = +{ + {"getAttribute", AttributeListGetAttribute, 1}, + {"setAttribute", AttributeListSetAttribute, 1}, + {"remove", AttributeListRemove, 1}, + {"item", AttributeListItem, 1}, + {"getLength", AttributeListGetLength, 0}, {0} }; + // // AttributeList constructor // @@ -297,79 +466,93 @@ AttributeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval return JS_TRUE; } -// -// AttributeList static property ids -// // -// AttributeList static properties +// AttributeList class initialization // - -// -// AttributeList static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitAttributeListClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - NULL, // parent proto - &attributeList, // JSClass - AttributeList, // JSNative ctor - 0, // ctor args - NULL, // proto props - attributeListMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "AttributeList", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &AttributeListClass, // JSClass + AttributeList, // JSNative ctor + 0, // ctor args + AttributeListProperties, // proto props + AttributeListMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// AttributeList instance property ids -// // -// AttributeList instance properties +// Method for creating a new AttributeList JavaScript object // - -// -// New a AttributeList object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptAttributeList(JSContext *aContext, nsIDOMAttributeList *aAttributeList, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptAttributeList(nsIScriptContext *aContext, nsIDOMAttributeList *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aAttributeList && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptAttributeList"); JSObject *proto; - NS_InitAttributeListClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitAttributeListClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &attributeList, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &AttributeListClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aAttributeList); - aAttributeList->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSComment.cpp b/mozilla/dom/src/nsJSComment.cpp new file mode 100644 index 00000000000..86f63398bbe --- /dev/null +++ b/mozilla/dom/src/nsJSComment.cpp @@ -0,0 +1,337 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMComment.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID); + +NS_DEF_PTR(nsIDOMComment); + +// +// Comment property ids +// +enum Comment_slots { + COMMENT_DATA = -11 +}; + +/***********************************************************************/ +// +// Comment Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetCommentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMComment *a = (nsIDOMComment*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case COMMENT_DATA: + { + nsAutoString prop; + if (NS_OK == a->GetData(prop)) { + JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length()); + // set the return value + *vp = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; + } + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// Comment Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetCommentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMComment *a = (nsIDOMComment*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case COMMENT_DATA: + { + nsAutoString prop; + JSString *jsstring; + if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) { + prop.SetString(JS_GetStringChars(jsstring)); + } + else { + prop.SetString((const char *)nsnull); + } + + a->SetData(prop); + + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// Comment finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeComment(JSContext *cx, JSObject *obj) +{ + nsIDOMComment *a = (nsIDOMComment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// Comment enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateComment(JSContext *cx, JSObject *obj) +{ + nsIDOMComment *a = (nsIDOMComment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Comment resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveComment(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMComment *a = (nsIDOMComment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for Comment +// +JSClass CommentClass = { + "Comment", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetCommentProperty, + SetCommentProperty, + EnumerateComment, + ResolveComment, + JS_ConvertStub, + FinalizeComment +}; + + +// +// Comment class properties +// +static JSPropertySpec CommentProperties[] = +{ + {"data", COMMENT_DATA, JSPROP_ENUMERATE}, + {0} +}; + + +// +// Comment class methods +// +static JSFunctionSpec CommentMethods[] = +{ + {0} +}; + + +// +// Comment constructor +// +PR_STATIC_CALLBACK(JSBool) +Comment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// Comment class initialization +// +nsresult NS_InitCommentClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Comment", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &CommentClass, // JSClass + Comment, // JSNative ctor + 0, // ctor args + CommentProperties, // proto props + CommentMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new Comment JavaScript object +// +extern "C" NS_DOM NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptComment"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitCommentClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &CommentClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSDOM.cpp b/mozilla/dom/src/nsJSDOM.cpp new file mode 100644 index 00000000000..a03646741df --- /dev/null +++ b/mozilla/dom/src/nsJSDOM.cpp @@ -0,0 +1,405 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMDocument.h" +#include "nsIDOMDOM.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIDOMIID, NS_IDOMDOM_IID); + +NS_DEF_PTR(nsIDOMDocument); +NS_DEF_PTR(nsIDOMDOM); + + +/***********************************************************************/ +// +// DOM Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetDOMProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDOM *a = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// DOM Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetDOMProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDOM *a = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// DOM finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeDOM(JSContext *cx, JSObject *obj) +{ + nsIDOMDOM *a = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// DOM enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateDOM(JSContext *cx, JSObject *obj) +{ + nsIDOMDOM *a = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// DOM resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveDOM(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMDOM *a = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method CreateDocument +// +PR_STATIC_CALLBACK(JSBool) +DOMCreateDocument(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDOM *nativeThis = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMDocument* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->CreateDocument(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method HasFeature +// +PR_STATIC_CALLBACK(JSBool) +DOMHasFeature(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDOM *nativeThis = (nsIDOMDOM*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRBool nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->HasFeature(b0, &nativeRet)) { + return JS_FALSE; + } + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for DOM +// +JSClass DOMClass = { + "DOM", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetDOMProperty, + SetDOMProperty, + EnumerateDOM, + ResolveDOM, + JS_ConvertStub, + FinalizeDOM +}; + + +// +// DOM class properties +// +static JSPropertySpec DOMProperties[] = +{ + {0} +}; + + +// +// DOM class methods +// +static JSFunctionSpec DOMMethods[] = +{ + {"createDocument", DOMCreateDocument, 1}, + {"hasFeature", DOMHasFeature, 1}, + {0} +}; + + +// +// DOM constructor +// +PR_STATIC_CALLBACK(JSBool) +DOM(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// DOM class initialization +// +nsresult NS_InitDOMClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DOM", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DOMClass, // JSClass + DOM, // JSNative ctor + 0, // ctor args + DOMProperties, // proto props + DOMMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new DOM JavaScript object +// +extern "C" NS_DOM NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDOM"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDOMClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &DOMClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSDocument.cpp b/mozilla/dom/src/nsJSDocument.cpp index ec24c93c001..13805a92c10 100644 --- a/mozilla/dom/src/nsJSDocument.cpp +++ b/mozilla/dom/src/nsJSDocument.cpp @@ -15,77 +15,170 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMDocument.h" -#include "nsIDOMNode.h" -#include "nsIDOMElement.h" -#include "nsIDOMText.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMAttributeList.h" +#include "nsIDOMElement.h" +#include "nsIDOMPI.h" +#include "nsIDOMNodeIterator.h" +#include "nsIDOMDocument.h" +#include "nsIDOMTreeIterator.h" +#include "nsIDOMAttribute.h" +#include "nsIDOMNode.h" +#include "nsIDOMText.h" +#include "nsIDOMDocumentContext.h" +#include "nsIDOMComment.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID); +static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIPIIID, NS_IDOMPI_IID); +static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kITreeIteratorIID, NS_IDOMTREEITERATOR_IID); +static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDocumentContextIID, NS_IDOMDOCUMENTCONTEXT_IID); +static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID); + +NS_DEF_PTR(nsIDOMAttributeList); +NS_DEF_PTR(nsIDOMElement); +NS_DEF_PTR(nsIDOMPI); +NS_DEF_PTR(nsIDOMNodeIterator); +NS_DEF_PTR(nsIDOMDocument); +NS_DEF_PTR(nsIDOMTreeIterator); +NS_DEF_PTR(nsIDOMAttribute); +NS_DEF_PTR(nsIDOMNode); +NS_DEF_PTR(nsIDOMText); +NS_DEF_PTR(nsIDOMDocumentContext); +NS_DEF_PTR(nsIDOMComment); // // Document property ids // -enum document_slot { - DOCUMENT_DOCUMENTTYPE = -21, - DOCUMENT_DOCUMENTELEMENT = -22, - DOCUMENT_CONTEXTINFO = -23 +enum Document_slots { + DOCUMENT_DOCUMENTTYPE = -11, + DOCUMENT_DOCUMENTELEMENT = -12, + DOCUMENT_DOCUMENTCONTEXT = -13 }; /***********************************************************************/ - // -// Document properties getter +// Document Properties Getter // PR_STATIC_CALLBACK(JSBool) GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != document, "null pointer"); + nsIDOMDocument *a = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case DOCUMENT_DOCUMENTTYPE: { - //XXX TBI + nsIDOMNode* prop; + if (NS_OK == a->GetDocumentType(&prop)) { + // get the js object + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(prop); + } + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } break; } case DOCUMENT_DOCUMENTELEMENT: { - nsIDOMElement *element = nsnull; - // call the function - if (NS_OK == document->GetDocumentElement(&element)) { - + nsIDOMElement* prop; + if (NS_OK == a->GetDocumentElement(&prop)) { // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == element->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *vp = OBJECT_TO_JSVAL(object); + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); } - NS_RELEASE(owner); + NS_RELEASE(prop); } - NS_RELEASE(element); + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; } break; } - case DOCUMENT_CONTEXTINFO: + case DOCUMENT_DOCUMENTCONTEXT: { - //XXX TBI + nsIDOMDocumentContext* prop; + if (NS_OK == a->GetDocumentContext(&prop)) { + // get the js object + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(prop); + } + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } break; } default: { - nsIScriptObject *object; - if (NS_OK == document->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; } } } @@ -94,37 +187,93 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) return PR_TRUE; } +/***********************************************************************/ // -// Document properties setter +// Document Properties Setter // PR_STATIC_CALLBACK(JSBool) SetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != document, "null pointer"); + nsIDOMDocument *a = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case DOCUMENT_DOCUMENTTYPE: { - //XXX TBI + nsIDOMNode* prop; + if (JSVAL_IS_OBJECT(*vp)) { + JSObject *jsobj = JSVAL_TO_OBJECT(*vp); + nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj); + if (NS_OK != supports->QueryInterface(kINodeIID, (void **)&prop)) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(*vp)) { + prop = nsnull; + } + else { + return JS_FALSE; + } + + a->SetDocumentType(prop); + if (prop) NS_RELEASE(prop); break; } case DOCUMENT_DOCUMENTELEMENT: { - //XXX TBI + nsIDOMElement* prop; + if (JSVAL_IS_OBJECT(*vp)) { + JSObject *jsobj = JSVAL_TO_OBJECT(*vp); + nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj); + if (NS_OK != supports->QueryInterface(kIElementIID, (void **)&prop)) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(*vp)) { + prop = nsnull; + } + else { + return JS_FALSE; + } + + a->SetDocumentElement(prop); + if (prop) NS_RELEASE(prop); break; } - case DOCUMENT_CONTEXTINFO: + case DOCUMENT_DOCUMENTCONTEXT: { - //XXX TBI + nsIDOMDocumentContext* prop; + if (JSVAL_IS_OBJECT(*vp)) { + JSObject *jsobj = JSVAL_TO_OBJECT(*vp); + nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj); + if (NS_OK != supports->QueryInterface(kIDocumentContextIID, (void **)&prop)) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(*vp)) { + prop = nsnull; + } + else { + return JS_FALSE; + } + + a->SetDocumentContext(prop); + if (prop) NS_RELEASE(prop); break; } default: { - nsIScriptObject *object; - if (NS_OK == document->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; } } } @@ -133,181 +282,662 @@ SetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) return PR_TRUE; } + // // Document finalizer // PR_STATIC_CALLBACK(void) FinalizeDocument(JSContext *cx, JSObject *obj) { - nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + nsIDOMDocument *a = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - if (nsnull != document) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == document->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - document->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// Document enumerate // PR_STATIC_CALLBACK(JSBool) -CreateDocumentContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateDocument(JSContext *cx, JSObject *obj) { - //XXX TBI - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -CreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - - if (nsnull != document) { - if (argc > 0) { - JSString* jsstring1 = JSVAL_TO_STRING(argv[0]); - nsString tagName(JS_GetStringChars(jsstring1)); - nsIDOMElement* element; + nsIDOMDocument *a = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - if (NS_OK == document->CreateElement(tagName, nsnull, &element)) { - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == element->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(element); - } + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); } } return JS_TRUE; } + +// +// Document resolve +// PR_STATIC_CALLBACK(JSBool) -CreateTextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ResolveDocument(JSContext *cx, JSObject *obj, jsval id) { - nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - - if (nsnull != document) { - NS_ASSERTION(1 == argc, "unexpected argument count"); - - JSString* jsstring1 = JSVAL_TO_STRING(argv[0]); - nsString data(JS_GetStringChars(jsstring1)); - nsIDOMText* textNode; + nsIDOMDocument *a = (nsIDOMDocument*)JS_GetPrivate(cx, obj); - if (NS_OK == document->CreateTextNode(data, &textNode)) { - // get the js object + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method CreateDocumentContext +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateDocumentContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMDocumentContext* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->CreateDocumentContext(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == textNode->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { // set the return value *rval = OBJECT_TO_JSVAL(object); } NS_RELEASE(owner); } - NS_RELEASE(textNode); + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; } } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateElement +// PR_STATIC_CALLBACK(JSBool) -CreateComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMElement* nativeRet; + nsAutoString b0; + nsIDOMAttributeListPtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (JSVAL_IS_OBJECT(argv[1])) { + nsISupports *supports1 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[1])); + NS_ASSERTION(nsnull != supports1, "null pointer"); + + if ((nsnull == supports1) || + (NS_OK != supports1->QueryInterface(kIAttributeListIID, (void **)(b1.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[1])){ + b1 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->CreateElement(b0, b1, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateTextNode +// PR_STATIC_CALLBACK(JSBool) -CreatePI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreateTextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMText* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->CreateTextNode(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateComment +// PR_STATIC_CALLBACK(JSBool) -CreateAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreateComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMComment* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->CreateComment(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreatePI +// PR_STATIC_CALLBACK(JSBool) -CreateAttributeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreatePI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMPI* nativeRet; + nsAutoString b0; + nsAutoString b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + JSString *jsstring1 = JS_ValueToString(cx, argv[1]); + if (nsnull != jsstring1) { + b1.SetString(JS_GetStringChars(jsstring1)); + } + else { + b1.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->CreatePI(b0, b1, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateAttribute +// PR_STATIC_CALLBACK(JSBool) -CreateTreeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreateAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttribute* nativeRet; + nsAutoString b0; + nsIDOMNodePtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (JSVAL_IS_OBJECT(argv[1])) { + nsISupports *supports1 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[1])); + NS_ASSERTION(nsnull != supports1, "null pointer"); + + if ((nsnull == supports1) || + (NS_OK != supports1->QueryInterface(kINodeIID, (void **)(b1.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[1])){ + b1 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->CreateAttribute(b0, b1, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateAttributeList +// PR_STATIC_CALLBACK(JSBool) -GetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +DocumentCreateAttributeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - //XXX TBI + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttributeList* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->CreateAttributeList(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + return JS_TRUE; } + +// +// Native method CreateTreeIterator +// +PR_STATIC_CALLBACK(JSBool) +DocumentCreateTreeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMTreeIterator* nativeRet; + nsIDOMNodePtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->CreateTreeIterator(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagName +// +PR_STATIC_CALLBACK(JSBool) +DocumentGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodeIterator* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->GetElementsByTagName(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM Document +// class for Document // -JSClass document = { +JSClass DocumentClass = { "Document", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetDocumentProperty, + JS_PropertyStub, + JS_PropertyStub, + GetDocumentProperty, SetDocumentProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateDocument, + ResolveDocument, + JS_ConvertStub, FinalizeDocument }; + // // Document class properties // -static JSPropertySpec documentProperties[] = +static JSPropertySpec DocumentProperties[] = { - {"documentType", DOCUMENT_DOCUMENTTYPE, JSPROP_ENUMERATE}, - {"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE}, - {"contextInfo", DOCUMENT_CONTEXTINFO, JSPROP_ENUMERATE}, + {"documentType", DOCUMENT_DOCUMENTTYPE, JSPROP_ENUMERATE}, + {"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE}, + {"documentContext", DOCUMENT_DOCUMENTCONTEXT, JSPROP_ENUMERATE}, {0} }; + // // Document class methods // -static JSFunctionSpec documentMethods[] = { - {"createDocumentContext", CreateDocumentContext, 0}, - {"createElement", CreateElement, 2}, - {"createTextNode", CreateTextNode, 1}, - {"createComment", CreateComment, 1}, - {"createPI", CreatePI, 2}, - {"createAttribute", CreateAttribute, 2}, - {"createAttributeList", CreateAttributeList, 0}, - {"createTreeIterator", CreateTreeIterator, 1}, - {"getElementsByTagName", GetElementsByTagName, 0}, +static JSFunctionSpec DocumentMethods[] = +{ + {"createDocumentContext", DocumentCreateDocumentContext, 0}, + {"createElement", DocumentCreateElement, 2}, + {"createTextNode", DocumentCreateTextNode, 1}, + {"createComment", DocumentCreateComment, 1}, + {"createPI", DocumentCreatePI, 2}, + {"createAttribute", DocumentCreateAttribute, 2}, + {"createAttributeList", DocumentCreateAttributeList, 0}, + {"createTreeIterator", DocumentCreateTreeIterator, 1}, + {"getElementsByTagName", DocumentGetElementsByTagName, 1}, {0} }; + // // Document constructor // @@ -317,82 +947,96 @@ Document(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Document static property ids -// // -// Document static properties +// Document class initialization // - -// -// Document static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitNodeClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitDocumentClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitDocumentClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - JSObject *parentProto = nsnull; - NS_InitNodeClass(aContext, &parentProto); - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - parentProto, // parent proto - &document, // JSClass - Document, // JSNative ctor - 0, // ctor args - documentProperties, // proto props - documentMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Document", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitDocumentFragmentClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DocumentClass, // JSClass + Document, // JSNative ctor + 0, // ctor args + DocumentProperties, // proto props + DocumentMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// Document instance property ids -// // -// Document instance properties +// Method for creating a new Document JavaScript object // - -// -// New a document object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptDocument(JSContext *aContext, nsIDOMDocument *aDocument, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aDocument && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocument"); JSObject *proto; - NS_InitDocumentClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDocumentClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &document, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &DocumentClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aDocument); - aDocument->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSDocumentContext.cpp b/mozilla/dom/src/nsJSDocumentContext.cpp new file mode 100644 index 00000000000..4b69fe39913 --- /dev/null +++ b/mozilla/dom/src/nsJSDocumentContext.cpp @@ -0,0 +1,357 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMDocument.h" +#include "nsIDOMDocumentContext.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentContextIID, NS_IDOMDOCUMENTCONTEXT_IID); + +NS_DEF_PTR(nsIDOMDocument); +NS_DEF_PTR(nsIDOMDocumentContext); + +// +// DocumentContext property ids +// +enum DocumentContext_slots { + DOCUMENTCONTEXT_DOCUMENT = -11 +}; + +/***********************************************************************/ +// +// DocumentContext Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case DOCUMENTCONTEXT_DOCUMENT: + { + nsIDOMDocument* prop; + if (NS_OK == a->GetDocument(&prop)) { + // get the js object + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(prop); + } + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// DocumentContext Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case DOCUMENTCONTEXT_DOCUMENT: + { + nsIDOMDocument* prop; + if (JSVAL_IS_OBJECT(*vp)) { + JSObject *jsobj = JSVAL_TO_OBJECT(*vp); + nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj); + if (NS_OK != supports->QueryInterface(kIDocumentIID, (void **)&prop)) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(*vp)) { + prop = nsnull; + } + else { + return JS_FALSE; + } + + a->SetDocument(prop); + if (prop) NS_RELEASE(prop); + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// DocumentContext finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeDocumentContext(JSContext *cx, JSObject *obj) +{ + nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// DocumentContext enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateDocumentContext(JSContext *cx, JSObject *obj) +{ + nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// DocumentContext resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveDocumentContext(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for DocumentContext +// +JSClass DocumentContextClass = { + "DocumentContext", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetDocumentContextProperty, + SetDocumentContextProperty, + EnumerateDocumentContext, + ResolveDocumentContext, + JS_ConvertStub, + FinalizeDocumentContext +}; + + +// +// DocumentContext class properties +// +static JSPropertySpec DocumentContextProperties[] = +{ + {"document", DOCUMENTCONTEXT_DOCUMENT, JSPROP_ENUMERATE}, + {0} +}; + + +// +// DocumentContext class methods +// +static JSFunctionSpec DocumentContextMethods[] = +{ + {0} +}; + + +// +// DocumentContext constructor +// +PR_STATIC_CALLBACK(JSBool) +DocumentContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// DocumentContext class initialization +// +nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentContext", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DocumentContextClass, // JSClass + DocumentContext, // JSNative ctor + 0, // ctor args + DocumentContextProperties, // proto props + DocumentContextMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new DocumentContext JavaScript object +// +extern "C" NS_DOM NS_NewScriptDocumentContext(nsIScriptContext *aContext, nsIDOMDocumentContext *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentContext"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDocumentContextClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &DocumentContextClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSDocumentFragment.cpp b/mozilla/dom/src/nsJSDocumentFragment.cpp new file mode 100644 index 00000000000..7bcbab79902 --- /dev/null +++ b/mozilla/dom/src/nsJSDocumentFragment.cpp @@ -0,0 +1,360 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMDocument.h" +#include "nsIDOMDocumentFragment.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID); + +NS_DEF_PTR(nsIDOMDocument); +NS_DEF_PTR(nsIDOMDocumentFragment); + +// +// DocumentFragment property ids +// +enum DocumentFragment_slots { + DOCUMENTFRAGMENT_MASTERDOC = -11 +}; + +/***********************************************************************/ +// +// DocumentFragment Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetDocumentFragmentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentFragment *a = (nsIDOMDocumentFragment*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case DOCUMENTFRAGMENT_MASTERDOC: + { + nsIDOMDocument* prop; + if (NS_OK == a->GetMasterDoc(&prop)) { + // get the js object + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(prop); + } + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// DocumentFragment Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetDocumentFragmentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMDocumentFragment *a = (nsIDOMDocumentFragment*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case DOCUMENTFRAGMENT_MASTERDOC: + { + nsIDOMDocument* prop; + if (JSVAL_IS_OBJECT(*vp)) { + JSObject *jsobj = JSVAL_TO_OBJECT(*vp); + nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj); + if (NS_OK != supports->QueryInterface(kIDocumentIID, (void **)&prop)) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(*vp)) { + prop = nsnull; + } + else { + return JS_FALSE; + } + + a->SetMasterDoc(prop); + if (prop) NS_RELEASE(prop); + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// DocumentFragment finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeDocumentFragment(JSContext *cx, JSObject *obj) +{ + nsIDOMDocumentFragment *a = (nsIDOMDocumentFragment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// DocumentFragment enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateDocumentFragment(JSContext *cx, JSObject *obj) +{ + nsIDOMDocumentFragment *a = (nsIDOMDocumentFragment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// DocumentFragment resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveDocumentFragment(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMDocumentFragment *a = (nsIDOMDocumentFragment*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for DocumentFragment +// +JSClass DocumentFragmentClass = { + "DocumentFragment", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetDocumentFragmentProperty, + SetDocumentFragmentProperty, + EnumerateDocumentFragment, + ResolveDocumentFragment, + JS_ConvertStub, + FinalizeDocumentFragment +}; + + +// +// DocumentFragment class properties +// +static JSPropertySpec DocumentFragmentProperties[] = +{ + {"masterDoc", DOCUMENTFRAGMENT_MASTERDOC, JSPROP_ENUMERATE}, + {0} +}; + + +// +// DocumentFragment class methods +// +static JSFunctionSpec DocumentFragmentMethods[] = +{ + {0} +}; + + +// +// DocumentFragment constructor +// +PR_STATIC_CALLBACK(JSBool) +DocumentFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// DocumentFragment class initialization +// +nsresult NS_InitDocumentFragmentClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentFragment", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &DocumentFragmentClass, // JSClass + DocumentFragment, // JSNative ctor + 0, // ctor args + DocumentFragmentProperties, // proto props + DocumentFragmentMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new DocumentFragment JavaScript object +// +extern "C" NS_DOM NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentFragment"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitDocumentFragmentClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &DocumentFragmentClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSElement.cpp b/mozilla/dom/src/nsJSElement.cpp index 016af77a5fd..c305671248b 100644 --- a/mozilla/dom/src/nsJSElement.cpp +++ b/mozilla/dom/src/nsJSElement.cpp @@ -15,382 +15,672 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMElement.h" -#include "nsIDOMAttribute.h" -#include "nsIDOMIterators.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMAttributeList.h" +#include "nsIDOMElement.h" +#include "nsIDOMNodeIterator.h" +#include "nsIDOMAttribute.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kIDOMAttributeIID, NS_IDOMATTRIBUTE_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID); +static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID); +static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID); + +NS_DEF_PTR(nsIDOMAttributeList); +NS_DEF_PTR(nsIDOMElement); +NS_DEF_PTR(nsIDOMNodeIterator); +NS_DEF_PTR(nsIDOMAttribute); + /***********************************************************************/ - // -// Element properties getter +// Element Properties Getter // PR_STATIC_CALLBACK(JSBool) GetElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != element, "null pointer"); + nsIDOMElement *a = (nsIDOMElement*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == element->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// Element properties setter +// Element Properties Setter // PR_STATIC_CALLBACK(JSBool) SetElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); + nsIDOMElement *a = (nsIDOMElement*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object = nsnull; - if (NS_OK == element->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } + // // Element finalizer // PR_STATIC_CALLBACK(void) FinalizeElement(JSContext *cx, JSObject *obj) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); + nsIDOMElement *a = (nsIDOMElement*)JS_GetPrivate(cx, obj); - if (nsnull != element) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == element->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - element->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// Element enumerate // PR_STATIC_CALLBACK(JSBool) -GetTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateElement(JSContext *cx, JSObject *obj) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); + nsIDOMElement *a = (nsIDOMElement*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Element resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveElement(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMElement *a = (nsIDOMElement*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method GetTagName +// +PR_STATIC_CALLBACK(JSBool) +ElementGetTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + *rval = JSVAL_NULL; - // call the function - nsAutoString string; - if (NS_OK == element->GetTagName(string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string, string.Length()); + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetTagName(nativeRet)) { + return JS_FALSE; + } + + JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length()); // set the return value *rval = STRING_TO_JSVAL(jsstring); } + else { + return JS_FALSE; + } return JS_TRUE; } + +// +// Native method GetAttributes +// PR_STATIC_CALLBACK(JSBool) -GetAttributes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ElementGetAttributes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttributeList* nativeRet; + *rval = JSVAL_NULL; - // call the function - nsIDOMAttributeList *attributeList = nsnull; - if (NS_OK == element->GetAttributes(&attributeList)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attributeList->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(attributeList); + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; } - return JS_TRUE; -} + if (argc >= 0) { -PR_STATIC_CALLBACK(JSBool) -GetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - nsAutoString string; - if (NS_OK == element->GetDOMAttribute(string1, string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string, string.Length()); - // set the return value - *rval = STRING_TO_JSVAL(jsstring); - } + if (NS_OK != nativeThis->GetAttributes(&nativeRet)) { + return JS_FALSE; } - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -SetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(2 == argc, "wrong number of arguments"); - if (2 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0]) && - JSVAL_IS_STRING(argv[1])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - JSString *jsstring2 = JSVAL_TO_STRING(argv[1]); - nsAutoString string2 = JS_GetStringChars(jsstring2); - - // call the function - element->SetDOMAttribute(string1, string2); - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -RemoveAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - element->RemoveAttribute(string1); - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - nsIDOMAttribute *attribute = nsnull; - if (NS_OK == element->GetAttributeNode(string1, &attribute)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == attribute->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); } - NS_RELEASE(attribute); + NS_RELEASE(owner); } + NS_RELEASE(nativeRet); } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method GetDOMAttribute +// PR_STATIC_CALLBACK(JSBool) -SetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ElementGetDOMAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - if (1 == argc) { - // get the arguments - if (JSVAL_IS_OBJECT(argv[0])) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString nativeRet; + nsAutoString b0; - nsIDOMAttribute *attribute1 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMAttributeIID, (void**)&attribute1)) { - element->SetAttributeNode(attribute1); - NS_RELEASE(attribute1); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -RemoveAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - if (1 == argc) { - // get the arguments - if (JSVAL_IS_OBJECT(argv[0])) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); - - nsIDOMAttribute *attribute1 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMAttributeIID, (void**)&attribute1)) { - element->RemoveAttributeNode(attribute1); - NS_RELEASE(attribute1); - } - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - // call the function - nsIDOMNodeIterator *nodeIterator = nsnull; - if (NS_OK == element->GetElementsByTagName(string1, &nodeIterator)) { + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == nodeIterator->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(nodeIterator); - } + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->GetDOMAttribute(b0, nativeRet)) { + return JS_FALSE; + } + + JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length()); + // set the return value + *rval = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; } return JS_TRUE; } -PR_STATIC_CALLBACK(JSBool) -Normalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMElement *element = (nsIDOMElement*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != element, "null pointer"); - // call the function - element->Normalize(); +// +// Native method SetDOMAttribute +// +PR_STATIC_CALLBACK(JSBool) +ElementSetDOMAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + nsAutoString b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + JSString *jsstring1 = JS_ValueToString(cx, argv[1]); + if (nsnull != jsstring1) { + b1.SetString(JS_GetStringChars(jsstring1)); + } + else { + b1.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->SetDOMAttribute(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } return JS_TRUE; } + +// +// Native method RemoveAttribute +// +PR_STATIC_CALLBACK(JSBool) +ElementRemoveAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->RemoveAttribute(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetAttributeNode +// +PR_STATIC_CALLBACK(JSBool) +ElementGetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttribute* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->GetAttributeNode(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method SetAttributeNode +// +PR_STATIC_CALLBACK(JSBool) +ElementSetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttributePtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kIAttributeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->SetAttributeNode(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method RemoveAttributeNode +// +PR_STATIC_CALLBACK(JSBool) +ElementRemoveAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMAttributePtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kIAttributeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->RemoveAttributeNode(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagName +// +PR_STATIC_CALLBACK(JSBool) +ElementGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodeIterator* nativeRet; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->GetElementsByTagName(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Normalize +// +PR_STATIC_CALLBACK(JSBool) +ElementNormalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->Normalize()) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM Element +// class for Element // -JSClass element = { +JSClass ElementClass = { "Element", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetElementProperty, + JS_PropertyStub, + JS_PropertyStub, + GetElementProperty, SetElementProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateElement, + ResolveElement, + JS_ConvertStub, FinalizeElement }; -// -// Element property ids -// // // Element class properties // +static JSPropertySpec ElementProperties[] = +{ + {0} +}; + // // Element class methods // -static JSFunctionSpec elementMethods[] = { - {"getTagName", GetTagName, 0}, - {"getAttributes", GetAttributes, 0}, - {"getAttribute", GetAttribute, 1}, - {"setAttribute", SetAttribute, 2}, - {"removeAttribute", RemoveAttribute, 1}, - {"getAttributeNode", GetAttributeNode, 1}, - {"setAttributeNode", SetAttributeNode, 1}, - {"removeAttributeNode", RemoveAttributeNode, 1}, - {"getElementsByTagName", GetElementsByTagName, 1}, - {"normalize", Normalize, 0}, +static JSFunctionSpec ElementMethods[] = +{ + {"getTagName", ElementGetTagName, 0}, + {"getAttributes", ElementGetAttributes, 0}, + {"getDOMAttribute", ElementGetDOMAttribute, 1}, + {"setDOMAttribute", ElementSetDOMAttribute, 2}, + {"removeAttribute", ElementRemoveAttribute, 1}, + {"getAttributeNode", ElementGetAttributeNode, 1}, + {"setAttributeNode", ElementSetAttributeNode, 1}, + {"removeAttributeNode", ElementRemoveAttributeNode, 1}, + {"getElementsByTagName", ElementGetElementsByTagName, 1}, + {"normalize", ElementNormalize, 0}, {0} }; + // // Element constructor // @@ -400,82 +690,96 @@ Element(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Element static property ids -// // -// Element static properties +// Element class initialization // - -// -// Element static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitNodeClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitElementClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitElementClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - JSObject *parentProto; - NS_InitNodeClass(aContext, &parentProto); - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - parentProto, // parent proto - &element, // JSClass - Element, // JSNative ctor - 0, // ctor args - NULL, // proto props - elementMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Element", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &ElementClass, // JSClass + Element, // JSNative ctor + 0, // ctor args + ElementProperties, // proto props + ElementMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// Element instance property ids -// // -// Element instance properties +// Method for creating a new Element JavaScript object // - -// -// New a element object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptElement(JSContext *aContext, nsIDOMElement *aElement, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aElement && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptElement"); JSObject *proto; - NS_InitElementClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitElementClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &element, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &ElementClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aElement); - aElement->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSEnvironment.cpp b/mozilla/dom/src/nsJSEnvironment.cpp index 397b4baef64..224332e1701 100644 --- a/mozilla/dom/src/nsJSEnvironment.cpp +++ b/mozilla/dom/src/nsJSEnvironment.cpp @@ -18,16 +18,27 @@ #include "nsJSEnvironment.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" +#include "nsIDOMNode.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocument.h" +#include "nsIDOMText.h" +#include "nsIDOMAttribute.h" +#include "nsIDOMAttributeList.h" +#include "nsIDOMNodeIterator.h" const uint32 gGCSize = 4L * 1024L * 1024L; const size_t gStackSize = 8192; static NS_DEFINE_IID(kIScriptContextIID, NS_ISCRIPTCONTEXT_IID); +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); nsJSContext::nsJSContext(JSRuntime *aRuntime) { - mRefCnt = 1; + mRefCnt = 0; mContext = JS_NewContext(aRuntime, gStackSize); + JS_SetContextPrivate(mContext, (void *)this); } nsJSContext::~nsJSContext() @@ -50,81 +61,105 @@ PRBool nsJSContext::EvaluateString(const char *aScript, aRetValue); } -JSObject* nsJSContext::GetGlobalObject() +nsIScriptGlobalObject* nsJSContext::GetGlobalObject() { - return JS_GetGlobalObject(mContext); + JSObject *global = JS_GetGlobalObject(mContext); + nsIScriptGlobalObject *script_global; + + if (nsnull != global) { + script_global = (nsIScriptGlobalObject *)JS_GetPrivate(mContext, global); + NS_ADDREF(script_global); + return script_global; + } + else { + return nsnull; + } } -JSContext* nsJSContext::GetContext() +void* nsJSContext::GetNativeContext() { - return mContext; + return (void *)mContext; } -#define GLOBAL_OBJECT_NAME "window_object" -nsresult NS_NewGlobalWindow(JSContext *aContext, nsIWebWidget *aWindow, void **aJSObject); -nsresult nsJSContext::InitContext(nsIWebWidget *aGlobalObject) +nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) { nsresult result = NS_ERROR_FAILURE; - + nsIScriptObjectOwner *owner; JSObject *global; - nsresult res = NS_NewGlobalWindow(mContext, aGlobalObject, (void**)&global); + nsresult res = aGlobalObject->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner); + if (NS_OK == res) { + res = owner->GetScriptObject(this, (void **)&global); + // init standard classes - if (::JS_InitStandardClasses(mContext, global)) { - res = InitAllClasses(); // this will complete the global object initialization + if ((NS_OK == res) && ::JS_InitStandardClasses(mContext, global)) { + JS_SetGlobalObject(mContext, global); + res = InitClasses(); // this will complete the global object initialization } + + NS_RELEASE(owner); } return res; } -nsresult NS_InitWindowClass(JSContext *aContext, JSObject *aGlobal); -nsresult NS_InitNodeClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitElementClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitDocumentClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitTextClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitAttributeClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitAttributeListClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitNodeIteratorClass(JSContext *aContext, JSObject **aPrototype); - -nsresult nsJSContext::InitAllClasses() +nsresult nsJSContext::InitClasses() { - if (NS_OK == NS_InitWindowClass(mContext, GetGlobalObject()) && - NS_OK == NS_InitNodeClass(mContext, nsnull) && - NS_OK == NS_InitElementClass(mContext, nsnull) && - NS_OK == NS_InitDocumentClass(mContext, nsnull) && - NS_OK == NS_InitTextClass(mContext, nsnull) && - NS_OK == NS_InitAttributeClass(mContext, nsnull) && - NS_OK == NS_InitAttributeListClass(mContext, nsnull) && - NS_OK == NS_InitNodeIteratorClass(mContext, nsnull)) - return NS_OK; + nsresult res = NS_ERROR_FAILURE; + nsIScriptGlobalObject *global = GetGlobalObject(); - return NS_ERROR_FAILURE; + if (NS_OK == NS_InitWindowClass(this, global) && + NS_OK == NS_InitNodeClass(this, nsnull) && + NS_OK == NS_InitElementClass(this, nsnull) && + NS_OK == NS_InitDocumentClass(this, nsnull) && + NS_OK == NS_InitTextClass(this, nsnull) && + NS_OK == NS_InitAttributeClass(this, nsnull) && + NS_OK == NS_InitAttributeListClass(this, nsnull) && + NS_OK == NS_InitNodeIteratorClass(this, nsnull)) { + res = NS_OK; + } + + NS_RELEASE(global); + return res; +} + +nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull; + +nsJSEnvironment * +nsJSEnvironment::GetScriptingEnvironment() +{ + if (nsnull == sTheEnvironment) { + sTheEnvironment = new nsJSEnvironment(); + } + return sTheEnvironment; } nsJSEnvironment::nsJSEnvironment() { mRuntime = JS_Init(gGCSize); - mScriptContext = new nsJSContext(mRuntime); } nsJSEnvironment::~nsJSEnvironment() { - NS_RELEASE(mScriptContext); JS_Finish(mRuntime); } -nsIScriptContext* nsJSEnvironment::GetContext() +nsIScriptContext* nsJSEnvironment::GetNewContext() { - return mScriptContext; + nsIScriptContext *context; + context = new nsJSContext(mRuntime); + NS_ADDREF(context); + return context; } -extern "C" NS_DOM NS_CreateContext(nsIWebWidget *aGlobal, nsIScriptContext **aContext) + +extern "C" NS_DOM NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext) { - nsJSEnvironment *environment = new nsJSEnvironment(); - *aContext = environment->GetContext(); + nsJSEnvironment *environment = nsJSEnvironment::GetScriptingEnvironment(); + *aContext = environment->GetNewContext(); (*aContext)->InitContext(aGlobal); + aGlobal->SetContext(*aContext); return NS_OK; } diff --git a/mozilla/dom/src/nsJSEnvironment.h b/mozilla/dom/src/nsJSEnvironment.h index 7753164a66c..24a7625637a 100644 --- a/mozilla/dom/src/nsJSEnvironment.h +++ b/mozilla/dom/src/nsJSEnvironment.h @@ -33,22 +33,24 @@ public: virtual PRBool EvaluateString(const char *aScript, PRUint32 aScriptSize, jsval *aRetValue); - virtual JSObject* GetGlobalObject(); - virtual JSContext* GetContext(); - virtual nsresult InitAllClasses(); - virtual nsresult InitContext(nsIWebWidget *aGlobalObject); + virtual nsIScriptGlobalObject* GetGlobalObject(); + virtual void* GetNativeContext(); + virtual nsresult InitClasses(); + virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject); }; class nsJSEnvironment { private: - nsIScriptContext *mScriptContext; + static nsJSEnvironment *sTheEnvironment; JSRuntime *mRuntime; public: nsJSEnvironment(); ~nsJSEnvironment(); - nsIScriptContext* GetContext(); + nsIScriptContext* GetNewContext(); + + static nsJSEnvironment *GetScriptingEnvironment(); }; #endif /* nsJSEnvironment_h___ */ diff --git a/mozilla/dom/src/nsJSNode.cpp b/mozilla/dom/src/nsJSNode.cpp index 5a59b84625e..d21c09ca75f 100644 --- a/mozilla/dom/src/nsJSNode.cpp +++ b/mozilla/dom/src/nsJSNode.cpp @@ -15,433 +15,691 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ -#include "nscore.h" -#include "nsIScriptObject.h" -#include "nsIScriptObjectOwner.h" -#include "nsIDOMNode.h" -#include "nsIDOMIterators.h" #include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMNodeIterator.h" +#include "nsIDOMNode.h" + static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); + +NS_DEF_PTR(nsIDOMNodeIterator); +NS_DEF_PTR(nsIDOMNode); + /***********************************************************************/ - // -// Node properties getter +// Node Properties Getter // PR_STATIC_CALLBACK(JSBool) GetNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); + nsIDOMNode *a = (nsIDOMNode*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == node->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// Node properties setter +// Node Properties Setter // PR_STATIC_CALLBACK(JSBool) SetNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); + nsIDOMNode *a = (nsIDOMNode*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == node->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } + // // Node finalizer // PR_STATIC_CALLBACK(void) FinalizeNode(JSContext *cx, JSObject *obj) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); + nsIDOMNode *a = (nsIDOMNode*)JS_GetPrivate(cx, obj); - if (nsnull != node) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == node->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - node->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// Node enumerate // PR_STATIC_CALLBACK(JSBool) -GetNodeType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateNode(JSContext *cx, JSObject *obj) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - - PRInt32 type = 0; - // call the function - if (NS_OK == node->GetNodeType(&type)) { - *rval = INT_TO_JSVAL(type); + nsIDOMNode *a = (nsIDOMNode*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } } - return JS_TRUE; } + +// +// Node resolve +// PR_STATIC_CALLBACK(JSBool) -GetParentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ResolveNode(JSContext *cx, JSObject *obj, jsval id) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); + nsIDOMNode *a = (nsIDOMNode*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method GetNodeType +// +PR_STATIC_CALLBACK(JSBool) +NodeGetNodeType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRInt32 nativeRet; + *rval = JSVAL_NULL; - nsIDOMNode *parent = nsnull; - // call the function - if (NS_OK == node->GetParentNode(&parent)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == parent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(parent); + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; } - return JS_TRUE; -} + if (argc >= 0) { -PR_STATIC_CALLBACK(JSBool) -GetChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNodeIterator *nodeIterator = nsnull; - // call the function - if (NS_OK == node->GetChildNodes(&nodeIterator)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == nodeIterator->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + if (NS_OK != nativeThis->GetNodeType(&nativeRet)) { + return JS_FALSE; } - NS_RELEASE(nodeIterator); - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -HasChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - - // call the function - if (NS_OK == node->HasChildNodes()) { - *rval = JSVAL_TRUE; + *rval = INT_TO_JSVAL(nativeRet); } else { - *rval = JSVAL_FALSE; + return JS_FALSE; } return JS_TRUE; } + +// +// Native method GetParentNode +// PR_STATIC_CALLBACK(JSBool) -GetFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +NodeGetParentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + *rval = JSVAL_NULL; - nsIDOMNode *child = nsnull; - // call the function - if (NS_OK == node->GetFirstChild(&child)) { + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == child->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + if (argc >= 0) { + + if (NS_OK != nativeThis->GetParentNode(&nativeRet)) { + return JS_FALSE; } - NS_RELEASE(child); - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetPreviousSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *previous = nsnull; - // call the function - if (NS_OK == node->GetPreviousSibling(&previous)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == previous->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(previous); - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *next = nsnull; - // call the function - if (NS_OK == node->GetNextSibling(&next)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == next->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(next); - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -InsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - NS_ASSERTION(2 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (2 == argc) { - // get the arguments. the refChild can be null - if (JSVAL_IS_OBJECT(argv[0]) && (JSVAL_IS_OBJECT(argv[1]) || JSVAL_IS_NULL(argv[1]))) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - JSObject *obj2 = JSVAL_IS_OBJECT(argv[1]) ? JSVAL_TO_OBJECT(argv[1]) : nsnull; - - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); - - nsISupports *support2 = nsnull; - if (nsnull != obj2) { - support2 = (nsISupports*)JS_GetPrivate(cx, obj2); - NS_ASSERTION(nsnull != support2, "null pointer"); - } - - nsIDOMNode *node1 = nsnull; - nsIDOMNode *node2 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMNodeIID, (void**)&node1)) { - if ((nsnull == support2) || - (NS_OK == support2->QueryInterface(kIDOMNodeIID, (void**)&node2))) { - - // call the function - if (NS_OK == node->InsertBefore(node1, node2)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == node1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - } - NS_IF_RELEASE(node2); + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); } - NS_RELEASE(node1); + NS_RELEASE(owner); } + NS_RELEASE(nativeRet); } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method GetChildNodes +// PR_STATIC_CALLBACK(JSBool) -ReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +NodeGetChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - NS_ASSERTION(2 == argc, "wrong number of arguments"); + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodeIterator* nativeRet; + *rval = JSVAL_NULL; - if (2 == argc) { - // get the arguments - if (JSVAL_IS_OBJECT(argv[0]) && JSVAL_IS_OBJECT(argv[1])) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - JSObject *obj2 = JSVAL_TO_OBJECT(argv[1]); - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); - nsISupports *support2 = (nsISupports*)JS_GetPrivate(cx, obj2); - NS_ASSERTION(nsnull != support2, "null pointer"); - nsIDOMNode *node1 = nsnull; - nsIDOMNode *node2 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMNodeIID, (void**)&node1)) { - if (NS_OK == support2->QueryInterface(kIDOMNodeIID, (void**)&node2)) { + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } - // call the function - if (NS_OK == node->ReplaceChild(node1, node2)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == node2->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - } - NS_RELEASE(node2); + if (argc >= 0) { + + if (NS_OK != nativeThis->GetChildNodes(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); } - NS_RELEASE(node1); + NS_RELEASE(owner); } + NS_RELEASE(nativeRet); } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method HasChildNodes +// PR_STATIC_CALLBACK(JSBool) -RemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +NodeHasChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNode *node = (nsIDOMNode*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != node, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRBool nativeRet; + *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->HasChildNodes(&nativeRet)) { + return JS_FALSE; + } + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetFirstChild +// +PR_STATIC_CALLBACK(JSBool) +NodeGetFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetFirstChild(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetPreviousSibling +// +PR_STATIC_CALLBACK(JSBool) +NodeGetPreviousSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetPreviousSibling(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetNextSibling +// +PR_STATIC_CALLBACK(JSBool) +NodeGetNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetNextSibling(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method InsertBefore +// +PR_STATIC_CALLBACK(JSBool) +NodeInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodePtr b0; + nsIDOMNodePtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + if (JSVAL_IS_OBJECT(argv[0])) { - JSObject *obj1 = JSVAL_TO_OBJECT(argv[0]); - //XXX should check if that's a good class (do not just GetPrivate) - nsISupports *support1 = (nsISupports*)JS_GetPrivate(cx, obj1); - NS_ASSERTION(nsnull != support1, "null pointer"); + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); - nsIDOMNode *node1 = nsnull; - if (NS_OK == support1->QueryInterface(kIDOMNodeIID, (void**)&node1)) { - - // call the function - if (NS_OK == node->RemoveChild(node1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == node1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - } - NS_RELEASE(node1); + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) { + return JS_FALSE; } } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (JSVAL_IS_OBJECT(argv[1])) { + nsISupports *supports1 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[1])); + NS_ASSERTION(nsnull != supports1, "null pointer"); + + if ((nsnull == supports1) || + (NS_OK != supports1->QueryInterface(kINodeIID, (void **)(b1.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[1])){ + b1 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->InsertBefore(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method ReplaceChild +// +PR_STATIC_CALLBACK(JSBool) +NodeReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodePtr b0; + nsIDOMNodePtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (JSVAL_IS_OBJECT(argv[1])) { + nsISupports *supports1 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[1])); + NS_ASSERTION(nsnull != supports1, "null pointer"); + + if ((nsnull == supports1) || + (NS_OK != supports1->QueryInterface(kINodeIID, (void **)(b1.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[1])){ + b1 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ReplaceChild(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method RemoveChild +// +PR_STATIC_CALLBACK(JSBool) +NodeRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodePtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (NS_OK != nativeThis->RemoveChild(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM Node +// class for Node // -JSClass node = { +JSClass NodeClass = { "Node", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetNodeProperty, + JS_PropertyStub, + JS_PropertyStub, + GetNodeProperty, SetNodeProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateNode, + ResolveNode, + JS_ConvertStub, FinalizeNode }; -// -// Node property ids -// // // Node class properties // +static JSPropertySpec NodeProperties[] = +{ + {0} +}; + // // Node class methods // -static JSFunctionSpec nodeMethods[] = { - {"getNodeType", GetNodeType, 0}, - {"getParentNode", GetParentNode, 0}, - {"getChildNodes", GetChildNodes, 0}, - {"hasChildNodes", HasChildNodes, 0}, - {"getFirstChild", GetFirstChild, 0}, - {"getPreviousSibling", GetPreviousSibling, 0}, - {"getNextSibling", GetNextSibling, 0}, - {"insertBefore", InsertBefore, 2}, - {"replaceChild", ReplaceChild, 2}, - {"removeChild", RemoveChild, 1}, +static JSFunctionSpec NodeMethods[] = +{ + {"getNodeType", NodeGetNodeType, 0}, + {"getParentNode", NodeGetParentNode, 0}, + {"getChildNodes", NodeGetChildNodes, 0}, + {"hasChildNodes", NodeHasChildNodes, 0}, + {"getFirstChild", NodeGetFirstChild, 0}, + {"getPreviousSibling", NodeGetPreviousSibling, 0}, + {"getNextSibling", NodeGetNextSibling, 0}, + {"insertBefore", NodeInsertBefore, 2}, + {"replaceChild", NodeReplaceChild, 2}, + {"removeChild", NodeRemoveChild, 1}, {0} }; + // // Node constructor // @@ -451,98 +709,116 @@ Node(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Node static property ids -// // -// Node static properties +// Node class initialization // - -// -// Node static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitNodeClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; - JSObject *global = JS_GetGlobalObject(aContext); + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - proto = JS_InitClass(aContext, // context - global, // global object - NULL, // parent proto - &node, // JSClass - Node, // JSNative ctor - 0, // ctor args - NULL, // proto props - nodeMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Node", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &NodeClass, // JSClass + Node, // JSNative ctor + 0, // ctor args + NodeProperties, // proto props + NodeMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } - jsval vp; - if (PR_TRUE == JS_GetProperty(aContext, global, node.name, &vp)) { - if (JSVAL_IS_OBJECT(vp)) { - jsval value = INT_TO_JSVAL(1); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "DOCUMENT", &value); - value = INT_TO_JSVAL(2); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "ELEMENT", &value); - value = INT_TO_JSVAL(3); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "ATTRIBUTE", &value); - value = INT_TO_JSVAL(4); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "PI", &value); - value = INT_TO_JSVAL(5); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "COMMENT", &value); - value = INT_TO_JSVAL(6); - JS_SetProperty(aContext, JSVAL_TO_OBJECT(vp), "TEXT", &value); - } + if ((PR_TRUE == JS_LookupProperty(jscontext, global, "Node", &vp)) && + JSVAL_IS_OBJECT(vp) && + ((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) { + vp = INT_TO_JSVAL(nsIDOMNode::DOCUMENT); + JS_SetProperty(jscontext, constructor, "DOCUMENT", &vp); + + vp = INT_TO_JSVAL(nsIDOMNode::ELEMENT); + JS_SetProperty(jscontext, constructor, "ELEMENT", &vp); + + vp = INT_TO_JSVAL(nsIDOMNode::ATTRIBUTE); + JS_SetProperty(jscontext, constructor, "ATTRIBUTE", &vp); + + vp = INT_TO_JSVAL(nsIDOMNode::PI); + JS_SetProperty(jscontext, constructor, "PI", &vp); + + vp = INT_TO_JSVAL(nsIDOMNode::COMMENT); + JS_SetProperty(jscontext, constructor, "COMMENT", &vp); + + vp = INT_TO_JSVAL(nsIDOMNode::TEXT); + JS_SetProperty(jscontext, constructor, "TEXT", &vp); + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// Node instance property ids -// // -// Node instance properties +// Method for creating a new Node JavaScript object // - -// -// New a node object in js, connect the native and js worlds -// -nsresult NS_NewScriptNode(JSContext *aContext, nsIDOMNode *aNode, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aNode && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNode"); JSObject *proto; - NS_InitNodeClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &node, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &NodeClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aNode); - aNode->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSNodeIterator.cpp b/mozilla/dom/src/nsJSNodeIterator.cpp index 6a938be8707..ebb92dc9381 100644 --- a/mozilla/dom/src/nsJSNodeIterator.cpp +++ b/mozilla/dom/src/nsJSNodeIterator.cpp @@ -15,322 +15,527 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMIterators.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMNodeIterator.h" #include "nsIDOMNode.h" -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); + static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); + +NS_DEF_PTR(nsIDOMNodeIterator); +NS_DEF_PTR(nsIDOMNode); + /***********************************************************************/ - // -// NodeIterator properties getter +// NodeIterator Properties Getter // PR_STATIC_CALLBACK(JSBool) GetNodeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != nodeIterator, "null pointer"); + nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == nodeIterator->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// NodeIterator properties setter +// NodeIterator Properties Setter // PR_STATIC_CALLBACK(JSBool) SetNodeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); + nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: //this is just to keep the compiler from issuing a warning - //that there is a switch with only a default case. MMP - default: - nsIScriptObject *object; - if (NS_OK == nodeIterator->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } } } } - return JS_TRUE; + return PR_TRUE; } + // // NodeIterator finalizer // PR_STATIC_CALLBACK(void) FinalizeNodeIterator(JSContext *cx, JSObject *obj) { - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - if (nsnull != nodeIterator) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == nodeIterator->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - nodeIterator->Release(); + NS_RELEASE(a); } } -/***********************************************************************/ + // -// JS->Native functions +// NodeIterator enumerate // PR_STATIC_CALLBACK(JSBool) -SetFilter(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateNodeIterator(JSContext *cx, JSObject *obj) { - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - - PRUint32 length = 0; - // call the function - if (NS_OK == nodeIterator->GetLength(&length)) { - // set the return value - *rval = INT_TO_JSVAL(length); - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -GetCurrentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->GetCurrentNode(&aNode1)) { - + nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); } - NS_RELEASE(aNode1); } - return JS_TRUE; } + +// +// NodeIterator resolve +// PR_STATIC_CALLBACK(JSBool) -GetNextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +ResolveNodeIterator(JSContext *cx, JSObject *obj, jsval id) { - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->GetNextNode(&aNode1)) { - + nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); } - NS_RELEASE(aNode1); + } + return JS_TRUE; +} + + +// +// Native method GetLength +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorGetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRUint32 nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetLength(&nativeRet)) { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method GetCurrentNode +// PR_STATIC_CALLBACK(JSBool) -GetPreviousNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +NodeIteratorGetCurrentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + *rval = JSVAL_NULL; - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->GetPreviousNode(&aNode1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(aNode1); + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; } - return JS_TRUE; -} + if (argc >= 0) { -PR_STATIC_CALLBACK(JSBool) -ToFirst(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->ToFirst(&aNode1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + if (NS_OK != nativeThis->GetCurrentNode(&nativeRet)) { + return JS_FALSE; } - NS_RELEASE(aNode1); - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -ToLast(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - *rval = JSVAL_NULL; - - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->ToLast(&aNode1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); - } - NS_RELEASE(aNode1); - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -MoveTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMNodeIterator *nodeIterator = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != nodeIterator, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - *rval = JSVAL_NULL; - if (1 == argc) { - // get the arguments - if (JSVAL_IS_INT(argv[0])) { - - nsIDOMNode *aNode1 = nsnull; - // call the function - if (NS_OK == nodeIterator->MoveTo(JSVAL_TO_INT(argv[0]), &aNode1)) { - - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == aNode1->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *rval = OBJECT_TO_JSVAL(object); - } - NS_RELEASE(owner); + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); } - NS_RELEASE(aNode1); + NS_RELEASE(owner); } + NS_RELEASE(nativeRet); } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; } return JS_TRUE; } + +// +// Native method GetNextNode +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorGetNextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetNextNode(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method GetPreviousNode +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorGetPreviousNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->GetPreviousNode(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToFirst +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorToFirst(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToFirst(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToLast +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorToLast(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToLast(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method MoveTo +// +PR_STATIC_CALLBACK(JSBool) +NodeIteratorMoveTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + PRInt32 b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->MoveTo(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// the jscript class for a DOM NodeIterator +// class for NodeIterator // -JSClass nodeIterator = { +JSClass NodeIteratorClass = { "NodeIterator", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetNodeIteratorProperty, + JS_PropertyStub, + JS_PropertyStub, + GetNodeIteratorProperty, SetNodeIteratorProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateNodeIterator, + ResolveNodeIterator, + JS_ConvertStub, FinalizeNodeIterator }; -// -// NodeIterator property ids -// // // NodeIterator class properties // +static JSPropertySpec NodeIteratorProperties[] = +{ + {0} +}; + // // NodeIterator class methods // -static JSFunctionSpec nodeIteratorMethods[] = { - {"setFilter", SetFilter, 2}, - {"getLength", GetLength, 0}, - {"getCurrentNode", GetCurrentNode, 0}, - {"getNextNode", GetNextNode, 0}, - {"getPreviousNode", GetPreviousNode, 0}, - {"toFirst", ToFirst, 0}, - {"toLast", ToLast, 0}, - {"moveTo", MoveTo, 1}, +static JSFunctionSpec NodeIteratorMethods[] = +{ + {"getLength", NodeIteratorGetLength, 0}, + {"getCurrentNode", NodeIteratorGetCurrentNode, 0}, + {"getNextNode", NodeIteratorGetNextNode, 0}, + {"getPreviousNode", NodeIteratorGetPreviousNode, 0}, + {"toFirst", NodeIteratorToFirst, 0}, + {"toLast", NodeIteratorToLast, 0}, + {"moveTo", NodeIteratorMoveTo, 1}, {0} }; + // // NodeIterator constructor // @@ -340,79 +545,93 @@ NodeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// NodeIterator static property ids -// // -// NodeIterator static properties +// NodeIterator class initialization // - -// -// NodeIterator static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitNodeIteratorClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitNodeIteratorClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - NULL, // parent proto - &nodeIterator, // JSClass - NodeIterator, // JSNative ctor - 0, // ctor args - NULL, // proto props - nodeIteratorMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "NodeIterator", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &NodeIteratorClass, // JSClass + NodeIterator, // JSNative ctor + 0, // ctor args + NodeIteratorProperties, // proto props + NodeIteratorMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - return NS_OK; } -// -// NodeIterator instance property ids -// // -// NodeIterator instance properties +// Method for creating a new NodeIterator JavaScript object // - -// -// New a nodeIterator object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptNodeIterator(JSContext *aContext, nsIDOMNodeIterator *aNodeIterator, JSObject *aParent, JSObject **aJSObject) +extern "C" NS_DOM NS_NewScriptNodeIterator(nsIScriptContext *aContext, nsIDOMNodeIterator *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aNodeIterator && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNodeIterator"); JSObject *proto; - NS_InitNodeIteratorClass(aContext, &proto); + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitNodeIteratorClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } // create a js object for this class - *aJSObject = JS_NewObject(aContext, &nodeIterator, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - + *aReturn = JS_NewObject(jscontext, &NodeIteratorClass, proto, parent); + if (nsnull != *aReturn) { // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aNodeIterator); - aNodeIterator->AddRef(); + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; } - else return NS_ERROR_FAILURE; return NS_OK; } - diff --git a/mozilla/dom/src/nsJSPI.cpp b/mozilla/dom/src/nsJSPI.cpp new file mode 100644 index 00000000000..92bbef71825 --- /dev/null +++ b/mozilla/dom/src/nsJSPI.cpp @@ -0,0 +1,367 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMPI.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIPIIID, NS_IDOMPI_IID); + +NS_DEF_PTR(nsIDOMPI); + +// +// PI property ids +// +enum PI_slots { + PI_NAME = -11, + PI_DATA = -12 +}; + +/***********************************************************************/ +// +// PI Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case PI_NAME: + { + nsAutoString prop; + if (NS_OK == a->GetName(prop)) { + JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length()); + // set the return value + *vp = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; + } + break; + } + case PI_DATA: + { + nsAutoString prop; + if (NS_OK == a->GetData(prop)) { + JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length()); + // set the return value + *vp = STRING_TO_JSVAL(jsstring); + } + else { + return JS_FALSE; + } + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// PI Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case PI_NAME: + { + nsAutoString prop; + JSString *jsstring; + if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) { + prop.SetString(JS_GetStringChars(jsstring)); + } + else { + prop.SetString((const char *)nsnull); + } + + a->SetName(prop); + + break; + } + case PI_DATA: + { + nsAutoString prop; + JSString *jsstring; + if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) { + prop.SetString(JS_GetStringChars(jsstring)); + } + else { + prop.SetString((const char *)nsnull); + } + + a->SetData(prop); + + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// PI finalizer +// +PR_STATIC_CALLBACK(void) +FinalizePI(JSContext *cx, JSObject *obj) +{ + nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// PI enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumeratePI(JSContext *cx, JSObject *obj) +{ + nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// PI resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolvePI(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for PI +// +JSClass PIClass = { + "PI", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetPIProperty, + SetPIProperty, + EnumeratePI, + ResolvePI, + JS_ConvertStub, + FinalizePI +}; + + +// +// PI class properties +// +static JSPropertySpec PIProperties[] = +{ + {"name", PI_NAME, JSPROP_ENUMERATE}, + {"data", PI_DATA, JSPROP_ENUMERATE}, + {0} +}; + + +// +// PI class methods +// +static JSFunctionSpec PIMethods[] = +{ + {0} +}; + + +// +// PI constructor +// +PR_STATIC_CALLBACK(JSBool) +PI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// PI class initialization +// +nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "PI", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &PIClass, // JSClass + PI, // JSNative ctor + 0, // ctor args + PIProperties, // proto props + PIMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new PI JavaScript object +// +extern "C" NS_DOM NS_NewScriptPI(nsIScriptContext *aContext, nsIDOMPI *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptPI"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitPIClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &PIClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSText.cpp b/mozilla/dom/src/nsJSText.cpp index edcc880f341..36653ae5cab 100644 --- a/mozilla/dom/src/nsJSText.cpp +++ b/mozilla/dom/src/nsJSText.cpp @@ -15,238 +15,471 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" #include "nscore.h" -#include "nsIScriptObject.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIDOMText.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMElement.h" +#include "nsIDOMText.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID); + +NS_DEF_PTR(nsIDOMElement); +NS_DEF_PTR(nsIDOMText); // // Text property ids // -enum text_slot { - TEXT_DATA = -1 +enum Text_slots { + TEXT_DATA = -11 }; /***********************************************************************/ - // -// Text properties getter +// Text Properties Getter // PR_STATIC_CALLBACK(JSBool) GetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - // NS_ASSERTION(nsnull != text, "null pointer"); + nsIDOMText *a = (nsIDOMText*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case TEXT_DATA: { - nsAutoString string; - if (NS_OK == text->GetData(string)) { - JSString *jsstring = JS_NewUCStringCopyN(cx, string, string.Length()); + nsAutoString prop; + if (NS_OK == a->GetData(prop)) { + JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length()); // set the return value *vp = STRING_TO_JSVAL(jsstring); } - } - default: - { - nsIScriptObject *object; - if (NS_OK == text->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->GetProperty(cx, id, vp); - } - } - } - } - - return JS_TRUE; -} - -// -// Text properties setter -// -PR_STATIC_CALLBACK(JSBool) -SetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) -{ - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != text, "null pointer"); - - if (JSVAL_IS_INT(id)) { - switch(JSVAL_TO_INT(id)) { - case TEXT_DATA: - { - if (JSVAL_IS_STRING(*vp)) { - JSString *jsstring = JSVAL_TO_STRING(*vp); - nsAutoString string = JS_GetStringChars(jsstring); - text->SetData(string); + else { + return JS_FALSE; } break; } default: { - nsIScriptObject *object; - if (NS_OK == text->QueryInterface(kIScriptObjectIID, (void**)&object)) { - return object->SetProperty(cx, id, vp); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; } } } } - return JS_TRUE; + return PR_TRUE; } +/***********************************************************************/ // -// Finalize Text +// Text Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMText *a = (nsIDOMText*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case TEXT_DATA: + { + nsAutoString prop; + JSString *jsstring; + if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) { + prop.SetString(JS_GetStringChars(jsstring)); + } + else { + prop.SetString((const char *)nsnull); + } + + a->SetData(prop); + + break; + } + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// Text finalizer // PR_STATIC_CALLBACK(void) FinalizeText(JSContext *cx, JSObject *obj) { - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); + nsIDOMText *a = (nsIDOMText*)JS_GetPrivate(cx, obj); - if (nsnull != text) { + if (nsnull != a) { // get the js object nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == text->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { owner->ResetScriptObject(); NS_RELEASE(owner); } - text->Release(); + NS_RELEASE(a); } } + +// +// Text enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateText(JSContext *cx, JSObject *obj) +{ + nsIDOMText *a = (nsIDOMText*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Text resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveText(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMText *a = (nsIDOMText*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method Append +// +PR_STATIC_CALLBACK(JSBool) +TextAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->Append(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Insert +// +PR_STATIC_CALLBACK(JSBool) +TextInsert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRInt32 b0; + nsAutoString b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + JSString *jsstring1 = JS_ValueToString(cx, argv[1]); + if (nsnull != jsstring1) { + b1.SetString(JS_GetStringChars(jsstring1)); + } + else { + b1.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->Insert(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Delete +// +PR_STATIC_CALLBACK(JSBool) +TextDelete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRInt32 b0; + PRInt32 b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->Delete(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Replace +// +PR_STATIC_CALLBACK(JSBool) +TextReplace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRInt32 b0; + PRInt32 b1; + nsAutoString b2; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 3) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) { + return JS_FALSE; + } + + JSString *jsstring2 = JS_ValueToString(cx, argv[2]); + if (nsnull != jsstring2) { + b2.SetString(JS_GetStringChars(jsstring2)); + } + else { + b2.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->Replace(b0, b1, b2)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method Splice +// +PR_STATIC_CALLBACK(JSBool) +TextSplice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMElementPtr b0; + PRInt32 b1; + PRInt32 b2; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 3) { + + if (JSVAL_IS_OBJECT(argv[0])) { + nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + NS_ASSERTION(nsnull != supports0, "null pointer"); + + if ((nsnull == supports0) || + (NS_OK != supports0->QueryInterface(kIElementIID, (void **)(b0.Query())))) { + return JS_FALSE; + } + } + else if (JSVAL_IS_NULL(argv[0])){ + b0 = nsnull; + } + else { + return JS_FALSE; + } + + if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) { + return JS_FALSE; + } + + if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->Splice(b0, b1, b2)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + /***********************************************************************/ // -// JS->Native functions +// class for Text // -PR_STATIC_CALLBACK(JSBool) -Append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != text, "null pointer"); - NS_ASSERTION(1 == argc, "wrong number of arguments"); - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - nsAutoString string1 = JS_GetStringChars(jsstring1); - - // call the function - text->Append(string1); - } - } - - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != text, "null pointer"); - NS_ASSERTION(2 == argc, "wrong number of arguments"); - if (2 == argc) { - // get the arguments - if (JSVAL_IS_INT(argv[0]) && - JSVAL_IS_STRING(argv[1])) { - JSString *jsstring2 = JSVAL_TO_STRING(argv[1]); - nsAutoString string2 = JS_GetStringChars(jsstring2); - - // call the function - text->Insert(JSVAL_TO_INT(argv[0]), string2); - } - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Delete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != text, "null pointer"); - NS_ASSERTION(2 == argc, "wrong number of arguments"); - if (2 == argc) { - // get the arguments - if (JSVAL_IS_INT(argv[0]) && JSVAL_IS_INT(argv[1])) { - // call the function - text->Delete(JSVAL_TO_INT(argv[0]), JSVAL_TO_INT(argv[1])); - } - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != text, "null pointer"); - NS_ASSERTION(3 == argc, "wrong number of arguments"); - if (3 == argc) { - // get the arguments - if (JSVAL_IS_INT(argv[0]) && - JSVAL_IS_INT(argv[1]) && - JSVAL_IS_STRING(argv[2])) { - JSString *jsstring3 = JSVAL_TO_STRING(argv[2]); - nsAutoString string3 = JS_GetStringChars(jsstring3); - - // call the function - text->Replace(JSVAL_TO_INT(argv[0]), JSVAL_TO_INT(argv[1]), string3); - } - } - return JS_TRUE; -} - -PR_STATIC_CALLBACK(JSBool) -Splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - //XXX TBI - return JS_TRUE; -} - -/***********************************************************************/ -// -// the jscript class for a DOM Text -// -JSClass text = { +JSClass TextClass = { "Text", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetTextProperty, + JS_PropertyStub, + JS_PropertyStub, + GetTextProperty, SetTextProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateText, + ResolveText, + JS_ConvertStub, FinalizeText }; + // // Text class properties // -static JSPropertySpec textProperties[] = +static JSPropertySpec TextProperties[] = { - {"data", TEXT_DATA, JSPROP_ENUMERATE}, + {"data", TEXT_DATA, JSPROP_ENUMERATE}, {0} }; + // // Text class methods // -static JSFunctionSpec textMethods[] = { - {"append", Append, 1}, - {"insert", Insert, 2}, - {"remove", Delete, 2}, - {"replace", Replace, 3}, - {"splice", Splice, 3}, +static JSFunctionSpec TextMethods[] = +{ + {"append", TextAppend, 1}, + {"insert", TextInsert, 2}, + {"delete", TextDelete, 2}, + {"replace", TextReplace, 3}, + {"splice", TextSplice, 3}, {0} }; + // // Text constructor // @@ -256,83 +489,96 @@ Text(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Text static property ids -// // -// Text static properties +// Text class initialization // - -// -// Text static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitNodeClass(JSContext *aContext, JSObject **aPrototype); -nsresult NS_InitTextClass(JSContext *aContext, JSObject **aPrototype) +nsresult NS_InitTextClass(nsIScriptContext *aContext, void **aPrototype) { - // look in the global object for this class prototype - static JSObject *proto = nsnull; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; - if (nsnull == proto) { - JSObject *parentProto; - NS_InitNodeClass(aContext, &parentProto); - JSObject *proto; - proto = JS_InitClass(aContext, // context - JS_GetGlobalObject(aContext), // global object - parentProto, // parent proto - &text, // JSClass - Text, // JSNative ctor - 0, // ctor args - textProperties, // proto props - textMethods, // proto funcs - NULL, // ctor props (static) - NULL); // ctor funcs (static) + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Text", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &TextClass, // JSClass + Text, // JSNative ctor + 0, // ctor args + TextProperties, // proto props + TextMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) if (nsnull == proto) { return NS_ERROR_FAILURE; } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; } - if (nsnull != aPrototype) { + if (aPrototype) { *aPrototype = proto; } - - return NS_OK; -} - -// -// Text instance property ids -// - -// -// Text instance properties -// - -// -// New a text object in js, connect the native and js worlds -// -extern "C" NS_DOM nsresult NS_NewScriptText(JSContext *aContext, nsIDOMText *aText, JSObject *aParent, JSObject **aJSObject) -{ - NS_PRECONDITION(nsnull != aContext && nsnull != aText && nsnull != aJSObject, "null arg"); - JSObject *proto; - NS_InitTextClass(aContext, &proto); - - // create a js object for this class - *aJSObject = JS_NewObject(aContext, &text, proto, aParent); - if (nsnull != *aJSObject) { - // define the instance specific properties - - // connect the native object to the js object - JS_SetPrivate(aContext, *aJSObject, aText); - aText->AddRef(); - } - else return NS_ERROR_FAILURE; - return NS_OK; } + +// +// Method for creating a new Text JavaScript object +// +extern "C" NS_DOM NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptText"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitTextClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &TextClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSTreeIterator.cpp b/mozilla/dom/src/nsJSTreeIterator.cpp new file mode 100644 index 00000000000..918eaaf2bb9 --- /dev/null +++ b/mozilla/dom/src/nsJSTreeIterator.cpp @@ -0,0 +1,708 @@ +/* -*- 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 "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMTreeIterator.h" +#include "nsIDOMNode.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kITreeIteratorIID, NS_IDOMTREEITERATOR_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); + +NS_DEF_PTR(nsIDOMTreeIterator); +NS_DEF_PTR(nsIDOMNode); + + +/***********************************************************************/ +// +// TreeIterator Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetTreeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// TreeIterator Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetTreeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + { + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); + NS_RELEASE(object); + return rval; + } + } + } + } + + return PR_TRUE; +} + + +// +// TreeIterator finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeTreeIterator(JSContext *cx, JSObject *obj) +{ + nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + owner->ResetScriptObject(); + NS_RELEASE(owner); + } + + NS_RELEASE(a); + } +} + + +// +// TreeIterator enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateTreeIterator(JSContext *cx, JSObject *obj) +{ + nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// TreeIterator resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveTreeIterator(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method NumChildren +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorNumChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRUint32 nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->NumChildren(&nativeRet)) { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method NumPreviousSiblings +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorNumPreviousSiblings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRUint32 nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->NumPreviousSiblings(&nativeRet)) { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method NumNextSiblings +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorNumNextSiblings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRUint32 nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->NumNextSiblings(&nativeRet)) { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToParent +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToParent(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToPreviousSibling +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToPreviousSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToPreviousSibling(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToNextSibling +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToNextSibling(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToFirstChild +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToFirstChild(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToLastChild +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToLastChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 0) { + + if (NS_OK != nativeThis->ToLastChild(&nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +// +// Native method ToNthChild +// +PR_STATIC_CALLBACK(JSBool) +TreeIteratorToNthChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNode* nativeRet; + PRInt32 b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ToNthChild(b0, &nativeRet)) { + return JS_FALSE; + } + + if (nativeRet != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *rval = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); + } + NS_RELEASE(nativeRet); + } + else { + *rval = JSVAL_NULL; + } + } + else { + return JS_FALSE; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for TreeIterator +// +JSClass TreeIteratorClass = { + "TreeIterator", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetTreeIteratorProperty, + SetTreeIteratorProperty, + EnumerateTreeIterator, + ResolveTreeIterator, + JS_ConvertStub, + FinalizeTreeIterator +}; + + +// +// TreeIterator class properties +// +static JSPropertySpec TreeIteratorProperties[] = +{ + {0} +}; + + +// +// TreeIterator class methods +// +static JSFunctionSpec TreeIteratorMethods[] = +{ + {"numChildren", TreeIteratorNumChildren, 0}, + {"numPreviousSiblings", TreeIteratorNumPreviousSiblings, 0}, + {"numNextSiblings", TreeIteratorNumNextSiblings, 0}, + {"toParent", TreeIteratorToParent, 0}, + {"toPreviousSibling", TreeIteratorToPreviousSibling, 0}, + {"toNextSibling", TreeIteratorToNextSibling, 0}, + {"toFirstChild", TreeIteratorToFirstChild, 0}, + {"toLastChild", TreeIteratorToLastChild, 0}, + {"toNthChild", TreeIteratorToNthChild, 1}, + {0} +}; + + +// +// TreeIterator constructor +// +PR_STATIC_CALLBACK(JSBool) +TreeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + return JS_TRUE; +} + + +// +// TreeIterator class initialization +// +nsresult NS_InitTreeIteratorClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "TreeIterator", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitNodeIteratorClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &TreeIteratorClass, // JSClass + TreeIterator, // JSNative ctor + 0, // ctor args + TreeIteratorProperties, // proto props + TreeIteratorMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new TreeIterator JavaScript object +// +extern "C" NS_DOM NS_NewScriptTreeIterator(nsIScriptContext *aContext, nsIDOMTreeIterator *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptTreeIterator"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitTreeIteratorClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &TreeIteratorClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports); + NS_ADDREF(aSupports); + } + else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/dom/src/nsJSWindow.cpp b/mozilla/dom/src/nsJSWindow.cpp index 268ac48d5f5..2c1157617d3 100644 --- a/mozilla/dom/src/nsJSWindow.cpp +++ b/mozilla/dom/src/nsJSWindow.cpp @@ -19,62 +19,78 @@ #include "jsapi.h" #include "nscore.h" #include "nsIScriptContext.h" -#include "nsIScriptObject.h" +#include "nsIJSScriptObject.h" #include "nsIScriptObjectOwner.h" -#include "nsIWebWidget.h" -#include "nsIDocument.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMDocument.h" +#include "nsIDOMWindow.h" + -static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID); + +NS_DEF_PTR(nsIDOMDocument); +NS_DEF_PTR(nsIDOMWindow); // // Window property ids // -enum window_slot { - WINDOW_DOCUMENT = -1, +enum Window_slots { + WINDOW_DOCUMENT = -11 }; /***********************************************************************/ - // -// Window properties getter +// Window Properties Getter // PR_STATIC_CALLBACK(JSBool) GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIWebWidget *window = (nsIWebWidget*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != window, "null pointer"); + nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + NS_ASSERTION(nsnull != a, "null pointer"); if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { case WINDOW_DOCUMENT: { - nsIDocument *document = window->GetDocument(); - // call the function - if (nsnull != document) { - + nsIDOMDocument* prop; + if (NS_OK == a->GetDocument(&prop)) { // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == document->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - JSObject *object = nsnull; - if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) { - // set the return value - *vp = OBJECT_TO_JSVAL(object); + if (prop != nsnull) { + nsIScriptObjectOwner *owner = nsnull; + if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + JSObject *object = nsnull; + nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx); + if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) { + // set the return value + *vp = OBJECT_TO_JSVAL(object); + } + NS_RELEASE(owner); } - NS_RELEASE(owner); + NS_RELEASE(prop); } - NS_RELEASE(document); + else { + *vp = JSVAL_NULL; + } + } + else { + return JS_FALSE; } break; } default: { - nsIScriptObject *object; - if (NS_OK == window->QueryInterface(kIScriptObjectIID, (void**)&object)) { - PRBool ret = object->GetProperty(cx, id, vp); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->GetProperty(cx, id, vp); NS_RELEASE(object); - return ret; + return rval; } } } @@ -83,28 +99,27 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) return PR_TRUE; } +/***********************************************************************/ // -// Window properties setter +// Window Properties Setter // PR_STATIC_CALLBACK(JSBool) SetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIWebWidget *window = (nsIWebWidget*)JS_GetPrivate(cx, obj); - NS_ASSERTION(nsnull != window, "null pointer"); + nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + NS_ASSERTION(nsnull != a, "null pointer"); if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case WINDOW_DOCUMENT: - { - break; - } + case 0: default: { - nsIScriptObject *object; - if (NS_OK == window->QueryInterface(kIScriptObjectIID, (void**)&object)) { - PRBool ret = object->SetProperty(cx, id, vp); + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + PRBool rval; + rval = object->SetProperty(cx, id, vp); NS_RELEASE(object); - return ret; + return rval; } } } @@ -113,81 +128,130 @@ SetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) return PR_TRUE; } + // // Window finalizer // PR_STATIC_CALLBACK(void) FinalizeWindow(JSContext *cx, JSObject *obj) { - /* - nsIWebWidget *window = (nsIWebWidget*)JS_GetPrivate(cx, obj); - - if (nsnull != window) { - // get the js object - nsIScriptObjectOwner *owner = nsnull; - if (NS_OK == window->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { - owner->ResetScriptObject(); - NS_RELEASE(owner); - } - } - */ } -/***********************************************************************/ + // -// JS->Native functions +// Window enumerate // PR_STATIC_CALLBACK(JSBool) -Dump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +EnumerateWindow(JSContext *cx, JSObject *obj) { - NS_ASSERTION(1 == argc, "wrong number of arguments"); - if (1 == argc) { - // get the arguments - if (JSVAL_IS_STRING(argv[0])) { - JSString *jsstring1 = JSVAL_TO_STRING(argv[0]); - char *print = JS_GetStringBytes(jsstring1); - printf("%s", print); - //delete print; + nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->EnumerateProperty(cx); + NS_RELEASE(object); } } + return JS_TRUE; +} + + +// +// Window resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveWindow(JSContext *cx, JSObject *obj, jsval id) +{ + nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + + if (nsnull != a) { + // get the js object + nsIJSScriptObject *object; + if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) { + object->Resolve(cx, id); + NS_RELEASE(object); + } + } + return JS_TRUE; +} + + +// +// Native method Dump +// +PR_STATIC_CALLBACK(JSBool) +WindowDump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + NS_ASSERTION(nsnull != nativeThis, "null pointer"); + JSBool rBool = JS_FALSE; + nsAutoString b0; + + *rval = JSVAL_NULL; + if (argc >= 1) { + + JSString *jsstring0 = JS_ValueToString(cx, argv[0]); + if (nsnull != jsstring0) { + b0.SetString(JS_GetStringChars(jsstring0)); + } + else { + b0.SetString(""); // Should this really be null?? + } + + if (NS_OK != nativeThis->Dump(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + return JS_FALSE; + } return JS_TRUE; } + /***********************************************************************/ // -// the jscript class for a DOM Window +// class for Window // -JSClass window = { +JSClass WindowClass = { "Window", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, - JS_PropertyStub, - GetWindowProperty, + JS_PropertyStub, + JS_PropertyStub, + GetWindowProperty, SetWindowProperty, - JS_EnumerateStub, - JS_ResolveStub, - JS_ConvertStub, + EnumerateWindow, + ResolveWindow, + JS_ConvertStub, FinalizeWindow }; + // // Window class properties // -static JSPropertySpec windowProperties[] = +static JSPropertySpec WindowProperties[] = { - {"document", WINDOW_DOCUMENT, JSPROP_ENUMERATE}, + {"document", WINDOW_DOCUMENT, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; + // // Window class methods // -static JSFunctionSpec windowMethods[] = { - {"dump", Dump, 1}, +static JSFunctionSpec WindowMethods[] = +{ + {"dump", WindowDump, 1}, {0} }; + // // Window constructor // @@ -197,47 +261,32 @@ Window(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } -// -// Window static property ids -// // -// Window static properties +// Window class initialization // - -// -// Window static methods -// - -/***********************************************************************/ - -// -// Init this object class -// -nsresult NS_InitWindowClass(JSContext *aContext, JSObject *aGlobalObject) +nsresult NS_InitWindowClass(nsIScriptContext *aContext, + nsIScriptGlobalObject *aGlobal) { - // look in the global object for this class prototype - JS_DefineProperties(aContext, aGlobalObject, windowProperties); - JS_DefineFunctions(aContext, aGlobalObject, windowMethods); + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *global = JS_GetGlobalObject(jscontext); + + JS_DefineProperties(jscontext, global, WindowProperties); + JS_DefineFunctions(jscontext, global, WindowMethods); + return NS_OK; } -// -// Window instance property ids -// // -// Window instance properties +// Method for creating a new Window JavaScript object // - -// -// New a Window object in js, connect the native and js worlds -// -nsresult NS_NewGlobalWindow(JSContext *aContext, nsIWebWidget *aWindow, void **aJSObject) +extern "C" NS_DOM NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn) { - NS_PRECONDITION(nsnull != aContext && nsnull != aWindow && nsnull != aJSObject, "null arg"); + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null arg"); + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); - JSObject *global = ::JS_NewObject(aContext, &window, NULL, NULL); + JSObject *global = ::JS_NewObject(jscontext, &WindowClass, NULL, NULL); if (global) { // The global object has a to be defined in two step: // 1- create a generic object, with no prototype and no parent which @@ -250,13 +299,11 @@ nsresult NS_NewGlobalWindow(JSContext *aContext, nsIWebWidget *aWindow, void **a // after JS_InitStandardClasses // assign "this" to the js object, don't AddRef - ::JS_SetPrivate(aContext, global, aWindow); - - *aJSObject = (void*)global; + ::JS_SetPrivate(jscontext, global, aSupports); + *aReturn = (void*)global; return NS_OK; } - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } - diff --git a/mozilla/dom/tests/js/DumpHTML.js b/mozilla/dom/tests/js/DumpHTML.js index a2aedf9fcbf5b01d61d2041e6a4b0e51e7f877eb..dcea53d624b69b32c212ea4c516b445bc4a0b513 100644 GIT binary patch delta 73 zcmaFKzgS>{1G}vP5Tumm7HBBh=qo8`E9B*;r0S)omV_jx`z7Y4YG?w*l 4) { + strcpy(aString, "void"); + } + break; } } diff --git a/mozilla/dom/tools/JSStubGen.cpp b/mozilla/dom/tools/JSStubGen.cpp index c76116198d5..41402a76245 100644 --- a/mozilla/dom/tools/JSStubGen.cpp +++ b/mozilla/dom/tools/JSStubGen.cpp @@ -75,11 +75,12 @@ JSStubGen::Generate(char *aFileName, static const char *kIncludeDefaultsStr = "\n" "#include \"jsapi.h\"\n" "#include \"nscore.h\"\n" -"#include \"nsIScriptObject.h\"\n" +"#include \"nsIScriptContext.h\"\n" +"#include \"nsIJSScriptObject.h\"\n" "#include \"nsIScriptObjectOwner.h\"\n" +"#include \"nsIScriptGlobalObject.h\"\n" "#include \"nsIPtr.h\"\n" -"#include \"nsString.h\"\n" -"#include \"nsIJSGlobalObject.h\"\n"; +"#include \"nsString.h\"\n"; static const char *kIncludeStr = "#include \"nsIDOM%s.h\"\n"; static PRIntn @@ -107,8 +108,8 @@ JSStubGen::GenerateIncludes(IdlSpecification &aSpec) static const char *kIIDDefaultStr = "\n" "static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);\n" -"static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID);\n" -"static NS_DEFINE_IID(kIJSGlobalObjectIID, NS_IJSGLOBALOBJECT_IID);\n"; +"static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);\n" +"static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);\n"; static const char *kIIDStr = "static NS_DEFINE_IID(kI%sIID, %s);\n"; PRIntn @@ -218,7 +219,11 @@ static const char *kPropFuncBeginStr = "\n" "%s%sProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)\n" "{\n" " nsIDOM%s *a = (nsIDOM%s*)JS_GetPrivate(cx, obj);\n" -" NS_ASSERTION(nsnull != a, \"null pointer\");\n" +"\n" +" // If there's no private data, this must be the prototype, so ignore\n" +" if (nsnull == a) {\n" +" return JS_TRUE;\n" +" }\n" "\n" " if (JSVAL_IS_INT(id)) {\n" " switch(JSVAL_TO_INT(id)) {\n"; @@ -226,8 +231,8 @@ static const char *kPropFuncBeginStr = "\n" static const char *kPropFuncEndStr = " default:\n" " {\n" -" nsIScriptObject *object;\n" -" if (NS_OK == a->QueryInterface(kIScriptObjectIID, (void**)&object)) {\n" +" nsIJSScriptObject *object;\n" +" if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {\n" " PRBool rval;\n" " rval = object->%sProperty(cx, id, vp);\n" " NS_RELEASE(object);\n" @@ -254,7 +259,7 @@ static const char *kPropCaseEndStr = " break;\n" " }\n"; -static const char *kNoAttrStr = " case 0:"; +static const char *kNoAttrStr = " case 0:\n"; void @@ -346,7 +351,8 @@ static const char *kObjectGetCaseStr = " nsIScriptObjectOwner *owner = nsnull;\n" " if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {\n" " JSObject *object = nsnull;\n" -" if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) {\n" +" nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);\n" +" if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {\n" " // set the return value\n" " *vp = OBJECT_TO_JSVAL(object);\n" " }\n" @@ -588,8 +594,8 @@ static const char *kEnumerateStr = " \n" " if (nsnull != a) {\n" " // get the js object\n" -" nsIScriptObject *object;\n" -" if (NS_OK == a->QueryInterface(kIScriptObjectIID, (void**)&object)) {\n" +" nsIJSScriptObject *object;\n" +" if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {\n" " object->EnumerateProperty(cx);\n" " NS_RELEASE(object);\n" " }\n" @@ -624,8 +630,8 @@ static const char *kResolveStr = " \n" " if (nsnull != a) {\n" " // get the js object\n" -" nsIScriptObject *object;\n" -" if (NS_OK == a->QueryInterface(kIScriptObjectIID, (void**)&object)) {\n" +" nsIJSScriptObject *object;\n" +" if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {\n" " object->Resolve(cx, id);\n" " NS_RELEASE(object);\n" " }\n" @@ -656,7 +662,6 @@ static const char *kMethodBeginStr = "\n\n" "%s%s(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)\n" "{\n" " nsIDOM%s *nativeThis = (nsIDOM%s*)JS_GetPrivate(cx, obj);\n" -" NS_ASSERTION(nsnull != nativeThis, \"null pointer\");\n" " JSBool rBool = JS_FALSE;\n"; static const char *kMethodReturnStr = @@ -666,6 +671,12 @@ static const char *kMethodParamStr = " %s b%d;\n"; static const char *kMethodBodyBeginStr = "\n" " *rval = JSVAL_NULL;\n" +"\n" +" // If there's no private data, this must be the prototype, so ignore\n" +" if (nsnull == nativeThis) {\n" +" return JS_TRUE;\n" +" }\n" +"\n" " if (argc >= %d) {\n"; static const char *kMethodObjectParamStr = "\n" @@ -742,7 +753,8 @@ static const char *kMethodObjectRetStr = " nsIScriptObjectOwner *owner = nsnull;\n" " if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {\n" " JSObject *object = nsnull;\n" -" if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) {\n" +" nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);\n" +" if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {\n" " // set the return value\n" " *rval = OBJECT_TO_JSVAL(object);\n" " }\n" @@ -859,7 +871,9 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec) } if (rval->GetType() != TYPE_VOID) { - strcpy(param_ptr, kMethodParamListDelimiterStr); + if (pcount > 0) { + strcpy(param_ptr, kMethodParamListDelimiterStr); + } sprintf(buf, kMethodBodyMiddleStr, method_name, param_buf, rval->GetType() == TYPE_STRING ? "" : "&"); } @@ -1060,56 +1074,76 @@ static const char *kInitClassBeginStr = "\n\n//\n" "// %s class initialization\n" "//\n" -"nsresult NS_Init%sClass(JSContext *aContext, JSObject **aPrototype)\n" +"nsresult NS_Init%sClass(nsIScriptContext *aContext, void **aPrototype)\n" "{\n" +" JSContext *jscontext = (JSContext *)aContext->GetNativeContext();\n" " JSObject *proto = nsnull;\n" +" JSObject *constructor = nsnull;\n" " JSObject *parent_proto = nsnull;\n" -" JSObject *obj = JS_GetGlobalObject(aContext);\n" -" nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, obj);\n" -" nsIJSGlobalObject *global;\n" +" JSObject *global = JS_GetGlobalObject(jscontext);\n" +" jsval vp;\n" "\n" -" if (NS_OK == supports->QueryInterface(kIJSGlobalObjectIID, (void **)&global)) {\n" -" *aPrototype = global->GetClassPrototype(aContext, \"%s\");\n" -" if (nsnull == *aPrototype) {\n"; +" if ((PR_TRUE != JS_LookupProperty(jscontext, global, \"%s\", &vp)) ||\n" +" !JSVAL_IS_OBJECT(vp) ||\n" +" ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||\n" +" (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), \"prototype\", &vp)) || \n" +" !JSVAL_IS_OBJECT(vp)) {\n\n"; #define JSGEN_GENERATE_INITCLASSBEGIN(buffer, className) \ sprintf(buffer, kInitClassBeginStr, className, className, className) static const char *kGetParentProtoStr = -" if (NS_OK != NS_Init%sClass(aContext, &parent_proto)) {\n" -" return NS_ERROR_FAILURE;\n" -" }\n"; +" if (NS_OK != NS_Init%sClass(aContext, (void **)&parent_proto)) {\n" +" return NS_ERROR_FAILURE;\n" +" }\n"; static const char *kInitClassBodyStr = -" *aPrototype = JS_InitClass(aContext, // context\n" -" obj, // global object\n" -" parent_proto, // parent proto \n" -" &%sClass, // JSClass\n" -" %s, // JSNative ctor\n" -" 0, // ctor args\n" -" %sProperties, // proto props\n" -" %sMethods, // proto funcs\n" -" nsnull, // ctor props (static)\n" -" nsnull); // ctor funcs (static)\n" -" if (nsnull == *aPrototype) {\n" -" NS_RELEASE(global);\n" -" return NS_ERROR_FAILURE;\n" -" }\n" -"\n" -" global->SetClassPrototype(aContext, \"%s\", *aPrototype);\n" +" proto = JS_InitClass(jscontext, // context\n" +" global, // global object\n" +" parent_proto, // parent proto \n" +" &%sClass, // JSClass\n" +" %s, // JSNative ctor\n" +" 0, // ctor args\n" +" %sProperties, // proto props\n" +" %sMethods, // proto funcs\n" +" nsnull, // ctor props (static)\n" +" nsnull); // ctor funcs (static)\n" +" if (nsnull == proto) {\n" +" return NS_ERROR_FAILURE;\n" " }\n" "\n"; #define JSGEN_GENERATE_INITCLASSBODY(buffer, className) \ sprintf(buffer, kInitClassBodyStr, className, className, \ - className, className, className) + className, className) + +static const char *kInitStaticBeginStr = +" if ((PR_TRUE == JS_LookupProperty(jscontext, global, \"%s\", &vp)) &&\n" +" JSVAL_IS_OBJECT(vp) &&\n" +" ((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {\n"; + +static const char *kInitStaticEntryStr = +" vp = INT_TO_JSVAL(nsIDOM%s::%s);\n" +" JS_SetProperty(jscontext, constructor, \"%s\", &vp);\n" +"\n"; + +static const char *kInitStaticEndStr = +" }\n" +"\n"; static const char *kInitClassEndStr = -" return NS_OK;\n" +" }\n" +" else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {\n" +" proto = JSVAL_TO_OBJECT(vp);\n" " }\n" " else {\n" " return NS_ERROR_FAILURE;\n" " }\n" +"\n" +" if (aPrototype) {\n" +" *aPrototype = proto;\n" +" }\n" +" return NS_OK;\n" "}\n"; void @@ -1133,6 +1167,25 @@ JSStubGen::GenerateInitClass(IdlSpecification &aSpec) JSGEN_GENERATE_INITCLASSBODY(buf, primary_class); *file << buf; + int c, ccount = primary_iface->ConstCount(); + + if (ccount > 0) { + sprintf(buf, kInitStaticBeginStr, primary_iface->GetName()); + *file << buf; + + for (c = 0; c < ccount; c++) { + IdlVariable *var = primary_iface->GetConstAt(c); + + if (NULL != var) { + sprintf(buf, kInitStaticEntryStr, primary_iface->GetName(), + var->GetName(), var->GetName()); + *file << buf; + } + } + + *file << kInitStaticEndStr; + } + *file << kInitClassEndStr; } @@ -1141,19 +1194,37 @@ static const char *kNewJSObjectStr = "\n\n//\n" "// Method for creating a new %s JavaScript object\n" "//\n" -"nsresult NS_NewScript%s(JSContext *aContext, nsIDOM%s *aSupports, JSObject *aParent, JSObject **aReturn)\n" +"extern \"C\" NS_DOM NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn)\n" "{\n" " NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, \"null argument to NS_NewScript%s\");\n" " JSObject *proto;\n" -" if (NS_OK != NS_Init%sClass(aContext, &proto)) {\n" +" JSObject *parent;\n" +" nsIScriptObjectOwner *owner;\n" +" JSContext *jscontext = (JSContext *)aContext->GetNativeContext();\n" +"\n" +" if (nsnull == aParent) {\n" +" parent = nsnull;\n" +" }\n" +" else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {\n" +" if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {\n" +" NS_RELEASE(owner);\n" +" return NS_ERROR_FAILURE;\n" +" }\n" +" NS_RELEASE(owner);\n" +" }\n" +" else {\n" +" return NS_ERROR_FAILURE;\n" +" }\n" +"\n" +" if (NS_OK != NS_Init%sClass(aContext, (void **)&proto)) {\n" " return NS_ERROR_FAILURE;\n" " }\n" "\n" " // create a js object for this class\n" -" *aReturn = JS_NewObject(aContext, &%sClass, proto, aParent);\n" +" *aReturn = JS_NewObject(jscontext, &%sClass, proto, parent);\n" " if (nsnull != *aReturn) {\n" " // connect the native object to the js object\n" -" JS_SetPrivate(aContext, *aReturn, aSupports);\n" +" JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);\n" " NS_ADDREF(aSupports);\n" " }\n" " else {\n" diff --git a/mozilla/dom/tools/Makefile.win b/mozilla/dom/tools/Makefile.win index f8156dc4362..a3191afb39b 100644 --- a/mozilla/dom/tools/Makefile.win +++ b/mozilla/dom/tools/Makefile.win @@ -57,6 +57,7 @@ include <$(DEPTH)\config\rules.mak> install:: $(PROGRAM) echo $(OS_CFLAGS) $(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin + $(MAKE_INSTALL) geniid.pl $(DIST)\bin clobber:: rm -f $(DIST)\bin\idlc.exe diff --git a/mozilla/dom/tools/XPCOMGen.cpp b/mozilla/dom/tools/XPCOMGen.cpp index c9b3faa5b5e..121807269fa 100644 --- a/mozilla/dom/tools/XPCOMGen.cpp +++ b/mozilla/dom/tools/XPCOMGen.cpp @@ -36,7 +36,10 @@ static const char *kFileSuffix = "h"; static const char *kIfdefStr = "\n" "#ifndef nsIDOM%s_h__\n" "#define nsIDOM%s_h__\n\n"; -static const char *kIncludeISupportsStr = "#include \"nsISupports.h\"\n"; +static const char *kIncludeDefaultsStr = +"#include \"nsISupports.h\"\n" +"#include \"nsString.h\"\n" +"#include \"nsIScriptContext.h\"\n"; static const char *kIncludeStr = "#include \"nsIDOM%s.h\"\n"; static const char *kForwardClassStr = "class nsIDOM%s;\n"; static const char *kUuidStr = @@ -46,7 +49,9 @@ static const char *kClassDeclStr = "class nsIDOM%s : "; static const char *kBaseClassStr = "public nsIDOM%s"; static const char *kNoBaseClassStr = "public nsISupports"; static const char *kClassPrologStr = " {\npublic:\n"; -static const char *kConstDeclStr = " const %s %s = %l;\n"; +static const char *kEnumDeclBeginStr = " enum {\n"; +static const char *kEnumEntryStr = " %s = %d%s\n"; +static const char *kEnumDeclEndStr = " };\n"; static const char *kGetterMethodDeclStr = "\n NS_IMETHOD Get%s(%s%s a%s)=0;\n"; static const char *kSetterMethodDeclStr = " NS_IMETHOD Set%s(%s a%s)=0;\n"; static const char *kMethodDeclStr = "\n NS_IMETHOD %s(%s)=0;\n"; @@ -54,8 +59,8 @@ static const char *kParamStr = "%s a%s"; static const char *kDelimiterStr = ", "; static const char *kReturnStr = "%s%s aReturn"; static const char *kClassEpilogStr = "};\n\n"; -static const char *kInitClassStr = "extern nsresult NS_Init%sClass(JSContext *aContext, JSObject **aPrototype);\n\n"; -static const char *kNewObjStr = "extern nsresult NS_NewScript%s(JSContext *aContext, nsIDOM%s *aSupports, JSObject *aParent, JSObject **aReturn);\n\n"; +static const char *kInitClassStr = "extern nsresult NS_Init%sClass(nsIScriptContext *aContext, void **aPrototype);\n\n"; +static const char *kNewObjStr = "extern \"C\" NS_DOM NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn);\n\n"; static const char *kEndifStr = "#endif // nsIDOM%s_h__\n"; @@ -88,6 +93,7 @@ XPCOMGen::Generate(char *aFileName, if (iface) { GenerateGuid(*iface); GenerateClassDecl(*iface); + GenerateEnums(*iface); GenerateMethods(*iface); GenerateEndClassDecl(); } @@ -117,7 +123,7 @@ XPCOMGen::GenerateIncludes(IdlSpecification &aSpec) char buf[512]; ofstream *file = GetFile(); - *file << kIncludeISupportsStr; + *file << kIncludeDefaultsStr; int i, icount = aSpec.InterfaceCount(); for (i = 0; i < icount; i++) { IdlInterface *iface = aSpec.GetInterfaceAt(i); @@ -194,6 +200,31 @@ XPCOMGen::GenerateClassDecl(IdlInterface &aInterface) *file << kClassPrologStr; } +void +XPCOMGen::GenerateEnums(IdlInterface &aInterface) +{ + char buf[512]; + ofstream *file = GetFile(); + + if (aInterface.ConstCount() > 0) { + int c, ccount = aInterface.ConstCount(); + + *file << kEnumDeclBeginStr; + + for (c = 0; c < ccount; c++) { + IdlVariable *var = aInterface.GetConstAt(c); + + if (NULL != var) { + sprintf(buf, kEnumEntryStr, var->GetName(), var->GetLongValue(), + ((c < ccount-1) ? "," : "")); + *file << buf; + } + } + + *file << kEnumDeclEndStr; + } +} + void XPCOMGen::GenerateMethods(IdlInterface &aInterface) { @@ -242,7 +273,7 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface) IdlVariable *rval = func->GetReturnValue(); if (rval->GetType() != TYPE_VOID) { - if (p > 0) { + if (pcount > 0) { strcpy(cur_param, kDelimiterStr); cur_param += strlen(kDelimiterStr); } @@ -250,6 +281,9 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface) sprintf(cur_param, kReturnStr, type_buf, rval->GetType() == TYPE_STRING ? "" : "*"); } + else { + *cur_param++ = '\0'; + } GetCapitalizedName(name_buf, *func); sprintf(buf, kMethodDeclStr, name_buf, param_buf); diff --git a/mozilla/dom/tools/XPCOMGen.h b/mozilla/dom/tools/XPCOMGen.h index 37ddcb2746b..1871b10c9a0 100644 --- a/mozilla/dom/tools/XPCOMGen.h +++ b/mozilla/dom/tools/XPCOMGen.h @@ -40,6 +40,7 @@ protected: void GenerateForwardDecls(IdlSpecification &aSpec); void GenerateGuid(IdlInterface &aInterface); void GenerateClassDecl(IdlInterface &aInterface); + void GenerateEnums(IdlInterface &aInterface); void GenerateMethods(IdlInterface &aInterface); void GenerateEndClassDecl(); void GenerateEpilog(IdlSpecification &aSpec); diff --git a/mozilla/dom/tools/geniid.pl b/mozilla/dom/tools/geniid.pl index db12f2678bc..83f34cd3563 100644 --- a/mozilla/dom/tools/geniid.pl +++ b/mozilla/dom/tools/geniid.pl @@ -3,7 +3,7 @@ require "find.pl"; $uuid = 0x6f7652e0; -$format = "{ 0x%x, 0xee43, 0x11d1, \\ \ +$format = "{ 0x%x, 0xee43, 0x11d1, \\\ { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }"; $pattern = "--- IID GOES HERE ---"; @@ -37,7 +37,6 @@ sub replaceText { while () { if (/$pattern/) { $replacement = sprintf($format, $uuid++); - warn "$name: Changing '$pattern' to '$replacement'\n"; s/$pattern/$replacement /g; } print REPLACEFILE; diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index 03a2adbd9a0..bcaebfc7148 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -25,6 +25,7 @@ #include "nsIPresShell.h" #include "nsIDocumentObserver.h" #include "nsEventListenerManager.h" +#include "nsIScriptGlobalObject.h" #include "nsSelection.h" #include "nsIDOMText.h" @@ -436,15 +437,17 @@ void nsDocument::ContentHasBeenRemoved(nsIContent* aContainer, } } -nsresult nsDocument::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; + nsIScriptGlobalObject *global = aContext->GetGlobalObject(); if (nsnull == mScriptObject) { - res = NS_NewScriptDocument(aContext, this, nsnull, (JSObject**)&mScriptObject); + res = NS_NewScriptDocument(aContext, this, global, (void**)&mScriptObject); } *aScriptObject = mScriptObject; + NS_RELEASE(global); return res; } @@ -474,14 +477,15 @@ nsresult nsDocument::GetChildNodes(nsIDOMNodeIterator **aIterator) return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsDocument::HasChildNodes() +nsresult nsDocument::HasChildNodes(PRBool *aReturn) { if (nsnull != mRootContent) { - return NS_OK; + *aReturn = PR_TRUE; } else { - return NS_ERROR_FAILURE; + *aReturn = PR_FALSE; } + return NS_OK; } nsresult nsDocument::GetFirstChild(nsIDOMNode **aNode) @@ -664,7 +668,7 @@ nsresult nsDocument::CreateAttributeList(nsIDOMAttributeList **aAttributesList) return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsDocument::CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator) +nsresult nsDocument::CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator) { //XXX TBI return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index 48590dfa9ff..4602cece179 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -22,6 +22,7 @@ #include "nsVoidArray.h" #include "nsIDOMDocument.h" #include "nsIScriptObjectOwner.h" +#include "nsIScriptContext.h" #include "nsIDOMEventCapturer.h" class nsISelection; @@ -161,14 +162,14 @@ public: public: - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD ResetScriptObject(); // nsIDOMDocument interface NS_IMETHOD GetNodeType(PRInt32 *aType); NS_IMETHOD GetParentNode(nsIDOMNode **aNode); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode); NS_IMETHOD GetNextSibling(nsIDOMNode **aNode); @@ -194,7 +195,7 @@ public: nsIDOMNode *value, nsIDOMAttribute **aAttribute); NS_IMETHOD CreateAttributeList(nsIDOMAttributeList **aAttributesList); - NS_IMETHOD CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator); + NS_IMETHOD CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator); NS_IMETHOD GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator); // nsIDOMEventCapturer interface diff --git a/mozilla/layout/html/base/src/Makefile b/mozilla/layout/html/base/src/Makefile index 38b8b9a0e8a..54c1765b1bd 100644 --- a/mozilla/layout/html/base/src/Makefile +++ b/mozilla/layout/html/base/src/Makefile @@ -60,7 +60,7 @@ EXPORTS = \ MODULE = raptor -REQUIRES = xpcom raptor dom netlib +REQUIRES = xpcom raptor dom netlib js include $(DEPTH)/config/config.mk diff --git a/mozilla/layout/html/base/src/makefile.win b/mozilla/layout/html/base/src/makefile.win index 00632157b50..cc6e08f962f 100644 --- a/mozilla/layout/html/base/src/makefile.win +++ b/mozilla/layout/html/base/src/makefile.win @@ -19,7 +19,7 @@ DEPTH=..\..\..\.. LIBRARY_NAME=raptorhtmlbase_s MODULE=raptor -REQUIRES=xpcom raptor +REQUIRES=xpcom raptor js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= \ @@ -93,7 +93,7 @@ CPP_OBJS= \ EXPORTS=nsGlobalVariables.h -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \ -I..\..\style\src -I$(PUBLIC)\dom -I$(PUBLIC)\netlib \ -I..\..\..\base\src diff --git a/mozilla/layout/html/base/src/nsDOMAttributes.cpp b/mozilla/layout/html/base/src/nsDOMAttributes.cpp index 1c099143e3e..b9106252bf9 100644 --- a/mozilla/layout/html/base/src/nsDOMAttributes.cpp +++ b/mozilla/layout/html/base/src/nsDOMAttributes.cpp @@ -69,11 +69,11 @@ NS_IMPL_ADDREF(nsDOMAttribute) NS_IMPL_RELEASE(nsDOMAttribute) -nsresult nsDOMAttribute::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsDOMAttribute::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; if (nsnull == mScriptObject) { - res = NS_NewScriptAttribute(aContext, this, nsnull, (JSObject**)&mScriptObject); + res = NS_NewScriptAttribute(aContext, this, nsnull, (void **)&mScriptObject); } *aScriptObject = mScriptObject; return res; @@ -107,7 +107,7 @@ nsresult nsDOMAttribute::SetValue(nsString &aValue) return NS_OK; } -nsresult nsDOMAttribute::GetSpecified() +nsresult nsDOMAttribute::GetSpecified(PRBool *aSpecified) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -173,11 +173,11 @@ NS_IMPL_ADDREF(nsDOMAttributeList) NS_IMPL_RELEASE(nsDOMAttributeList) -nsresult nsDOMAttributeList::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsDOMAttributeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; if (nsnull == mScriptObject) { - res = NS_NewScriptAttributeList(aContext, this, nsnull, (JSObject**)&mScriptObject); + res = NS_NewScriptAttributeList(aContext, this, nsnull, (void**)&mScriptObject); } *aScriptObject = mScriptObject; return res; diff --git a/mozilla/layout/html/base/src/nsDOMAttributes.h b/mozilla/layout/html/base/src/nsDOMAttributes.h index d977956b5ce..02cebaa9479 100644 --- a/mozilla/layout/html/base/src/nsDOMAttributes.h +++ b/mozilla/layout/html/base/src/nsDOMAttributes.h @@ -20,6 +20,7 @@ #define nsDOMAttributes_h__ #include "nsIDOMAttribute.h" +#include "nsIDOMAttributeList.h" #include "nsIScriptObjectOwner.h" class nsIContent; @@ -32,14 +33,14 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD ResetScriptObject(); // nsIDOMAttribute interface NS_IMETHOD GetName(nsString &aName); NS_IMETHOD GetValue(nsString &aValue); NS_IMETHOD SetValue(nsString &aValue); - NS_IMETHOD GetSpecified(); + NS_IMETHOD GetSpecified(PRBool *aSpecified); NS_IMETHOD SetSpecified(PRBool specified); NS_IMETHOD ToString(nsString &aString); @@ -57,7 +58,7 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD ResetScriptObject(); // nsIDOMAttributeList interface diff --git a/mozilla/layout/html/base/src/nsDOMIterator.cpp b/mozilla/layout/html/base/src/nsDOMIterator.cpp index 5edfdb89d57..f1722cdac82 100644 --- a/mozilla/layout/html/base/src/nsDOMIterator.cpp +++ b/mozilla/layout/html/base/src/nsDOMIterator.cpp @@ -69,11 +69,11 @@ NS_IMPL_ADDREF(nsDOMIterator) NS_IMPL_RELEASE(nsDOMIterator) -nsresult nsDOMIterator::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsDOMIterator::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; if (nsnull == mScriptObject) { - res = NS_NewScriptNodeIterator(aContext, this, nsnull, (JSObject**)&mScriptObject); + res = NS_NewScriptNodeIterator(aContext, this, nsnull, (void**)&mScriptObject); } *aScriptObject = mScriptObject; return res; @@ -100,12 +100,15 @@ nsresult nsDOMIterator::GetLength(PRUint32 *aLength) nsresult nsDOMIterator::GetCurrentNode(nsIDOMNode **aNode) { nsIContent *content = nsnull; - nsresult res = NS_ERROR_FAILURE; + nsresult res = NS_OK; content = mContent.ChildAt(mPosition); if (nsnull != content) { res = content->QueryInterface(kIDOMNodeIID, (void**)aNode); NS_RELEASE(content); } + else { + *aNode = nsnull; + } return res; } @@ -113,13 +116,16 @@ nsresult nsDOMIterator::GetCurrentNode(nsIDOMNode **aNode) nsresult nsDOMIterator::GetNextNode(nsIDOMNode **aNode) { nsIContent *content = nsnull; - nsresult res = NS_ERROR_FAILURE; + nsresult res = NS_OK; content = mContent.ChildAt(++mPosition); if (nsnull != content) { res = content->QueryInterface(kIDOMNodeIID, (void**)aNode); NS_RELEASE(content); } - else mPosition = mContent.ChildCount(); + else { + mPosition = mContent.ChildCount(); + *aNode = nsnull; + } return res; } @@ -127,13 +133,16 @@ nsresult nsDOMIterator::GetNextNode(nsIDOMNode **aNode) nsresult nsDOMIterator::GetPreviousNode(nsIDOMNode **aNode) { nsIContent *content = nsnull; - nsresult res = NS_ERROR_FAILURE; + nsresult res = NS_OK; content = mContent.ChildAt(--mPosition); if (nsnull != content) { res = content->QueryInterface(kIDOMNodeIID, (void**)aNode); NS_RELEASE(content); } - else mPosition = -1; + else { + mPosition = -1; + *aNode = nsnull; + } return res; } @@ -141,13 +150,16 @@ nsresult nsDOMIterator::GetPreviousNode(nsIDOMNode **aNode) nsresult nsDOMIterator::ToFirst(nsIDOMNode **aNode) { nsIContent *content = nsnull; - nsresult res = NS_ERROR_FAILURE; + nsresult res = NS_OK; mPosition = 0; content = mContent.ChildAt(mPosition); if (nsnull != content) { res = content->QueryInterface(kIDOMNodeIID, (void**)aNode); NS_RELEASE(content); } + else { + *aNode = nsnull; + } return res; } @@ -155,13 +167,16 @@ nsresult nsDOMIterator::ToFirst(nsIDOMNode **aNode) nsresult nsDOMIterator::ToLast(nsIDOMNode **aNode) { nsIContent *content = nsnull; - nsresult res = NS_ERROR_FAILURE; + nsresult res = NS_OK; mPosition = mPosition = mContent.ChildCount(); content = mContent.ChildAt(mPosition); if (nsnull != content) { res = content->QueryInterface(kIDOMNodeIID, (void**)aNode); NS_RELEASE(content); } + else { + *aNode = nsnull; + } return res; } diff --git a/mozilla/layout/html/base/src/nsDOMIterator.h b/mozilla/layout/html/base/src/nsDOMIterator.h index b16abb73c2d..1a582c91957 100644 --- a/mozilla/layout/html/base/src/nsDOMIterator.h +++ b/mozilla/layout/html/base/src/nsDOMIterator.h @@ -19,7 +19,7 @@ #ifndef nsDOMIterator_h__ #define nsDOMIterator_h__ -#include "nsIDOMIterators.h" +#include "nsIDOMNodeIterator.h" #include "nsIContent.h" #include "nsIScriptObjectOwner.h" @@ -30,7 +30,7 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD ResetScriptObject(); // nsIDOMIterator interface diff --git a/mozilla/layout/html/base/src/nsHTMLContainer.cpp b/mozilla/layout/html/base/src/nsHTMLContainer.cpp index 66b0624e15e..f5dd7838a2a 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainer.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContainer.cpp @@ -817,14 +817,15 @@ nsresult nsHTMLContainer::GetChildNodes(nsIDOMNodeIterator **aIterator) return NS_OK; } -nsresult nsHTMLContainer::HasChildNodes() +nsresult nsHTMLContainer::HasChildNodes(PRBool *aReturn) { if (0 != mChildren.Count()) { - return NS_OK; + *aReturn = PR_TRUE; } else { - return NS_ERROR_FAILURE; + *aReturn = PR_FALSE; } + return NS_OK; } nsresult nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode) @@ -836,8 +837,10 @@ nsresult nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode) return res; } - - return NS_ERROR_FAILURE; + else { + aNode = nsnull; + return NS_OK; + } } nsresult diff --git a/mozilla/layout/html/base/src/nsHTMLContainer.h b/mozilla/layout/html/base/src/nsHTMLContainer.h index e2253d5bbac..34611f312b0 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainer.h +++ b/mozilla/layout/html/base/src/nsHTMLContainer.h @@ -50,7 +50,7 @@ public: nsIPresContext* aPresContext); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild); NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, diff --git a/mozilla/layout/html/base/src/nsHTMLContent.cpp b/mozilla/layout/html/base/src/nsHTMLContent.cpp index 858c4d29e31..7ee60312c8e 100644 --- a/mozilla/layout/html/base/src/nsHTMLContent.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContent.cpp @@ -470,23 +470,29 @@ nsresult nsHTMLContent::GetParentNode(nsIDOMNode **aNode) NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); return res; } + else { + *aNode = nsnull; + } - return NS_ERROR_FAILURE; + return NS_OK; } nsresult nsHTMLContent::GetChildNodes(nsIDOMNodeIterator **aIterator) { - return NS_ERROR_FAILURE; + *aIterator = nsnull; + return NS_OK; } -nsresult nsHTMLContent::HasChildNodes() +nsresult nsHTMLContent::HasChildNodes(PRBool *aReturn) { - return NS_ERROR_FAILURE; + *aReturn = PR_FALSE; + return NS_OK; } nsresult nsHTMLContent::GetFirstChild(nsIDOMNode **aNode) { - return NS_ERROR_FAILURE; + *aNode = nsnull; + return NS_OK; } nsresult nsHTMLContent::GetPreviousSibling(nsIDOMNode **aNode) diff --git a/mozilla/layout/html/base/src/nsHTMLContent.h b/mozilla/layout/html/base/src/nsHTMLContent.h index fd2055c277b..6aee0656171 100644 --- a/mozilla/layout/html/base/src/nsHTMLContent.h +++ b/mozilla/layout/html/base/src/nsHTMLContent.h @@ -121,7 +121,7 @@ public: // nsIDOMNode interface NS_IMETHOD GetParentNode(nsIDOMNode **aNode); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode); NS_IMETHOD GetNextSibling(nsIDOMNode **aNode); diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp index fc8852a6520..9d954960854 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp @@ -369,19 +369,11 @@ nsIStyleRule* nsHTMLTagContent::GetStyleRule(void) return result; } -nsresult nsHTMLTagContent::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult nsHTMLTagContent::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; if (nsnull == mScriptObject) { - *aScriptObject = nsnull; - if (nsnull != mParent) { - nsIScriptObjectOwner *parent; - if (NS_OK == mParent->QueryInterface(kIScriptObjectOwner, (void**)&parent)) { - parent->GetScriptObject(aContext, aScriptObject); - NS_RELEASE(parent); - } - } - res = NS_NewScriptElement(aContext, this, (JSObject*)*aScriptObject, (JSObject**)&mScriptObject); + res = NS_NewScriptElement(aContext, this, mParent, (void**)&mScriptObject); } *aScriptObject = mScriptObject; return res; @@ -403,9 +395,9 @@ nsresult nsHTMLTagContent::GetChildNodes(nsIDOMNodeIterator **aIterator) return nsHTMLContent::GetChildNodes(aIterator); } -nsresult nsHTMLTagContent::HasChildNodes() +nsresult nsHTMLTagContent::HasChildNodes(PRBool *aReturn) { - return nsHTMLContent::HasChildNodes(); + return nsHTMLContent::HasChildNodes(aReturn); } nsresult nsHTMLTagContent::GetFirstChild(nsIDOMNode **aNode) @@ -440,8 +432,9 @@ nsresult nsHTMLTagContent::RemoveChild(nsIDOMNode *oldChild) nsresult nsHTMLTagContent::GetTagName(nsString &aName) { - NS_ASSERTION(nsnull != mTag, "no tag"); - mTag->ToString(aName); + if (nsnull != mTag) { + mTag->ToString(aName); + } return NS_OK; } @@ -450,10 +443,11 @@ nsresult nsHTMLTagContent::GetAttributes(nsIDOMAttributeList **aAttributeList) NS_PRECONDITION(nsnull != aAttributeList, "null pointer argument"); if (nsnull != mAttributes) { *aAttributeList = new nsDOMAttributeList(*this); - return NS_OK; } - - return NS_ERROR_FAILURE; + else { + *aAttributeList = nsnull; + } + return NS_OK; } nsresult nsHTMLTagContent::GetDOMAttribute(nsString &aName, nsString &aValue) diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.h b/mozilla/layout/html/base/src/nsHTMLTagContent.h index d09842d12a9..c6935ff7b6a 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.h +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.h @@ -87,7 +87,7 @@ public: virtual nsIStyleRule* GetStyleRule(void); // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); // nsIDOMElement interface NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); @@ -96,7 +96,7 @@ public: NS_IMETHOD GetNodeType(PRInt32 *aType); NS_IMETHOD GetParentNode(nsIDOMNode **aNode); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode); NS_IMETHOD GetNextSibling(nsIDOMNode **aNode); diff --git a/mozilla/layout/html/base/src/nsRootPart.cpp b/mozilla/layout/html/base/src/nsRootPart.cpp index 871a60033fa..b9cadd02f3e 100644 --- a/mozilla/layout/html/base/src/nsRootPart.cpp +++ b/mozilla/layout/html/base/src/nsRootPart.cpp @@ -472,6 +472,8 @@ public: nsGUIEvent* aEvent, nsEventStatus& aEventStatus); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + protected: virtual ~RootPart(); }; @@ -510,6 +512,18 @@ RootPart::HandleDOMEvent(nsIPresContext& aPresContext, return mDocument->HandleDOMEvent(aPresContext, aEvent, aEventStatus); } +nsresult +RootPart::GetScriptObject(nsIScriptContext *aContext, + void** aScriptObject) +{ + nsresult res = NS_OK; + if (nsnull == mScriptObject) { + res = NS_NewScriptElement(aContext, this, mDocument, (void**)&mScriptObject); + } + *aScriptObject = mScriptObject; + return res; +} + nsresult NS_NewRootPart(nsIHTMLContent** aInstancePtrResult, nsIDocument* aDocument) diff --git a/mozilla/layout/html/base/src/nsTextContent.cpp b/mozilla/layout/html/base/src/nsTextContent.cpp index ea078f206ec..d3f5d2c0ca0 100644 --- a/mozilla/layout/html/base/src/nsTextContent.cpp +++ b/mozilla/layout/html/base/src/nsTextContent.cpp @@ -259,13 +259,13 @@ public: nsIFrame*& aResult); // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(JSContext *aContext, void** aScriptObject); + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); // nsIDOMText interface NS_IMETHOD GetNodeType(PRInt32 *aType); NS_IMETHOD GetParentNode(nsIDOMNode **aNode); NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator); - NS_IMETHOD HasChildNodes(); + NS_IMETHOD HasChildNodes(PRBool *aReturn); NS_IMETHOD GetFirstChild(nsIDOMNode **aNode); NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode); NS_IMETHOD GetNextSibling(nsIDOMNode **aNode); @@ -274,11 +274,11 @@ public: nsIDOMNode *oldChild); NS_IMETHOD RemoveChild(nsIDOMNode *oldChild); NS_IMETHOD GetData(nsString& aString); - NS_IMETHOD SetData(const nsString& aString); - NS_IMETHOD Append(const nsString& aData); - NS_IMETHOD Insert(PRInt32 offset, const nsString& aData); + NS_IMETHOD SetData(nsString& aString); + NS_IMETHOD Append(nsString& aData); + NS_IMETHOD Insert(PRInt32 offset, nsString& aData); NS_IMETHOD Delete(PRInt32 offset, PRInt32 count); - NS_IMETHOD Replace(PRInt32 offset, PRInt32 count, const nsString& aData); + NS_IMETHOD Replace(PRInt32 offset, PRInt32 count, nsString& aData); NS_IMETHOD Splice(nsIDOMElement *element, PRInt32 offset, PRInt32 count); void ToCString(nsString& aBuf, PRInt32 aOffset, PRInt32 aLen) const; @@ -1753,19 +1753,11 @@ Text::CreateFrame(nsIPresContext* aPresContext, return NS_OK; } -nsresult Text::GetScriptObject(JSContext *aContext, void** aScriptObject) +nsresult Text::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { nsresult res = NS_OK; if (nsnull == mScriptObject) { - *aScriptObject = nsnull; - if (nsnull != mParent) { - nsIScriptObjectOwner *parent; - if (NS_OK == mParent->QueryInterface(kIScriptObjectOwner, (void**)&parent)) { - parent->GetScriptObject(aContext, aScriptObject); - NS_RELEASE(parent); - } - } - res = NS_NewScriptText(aContext, this, (JSObject*)*aScriptObject, (JSObject**)&mScriptObject); + res = NS_NewScriptText(aContext, this, mParent, (void**)&mScriptObject); } *aScriptObject = mScriptObject; return res; @@ -1790,9 +1782,9 @@ nsresult Text::GetChildNodes(nsIDOMNodeIterator **aIterator) return nsHTMLContent::GetChildNodes(aIterator); } -nsresult Text::HasChildNodes() +nsresult Text::HasChildNodes(PRBool *aReturn) { - return nsHTMLContent::HasChildNodes(); + return nsHTMLContent::HasChildNodes(aReturn); } nsresult Text::GetFirstChild(nsIDOMNode **aNode) @@ -1835,7 +1827,7 @@ Text::GetData(nsString& aString) } nsresult -Text::SetData(const nsString& aString) +Text::SetData(nsString& aString) { if (mText) { delete[] mText; @@ -1853,13 +1845,13 @@ Text::SetData(const nsString& aString) } nsresult -Text::Append(const nsString& aData) +Text::Append(nsString& aData) { return Replace(mLength, 0, aData); } nsresult -Text::Insert(PRInt32 offset, const nsString& aData) +Text::Insert(PRInt32 offset, nsString& aData) { return Replace(offset, 0, aData); } @@ -1872,7 +1864,7 @@ Text::Delete(PRInt32 offset, PRInt32 count) } nsresult -Text::Replace(PRInt32 offset, PRInt32 count, const nsString& aData) +Text::Replace(PRInt32 offset, PRInt32 count, nsString& aData) { // sanitize arguments if (offset < 0) { diff --git a/mozilla/layout/html/document/src/Makefile b/mozilla/layout/html/document/src/Makefile index d6570d4206a..d44e18074a3 100644 --- a/mozilla/layout/html/document/src/Makefile +++ b/mozilla/layout/html/document/src/Makefile @@ -49,7 +49,7 @@ INCLUDES += \ MODULE = raptor -REQUIRES = xpcom raptor dom netlib +REQUIRES = xpcom raptor dom netlib js include $(DEPTH)/config/rules.mk diff --git a/mozilla/layout/html/document/src/makefile.win b/mozilla/layout/html/document/src/makefile.win index 4150c0e8f47..d2bcc2c7d2f 100644 --- a/mozilla/layout/html/document/src/makefile.win +++ b/mozilla/layout/html/document/src/makefile.win @@ -32,7 +32,7 @@ EXPORTS = \ nsIHTMLDocument.h \ $(NULL) -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \ -I..\..\base\src -I..\..\forms\src \ -I..\..\style\src -I..\..\table\src -I$(PUBLIC)\dom \ -I$(PUBLIC)\netlib -I..\..\..\base\src diff --git a/mozilla/layout/html/forms/src/Makefile b/mozilla/layout/html/forms/src/Makefile index e655bb32df9..bbccf9423ca 100644 --- a/mozilla/layout/html/forms/src/Makefile +++ b/mozilla/layout/html/forms/src/Makefile @@ -40,7 +40,7 @@ MODULE = raptor INCLUDES += -I../../../base/src -I../../base/src -I../../style/src -REQUIRES = xpcom raptor dom netlib +REQUIRES = xpcom raptor dom netlib js include $(DEPTH)/config/rules.mk diff --git a/mozilla/layout/html/forms/src/makefile.win b/mozilla/layout/html/forms/src/makefile.win index 3b1fac1e9d1..ae95a48f2e9 100644 --- a/mozilla/layout/html/forms/src/makefile.win +++ b/mozilla/layout/html/forms/src/makefile.win @@ -21,7 +21,7 @@ LIBRARY_NAME=raptorhtmlforms_s DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN MODULE=raptor -REQUIRES=xpcom raptor +REQUIRES=xpcom raptor js CPPSRCS=nsForm.cpp nsInput.cpp nsInputButton.cpp nsInputCheckbox.cpp \ nsInputFile.cpp nsInputFrame.cpp \ @@ -33,7 +33,7 @@ CPP_OBJS=.\$(OBJDIR)\nsForm.obj .\$(OBJDIR)\nsInput.obj \ .\$(OBJDIR)\nsInputRadio.obj \ .\$(OBJDIR)\nsInputText.obj .\$(OBJDIR)\nsSelect.obj -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \ -I..\..\base\src -I..\..\style\src \ -I..\..\..\base\src \ -I$(PUBLIC)\dom -I$(PUBLIC)\netlib diff --git a/mozilla/layout/html/style/src/Makefile b/mozilla/layout/html/style/src/Makefile index 77539dc5c9e..474f2e534fa 100644 --- a/mozilla/layout/html/style/src/Makefile +++ b/mozilla/layout/html/style/src/Makefile @@ -44,7 +44,7 @@ MODULE = raptor INCLUDES += -I../../base/src -I../../../base/src -I. -REQUIRES = xpcom raptor dom netlib +REQUIRES = xpcom raptor dom netlib js include $(DEPTH)/config/rules.mk diff --git a/mozilla/layout/html/style/src/makefile.win b/mozilla/layout/html/style/src/makefile.win index 5842ef1aa4b..063feeb4651 100644 --- a/mozilla/layout/html/style/src/makefile.win +++ b/mozilla/layout/html/style/src/makefile.win @@ -19,7 +19,7 @@ DEPTH=..\..\..\.. LIBRARY_NAME=raptorhtmlstyle_s MODULE=raptor -REQUIRES=xpcom raptor +REQUIRES=xpcom raptor js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN @@ -38,7 +38,7 @@ CPP_OBJS=.\$(OBJDIR)\nsCSSKeywords.obj .\$(OBJDIR)\nsCSSLayout.obj \ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\netlib \ -I..\..\..\base\src \ - -I..\..\base\src + -I..\..\base\src -I$(PUBLIC)\js LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/layout/html/table/src/Makefile b/mozilla/layout/html/table/src/Makefile index 8ca73c53b4e..25e2d394774 100644 --- a/mozilla/layout/html/table/src/Makefile +++ b/mozilla/layout/html/table/src/Makefile @@ -45,7 +45,7 @@ CPPSRCS = \ MODULE = raptor -REQUIRES = xpcom raptor dom +REQUIRES = xpcom raptor dom js INCLUDES += -I../../base/src -I../../style/src -I../../../base/src diff --git a/mozilla/layout/html/table/src/makefile.win b/mozilla/layout/html/table/src/makefile.win index 39661e6017d..4e2eb2d1b49 100644 --- a/mozilla/layout/html/table/src/makefile.win +++ b/mozilla/layout/html/table/src/makefile.win @@ -19,7 +19,7 @@ DEPTH=..\..\..\.. LIBRARY_NAME=raptorhtmltable_s MODULE=raptor -REQUIRES=xpcom raptor +REQUIRES=xpcom raptor js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN @@ -45,7 +45,7 @@ CPP_OBJS=.\$(OBJDIR)\nsCellLayoutData.obj .\$(OBJDIR)\nsCellMap.obj \ LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor \ -I..\..\base\src -I..\..\style\src \ -I..\..\..\base\src \ - -I$(PUBLIC)\dom + -I$(PUBLIC)\dom -I$(PUBLIC)\js LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/layout/html/tests/Makefile b/mozilla/layout/html/tests/Makefile index 87124f2b987..5b424d98ae0 100644 --- a/mozilla/layout/html/tests/Makefile +++ b/mozilla/layout/html/tests/Makefile @@ -26,7 +26,8 @@ CPPSRCS = \ TestHTMLTagLookup.cpp \ $(NULL) -INCLUDES+=-I../src -I$(PUBLIC)/xpcom -I$(PUBLIC)/raptor -I$(PUBLIC)/netlib +INCLUDES+=-I../src -I$(PUBLIC)/xpcom -I$(PUBLIC)/raptor -I$(PUBLIC)/netlib \ + -I$(PUBLIC)\js DIRS = diff --git a/mozilla/layout/html/tests/makefile.win b/mozilla/layout/html/tests/makefile.win index 6b8f440ac7d..9b6d51a10d2 100644 --- a/mozilla/layout/html/tests/makefile.win +++ b/mozilla/layout/html/tests/makefile.win @@ -35,7 +35,7 @@ LCFLAGS = \ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\dom \ -I$(PUBLIC)\netlib -I..\base\src -I..\style\src \ - -I..\..\base\src + -I..\..\base\src -I$(PUBLIC)\js LLIBS= \ $(DIST)\lib\raptorhtmlbase_s.lib \