diff --git a/content/base/src/nsDOMSettableTokenList.cpp b/content/base/src/nsDOMSettableTokenList.cpp index d7b07fbfbc0b..2bd34a12915d 100644 --- a/content/base/src/nsDOMSettableTokenList.cpp +++ b/content/base/src/nsDOMSettableTokenList.cpp @@ -39,6 +39,7 @@ */ #include "nsDOMSettableTokenList.h" +#include "dombindings.h" nsDOMSettableTokenList::nsDOMSettableTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom) @@ -78,3 +79,10 @@ nsDOMSettableTokenList::SetValue(const nsAString& aValue) return mElement->SetAttr(kNameSpaceID_None, mAttrAtom, aValue, true); } +JSObject* +nsDOMSettableTokenList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope, + bool *triedToWrap) +{ + return mozilla::dom::binding::DOMSettableTokenList::create(cx, scope, this, + triedToWrap); +} diff --git a/content/base/src/nsDOMSettableTokenList.h b/content/base/src/nsDOMSettableTokenList.h index 1189394731e7..537bbd81a237 100644 --- a/content/base/src/nsDOMSettableTokenList.h +++ b/content/base/src/nsDOMSettableTokenList.h @@ -59,6 +59,9 @@ public: nsDOMSettableTokenList(nsGenericElement* aElement, nsIAtom* aAttrAtom); + virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope, + bool *triedToWrap); + protected: virtual ~nsDOMSettableTokenList(); }; diff --git a/content/base/src/nsDOMTokenList.cpp b/content/base/src/nsDOMTokenList.cpp index db92dc6d32be..0d98f6ac1fb9 100644 --- a/content/base/src/nsDOMTokenList.cpp +++ b/content/base/src/nsDOMTokenList.cpp @@ -44,6 +44,7 @@ #include "nsContentUtils.h" #include "nsDOMError.h" #include "nsGenericElement.h" +#include "dombindings.h" nsDOMTokenList::nsDOMTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom) @@ -52,21 +53,34 @@ nsDOMTokenList::nsDOMTokenList(nsGenericElement *aElement, nsIAtom* aAttrAtom) { // We don't add a reference to our element. If it goes away, // we'll be told to drop our reference + SetIsProxy(); } nsDOMTokenList::~nsDOMTokenList() { } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMTokenList) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMTokenList) + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMTokenList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMTokenList) + NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER +NS_IMPL_CYCLE_COLLECTION_TRACE_END + DOMCI_DATA(DOMTokenList, nsDOMTokenList) NS_INTERFACE_TABLE_HEAD(nsDOMTokenList) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_TABLE1(nsDOMTokenList, nsIDOMDOMTokenList) - NS_INTERFACE_TABLE_TO_MAP_SEGUE + NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDOMTokenList) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMTokenList) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsDOMTokenList) -NS_IMPL_RELEASE(nsDOMTokenList) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTokenList) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTokenList) void nsDOMTokenList::DropReference() @@ -293,3 +307,12 @@ nsDOMTokenList::ToString(nsAString& aResult) return NS_OK; } + +JSObject* +nsDOMTokenList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope, + bool *triedToWrap) +{ + return mozilla::dom::binding::DOMTokenList::create(cx, scope, this, + triedToWrap); +} + diff --git a/content/base/src/nsDOMTokenList.h b/content/base/src/nsDOMTokenList.h index e70d003d6512..df1f41d7d87b 100644 --- a/content/base/src/nsDOMTokenList.h +++ b/content/base/src/nsDOMTokenList.h @@ -46,16 +46,26 @@ class nsAttrValue; -class nsDOMTokenList : public nsIDOMDOMTokenList +class nsDOMTokenList : public nsIDOMDOMTokenList, + public nsWrapperCache { public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList) NS_DECL_NSIDOMDOMTOKENLIST nsDOMTokenList(nsGenericElement* aElement, nsIAtom* aAttrAtom); void DropReference(); + virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope, + bool *triedToWrap); + + nsINode *GetParentObject() + { + return mElement; + } + protected: ~nsDOMTokenList(); diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 3f9110ea4b51..e03df4da2b11 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -1980,7 +1980,7 @@ nsGenericElement::GetChildrenList() return slots->mChildrenList; } -nsIDOMDOMTokenList* +nsDOMTokenList* nsGenericElement::GetClassList(nsresult *aResult) { *aResult = NS_ERROR_OUT_OF_MEMORY; @@ -2468,6 +2468,9 @@ nsGenericElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb, b NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildrenList"); cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList)); + + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mClassList"); + cb.NoteXPCOMChild(mClassList.get()); } void @@ -2482,6 +2485,10 @@ nsGenericElement::nsDOMSlots::Unlink(bool aIsXUL) if (aIsXUL) NS_IF_RELEASE(mControllers); mChildrenList = nsnull; + if (mClassList) { + mClassList->DropReference(); + mClassList = nsnull; + } } nsGenericElement::nsGenericElement(already_AddRefed aNodeInfo) diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 5fde0c9dec3c..9553c667bbcc 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -597,7 +597,7 @@ public: nsIContent* GetLastElementChild(); nsIContent* GetPreviousElementSibling(); nsIContent* GetNextElementSibling(); - nsIDOMDOMTokenList* GetClassList(nsresult *aResult); + nsDOMTokenList* GetClassList(nsresult *aResult); bool MozMatchesSelector(const nsAString& aSelector, nsresult* aResult); /** diff --git a/content/html/content/src/nsHTMLOutputElement.cpp b/content/html/content/src/nsHTMLOutputElement.cpp index 5dcf0d6d0d29..f000a5a24173 100644 --- a/content/html/content/src/nsHTMLOutputElement.cpp +++ b/content/html/content/src/nsHTMLOutputElement.cpp @@ -100,8 +100,8 @@ public: NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLOutputElement, - nsGenericHTMLFormElement) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLOutputElement, + nsGenericHTMLFormElement) virtual nsXPCClassInfo* GetClassInfo(); protected: @@ -136,13 +136,26 @@ nsHTMLOutputElement::~nsHTMLOutputElement() } } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLOutputElement) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLOutputElement, + nsGenericHTMLFormElement) + if (tmp->mTokenList) { + tmp->mTokenList->DropReference(); + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTokenList) + } +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLOutputElement, + nsGenericHTMLFormElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTokenList, + nsDOMTokenList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_ADDREF_INHERITED(nsHTMLOutputElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLOutputElement, nsGenericElement) DOMCI_NODE_DATA(HTMLOutputElement, nsHTMLOutputElement) -NS_INTERFACE_TABLE_HEAD(nsHTMLOutputElement) +NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLOutputElement) NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLOutputElement, nsIDOMHTMLOutputElement, nsIMutationObserver, diff --git a/dom/interfaces/core/nsIDOMDOMTokenList.idl b/dom/interfaces/core/nsIDOMDOMTokenList.idl index fc926b4b8c13..c2404fca3317 100644 --- a/dom/interfaces/core/nsIDOMDOMTokenList.idl +++ b/dom/interfaces/core/nsIDOMDOMTokenList.idl @@ -49,11 +49,11 @@ interface nsIDOMDOMTokenList : nsISupports { readonly attribute unsigned long length; - DOMString item(in unsigned long index); + [getter] DOMString item(in unsigned long index); boolean contains([Null(Stringify)] in DOMString token); void add([Null(Stringify)] in DOMString token); void remove([Null(Stringify)] in DOMString token); boolean toggle([Null(Stringify)] in DOMString token); - DOMString toString(); + [stringifier] DOMString toString(); }; diff --git a/js/xpconnect/src/dom_quickstubs.qsconf b/js/xpconnect/src/dom_quickstubs.qsconf index 716647657742..3666343f8837 100644 --- a/js/xpconnect/src/dom_quickstubs.qsconf +++ b/js/xpconnect/src/dom_quickstubs.qsconf @@ -518,6 +518,7 @@ customIncludes = [ 'nsINodeList.h', 'nsCSSPropertiesQS.h', 'nsDocument.h', + 'nsDOMTokenList.h', 'nsGenericDOMDataNode.h', 'nsGenericElement.h', 'nsGenericHTMLElement.h', @@ -785,7 +786,7 @@ customMethodCalls = { }, 'nsIDOMElement_GetClassList': { 'thisType': 'nsGenericElement', - 'code': ' nsIDOMDOMTokenList *result = self->GetClassList(&rv);' + 'code': ' nsDOMTokenList *result = self->GetClassList(&rv);' }, 'nsIDOMElement_SetCapture': { 'thisType': 'nsGenericElement', diff --git a/js/xpconnect/src/dombindings.conf b/js/xpconnect/src/dombindings.conf index b088dad64bd0..3b4401ce2ea2 100644 --- a/js/xpconnect/src/dombindings.conf +++ b/js/xpconnect/src/dombindings.conf @@ -2,6 +2,8 @@ classes = { 'NodeList': 'nsINodeList', 'HTMLCollection': 'nsIHTMLCollection', 'HTMLOptionsCollection': 'nsHTMLOptionCollection', + 'DOMTokenList': 'nsDOMTokenList', + 'DOMSettableTokenList': 'nsDOMSettableTokenList', } irregularFilenames = { diff --git a/js/xpconnect/src/dombindings.h b/js/xpconnect/src/dombindings.h index 0fe4d5c5e302..626e59fb3363 100644 --- a/js/xpconnect/src/dombindings.h +++ b/js/xpconnect/src/dombindings.h @@ -43,6 +43,7 @@ #include "jsapi.h" #include "jsproxy.h" #include "xpcpublic.h" +#include "nsString.h" namespace mozilla { namespace dom {