summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-18 20:35:11 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:39 -0500
commitb7f890e02e6bf24db172881d6da910e70c7586fe (patch)
treebd9598a66bbd5f9a52fc51c291bc0dd2c8507856
parentfce396323da02695c266579d229f11bf0959280b (diff)
downloadUXP-b7f890e02e6bf24db172881d6da910e70c7586fe.tar
UXP-b7f890e02e6bf24db172881d6da910e70c7586fe.tar.gz
UXP-b7f890e02e6bf24db172881d6da910e70c7586fe.tar.lz
UXP-b7f890e02e6bf24db172881d6da910e70c7586fe.tar.xz
UXP-b7f890e02e6bf24db172881d6da910e70c7586fe.zip
Bug 1410790 - Add more assertion in CustomElementData::SetCustomElementDefinition and GetCustomElementDefinition;
This is a follow-up patch for bug 1392970. Since we only set CustomElementDefinition on a custom element which is custom, we could add more assertion to ensure that. Tag UXP Issue #1344
-rw-r--r--dom/base/CustomElementRegistry.cpp42
-rw-r--r--dom/base/CustomElementRegistry.h23
-rw-r--r--dom/base/FragmentOrElement.cpp18
3 files changed, 52 insertions, 31 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp
index 200668f9e..0f03b16bd 100644
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -138,6 +138,48 @@ CustomElementData::CustomElementData(nsIAtom* aType, State aState)
{
}
+void
+CustomElementData::SetCustomElementDefinition(CustomElementDefinition* aDefinition)
+{
+ MOZ_ASSERT(mState == State::eCustom);
+ MOZ_ASSERT(!mCustomElementDefinition);
+ MOZ_ASSERT(aDefinition->mType == mType);
+
+ mCustomElementDefinition = aDefinition;
+}
+
+CustomElementDefinition*
+CustomElementData::GetCustomElementDefinition()
+{
+ MOZ_ASSERT(mCustomElementDefinition ? mState == State::eCustom
+ : mState != State::eCustom);
+
+ return mCustomElementDefinition;
+}
+
+void
+CustomElementData::Traverse(nsCycleCollectionTraversalCallback& aCb) const
+{
+ for (uint32_t i = 0; i < mReactionQueue.Length(); i++) {
+ if (mReactionQueue[i]) {
+ mReactionQueue[i]->Traverse(aCb);
+ }
+ }
+
+ if (mCustomElementDefinition) {
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mCustomElementDefinition");
+ aCb.NoteNativeChild(mCustomElementDefinition,
+ NS_CYCLE_COLLECTION_PARTICIPANT(CustomElementDefinition));
+ }
+}
+
+void
+CustomElementData::Unlink()
+{
+ mReactionQueue.Clear();
+ mCustomElementDefinition = nullptr;
+}
+
//-----------------------------------------------------
// CustomElementRegistry
diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h
index 867c92647..d3dfef682 100644
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -130,24 +130,16 @@ struct CustomElementData
// e.g., create an element, insert a node.
AutoTArray<UniquePtr<CustomElementReaction>, 3> mReactionQueue;
- RefPtr<CustomElementDefinition> mCustomElementDefinition;
-
- void
- SetCustomElementDefinition(CustomElementDefinition* aDefinition)
- {
- MOZ_ASSERT(!mCustomElementDefinition);
-
- mCustomElementDefinition = aDefinition;
- }
+ void SetCustomElementDefinition(CustomElementDefinition* aDefinition);
+ CustomElementDefinition* GetCustomElementDefinition();
- CustomElementDefinition*
- GetCustomElementDefinition()
- {
- return mCustomElementDefinition;
- }
+ void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
+ void Unlink();
private:
virtual ~CustomElementData() {}
+
+ RefPtr<CustomElementDefinition> mCustomElementDefinition;
};
#define ALEADY_CONSTRUCTED_MARKER nullptr
@@ -167,7 +159,8 @@ struct CustomElementDefinition
mozilla::dom::LifecycleCallbacks* aCallbacks,
uint32_t aDocOrder);
- // The type (name) for this custom element.
+ // The type (name) for this custom element, for <button is="x-foo"> or <x-foo>
+ // this would be x-foo.
nsCOMPtr<nsIAtom> mType;
// The localname to (e.g. <button is=type> -- this would be button).
diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp
index a851190ff..526c3c9d4 100644
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -583,19 +583,7 @@ FragmentOrElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
cb.NoteXPCOMChild(mExtendedSlots->mXBLInsertionParent.get());
if (mExtendedSlots->mCustomElementData) {
- for (uint32_t i = 0;
- i < mExtendedSlots->mCustomElementData->mReactionQueue.Length(); i++) {
- if (mExtendedSlots->mCustomElementData->mReactionQueue[i]) {
- mExtendedSlots->mCustomElementData->mReactionQueue[i]->Traverse(cb);
- }
- }
-
- if (mExtendedSlots->mCustomElementData->mCustomElementDefinition) {
- NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
- "mExtendedSlots->mCustomElementData->mCustomElementDefinition");
- cb.NoteNativeChild(mExtendedSlots->mCustomElementData->mCustomElementDefinition,
- NS_CYCLE_COLLECTION_PARTICIPANT(CustomElementDefinition));
- }
+ mExtendedSlots->mCustomElementData->Traverse(cb);
}
for (auto iter = mExtendedSlots->mRegisteredIntersectionObservers.Iter();
@@ -633,9 +621,7 @@ FragmentOrElement::nsDOMSlots::Unlink()
MOZ_ASSERT(!(mExtendedSlots->mXBLBinding));
mExtendedSlots->mXBLInsertionParent = nullptr;
if (mExtendedSlots->mCustomElementData) {
- if (mExtendedSlots->mCustomElementData->mCustomElementDefinition) {
- mExtendedSlots->mCustomElementData->mCustomElementDefinition = nullptr;
- }
+ mExtendedSlots->mCustomElementData->Unlink();
mExtendedSlots->mCustomElementData = nullptr;
}
mExtendedSlots->mRegisteredIntersectionObservers.Clear();