Bug 1554498 - Some miscellaneous cleanups while I was going through this code. r=edgar
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 29 May 2019 19:20:37 +0000
changeset 476106 849ba4e850449a007e77316d6a2c1038f5143669
parent 476099 4b3431481d55e13e739e42dd5e526c11bea22f45
child 476107 388ab8151b4d5e797b6cde9a92a8be7e58836d2b
push id36086
push usershindli@mozilla.com
push dateThu, 30 May 2019 03:47:55 +0000
treeherdermozilla-central@73c98da145a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedgar
bugs1554498
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1554498 - Some miscellaneous cleanups while I was going through this code. r=edgar Differential Revision: https://phabricator.services.mozilla.com/D32638
dom/base/CharacterData.cpp
dom/base/Element.cpp
dom/base/ShadowRoot.cpp
--- a/dom/base/CharacterData.cpp
+++ b/dom/base/CharacterData.cpp
@@ -494,17 +494,17 @@ nsresult CharacterData::BindToTree(Docum
 
 void CharacterData::UnbindFromTree(bool aNullParent) {
   // Unset frame flags; if we need them again later, they'll get set again.
   UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE | NS_REFRAME_IF_WHITESPACE);
 
   Document* document = GetComposedDoc();
 
   if (aNullParent) {
-    if (this->IsRootOfNativeAnonymousSubtree()) {
+    if (IsRootOfNativeAnonymousSubtree()) {
       nsNodeUtils::NativeAnonymousChildListChange(this, true);
     }
     if (GetParent()) {
       NS_RELEASE(mParent);
     } else {
       mParent = nullptr;
     }
     SetParentIsContent(false);
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1701,18 +1701,17 @@ nsresult Element::BindToTree(Document* a
     // If we're not in the doc and not in a shadow tree,
     // update our subtree pointer.
     SetSubtreeRootPointer(aParent->SubtreeRoot());
   }
 
   if (IsInComposedDoc()) {
     // Connected callback must be enqueued whenever a custom element becomes
     // connected.
-    CustomElementData* data = GetCustomElementData();
-    if (data) {
+    if (CustomElementData* data = GetCustomElementData()) {
       if (data->mState == CustomElementData::State::eCustom) {
         nsContentUtils::EnqueueLifecycleCallback(Document::eConnected, this);
       } else {
         // Step 7.7.2.2 https://dom.spec.whatwg.org/#concept-node-insert
         nsContentUtils::TryToUpgradeElement(this);
       }
     }
   }
@@ -2614,28 +2613,26 @@ bool Element::SetAndSwapMappedAttribute(
   *aRetval = NS_OK;
   return false;
 }
 
 nsresult Element::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
                                 const nsAttrValueOrString* aValue,
                                 bool aNotify) {
   if (aNamespaceID == kNameSpaceID_None) {
-    if (aName == nsGkAtoms::_class) {
-      if (aValue) {
-        // Note: This flag is asymmetrical. It is never unset and isn't exact.
-        // If it is ever made to be exact, we probably need to handle this
-        // similarly to how ids are handled in PreIdMaybeChange and
-        // PostIdMaybeChange.
-        // Note that SetSingleClassFromParser inlines BeforeSetAttr and
-        // calls SetMayHaveClass directly. Making a subclass take action
-        // on the class attribute in a BeforeSetAttr override would
-        // require revising SetSingleClassFromParser.
-        SetMayHaveClass();
-      }
+    if (aName == nsGkAtoms::_class && aValue) {
+      // Note: This flag is asymmetrical. It is never unset and isn't exact.
+      // If it is ever made to be exact, we probably need to handle this
+      // similarly to how ids are handled in PreIdMaybeChange and
+      // PostIdMaybeChange.
+      // Note that SetSingleClassFromParser inlines BeforeSetAttr and
+      // calls SetMayHaveClass directly. Making a subclass take action
+      // on the class attribute in a BeforeSetAttr override would
+      // require revising SetSingleClassFromParser.
+      SetMayHaveClass();
     }
   }
 
   return NS_OK;
 }
 
 void Element::PreIdMaybeChange(int32_t aNamespaceID, nsAtom* aName,
                                const nsAttrValueOrString* aValue) {
--- a/dom/base/ShadowRoot.cpp
+++ b/dom/base/ShadowRoot.cpp
@@ -473,19 +473,18 @@ void ShadowRoot::GetEventTargetParent(Ev
     aVisitor.mEventTargetAtParent = shadowHost;
   }
 }
 
 ShadowRoot::SlotAssignment ShadowRoot::SlotAssignmentFor(nsIContent* aContent) {
   nsAutoString slotName;
   // Note that if slot attribute is missing, assign it to the first default
   // slot, if exists.
-  if (aContent->IsElement()) {
-    aContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::slot,
-                                   slotName);
+  if (Element* element = Element::FromNode(aContent)) {
+    element->GetAttr(kNameSpaceID_None, nsGkAtoms::slot, slotName);
   }
 
   SlotArray* slots = mSlotMap.Get(slotName);
   if (!slots) {
     return {};
   }
 
   HTMLSlotElement* slot = (*slots)->ElementAt(0);