diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 72085b0148fb..854844d92e22 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -3103,47 +3103,14 @@ nsresult Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) { void Element::GetLinkTarget(nsAString& aTarget) { aTarget.Truncate(); } -static void nsDOMTokenListPropertyDestructor(void* aObject, nsAtom* aProperty, - void* aPropertyValue, - void* aData) { - nsDOMTokenList* list = static_cast(aPropertyValue); - NS_RELEASE(list); -} - static nsStaticAtom* const sPropertiesToTraverseAndUnlink[] = { - nsGkAtoms::sandbox, nsGkAtoms::sizes, nsGkAtoms::dirAutoSetBy, nullptr}; + nsGkAtoms::dirAutoSetBy, nullptr}; // static nsStaticAtom* const* Element::HTMLSVGPropertiesToTraverseAndUnlink() { return sPropertiesToTraverseAndUnlink; } -nsDOMTokenList* Element::GetTokenList( - nsAtom* aAtom, const DOMTokenListSupportedTokenArray aSupportedTokens) { -#ifdef DEBUG - const nsStaticAtom* const* props = HTMLSVGPropertiesToTraverseAndUnlink(); - bool found = false; - for (uint32_t i = 0; props[i]; ++i) { - if (props[i] == aAtom) { - found = true; - break; - } - } - MOZ_ASSERT(found, "Trying to use an unknown tokenlist!"); -#endif - - nsDOMTokenList* list = nullptr; - if (HasProperties()) { - list = static_cast(GetProperty(aAtom)); - } - if (!list) { - list = new nsDOMTokenList(this, aAtom, aSupportedTokens); - NS_ADDREF(list); - SetProperty(aAtom, list, nsDOMTokenListPropertyDestructor); - } - return list; -} - nsresult Element::CopyInnerTo(Element* aDst, ReparseAttributes aReparse) { nsresult rv = aDst->mAttrs.EnsureCapacityToClone(mAttrs); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/base/Element.h b/dom/base/Element.h index b8bded46909e..58cc122edbc5 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -1908,10 +1908,6 @@ class Element : public FragmentOrElement { */ virtual void GetLinkTarget(nsAString& aTarget); - nsDOMTokenList* GetTokenList( - nsAtom* aAtom, - const DOMTokenListSupportedTokenArray aSupportedTokens = nullptr); - enum class ReparseAttributes { No, Yes }; /** * Copy attributes and state to another element diff --git a/dom/html/HTMLIFrameElement.cpp b/dom/html/HTMLIFrameElement.cpp index b475e108ac49..72dc463a955c 100644 --- a/dom/html/HTMLIFrameElement.cpp +++ b/dom/html/HTMLIFrameElement.cpp @@ -28,11 +28,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLIFrameElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLIFrameElement, nsGenericHTMLFrameElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFeaturePolicy) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSandbox) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLIFrameElement, nsGenericHTMLFrameElement) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFeaturePolicy) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mSandbox) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_ADDREF_INHERITED(HTMLIFrameElement, nsGenericHTMLFrameElement) diff --git a/dom/html/HTMLIFrameElement.h b/dom/html/HTMLIFrameElement.h index ff1d6b2b9b66..70e576e800b4 100644 --- a/dom/html/HTMLIFrameElement.h +++ b/dom/html/HTMLIFrameElement.h @@ -66,7 +66,11 @@ class HTMLIFrameElement final : public nsGenericHTMLFrameElement { SetHTMLAttr(nsGkAtoms::name, aName, aError); } nsDOMTokenList* Sandbox() { - return GetTokenList(nsGkAtoms::sandbox, sSupportedSandboxTokens); + if (!mSandbox) { + mSandbox = + new nsDOMTokenList(this, nsGkAtoms::sandbox, sSupportedSandboxTokens); + } + return mSandbox; } bool AllowFullscreen() const { return GetBoolAttr(nsGkAtoms::allowfullscreen); @@ -196,7 +200,8 @@ class HTMLIFrameElement final : public nsGenericHTMLFrameElement { */ void AfterMaybeChangeAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify); - RefPtr mFeaturePolicy; + RefPtr mFeaturePolicy; + RefPtr mSandbox; }; } // namespace dom diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 8a6183599a19..e8f387d8c1f6 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -75,12 +75,14 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement, nsGenericHTMLElement) tmp->nsStyleLinkElement::Traverse(cb); NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSizes) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement, nsGenericHTMLElement) tmp->nsStyleLinkElement::Unlink(); NS_IMPL_CYCLE_COLLECTION_UNLINK(mRelList) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mSizes) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLLinkElement, diff --git a/dom/html/HTMLLinkElement.h b/dom/html/HTMLLinkElement.h index a52c3eb83be1..3b312754ff39 100644 --- a/dom/html/HTMLLinkElement.h +++ b/dom/html/HTMLLinkElement.h @@ -11,6 +11,7 @@ #include "mozilla/dom/Link.h" #include "nsGenericHTMLElement.h" #include "nsStyleLinkElement.h" +#include "nsDOMTokenList.h" namespace mozilla { class EventChainPostVisitor; @@ -124,7 +125,12 @@ class HTMLLinkElement final : public nsGenericHTMLElement, static void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult); static nsContentPolicyType AsValueToContentPolicy(const nsAttrValue& aValue); - nsDOMTokenList* Sizes() { return GetTokenList(nsGkAtoms::sizes); } + nsDOMTokenList* Sizes() { + if (!mSizes) { + mSizes = new nsDOMTokenList(this, nsGkAtoms::sizes); + } + return mSizes; + } void GetType(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::type, aValue); } void SetType(const nsAString& aType, ErrorResult& aRv) { SetHTMLAttr(nsGkAtoms::type, aType, aRv); @@ -183,6 +189,7 @@ class HTMLLinkElement final : public nsGenericHTMLElement, Maybe GetStyleSheetInfo() final; RefPtr mRelList; + RefPtr mSizes; // The "explicitly enabled" flag. This flag is set whenever the `disabled` // attribute is explicitly unset, and makes alternate stylesheets not be