Bug 1596474 - Remove GetBindingParent from nsGenericHTMLElement. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 14 Nov 2019 17:16:01 +0000
changeset 501990 4a44d69250edf0378fe40d3b88dad9607cb54f78
parent 501989 ee728f3ea085900757752d009ea271d21087096a
child 501991 d8ef1649d10d3da44356be01016ee11c6926831a
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1596474
milestone72.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 1596474 - Remove GetBindingParent from nsGenericHTMLElement. r=smaug The two loops where they're used can't walk across shadow boundaries, so we only need to check for NAC. We don't have forms in NAC, so avoid silly book-keeping and just return early for those cases. Differential Revision: https://phabricator.services.mozilla.com/D53045
dom/html/nsGenericHTMLElement.cpp
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -425,23 +425,22 @@ void nsGenericHTMLElement::UnbindFromTre
   }
 }
 
 HTMLFormElement* nsGenericHTMLElement::FindAncestorForm(
     HTMLFormElement* aCurrentForm) {
   NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
                    IsHTMLElement(nsGkAtoms::img),
                "FindAncestorForm should not be called if @form is set!");
-
-  // Make sure we don't end up finding a form that's anonymous from
-  // our point of view. See also nsGenericHTMLFormElement::UpdateFieldSet.
-  nsIContent* bindingParent = GetBindingParent();
+  if (IsInNativeAnonymousSubtree()) {
+    return nullptr;
+  }
 
   nsIContent* content = this;
-  while (content != bindingParent && content) {
+  while (content) {
     // If the current ancestor is a form, return it as our form
     if (content->IsHTMLElement(nsGkAtoms::form)) {
 #ifdef DEBUG
       if (!nsContentUtils::IsInSameAnonymousTree(this, content)) {
         // It's possible that we started unbinding at |content| or
         // some ancestor of it, and |content| and |this| used to all be
         // anonymous.  Check for this the hard way.
         for (nsIContent* child = this; child != content;
@@ -2099,24 +2098,25 @@ void nsGenericHTMLFormElement::UpdateFor
   }
 
   if (mForm != oldForm || needStateUpdate) {
     UpdateState(true);
   }
 }
 
 void nsGenericHTMLFormElement::UpdateFieldSet(bool aNotify) {
+  if (IsInNativeAnonymousSubtree()) {
+    MOZ_ASSERT(!mFieldSet);
+    return;
+  }
+
   nsIContent* parent = nullptr;
   nsIContent* prev = nullptr;
 
-  // Don't walk out of anonymous subtrees. Note the similar code in
-  // nsGenericHTMLElement::FindAncestorForm.
-  nsIContent* bindingParent = GetBindingParent();
-
-  for (parent = GetParent(); parent && parent != bindingParent;
+  for (parent = GetParent(); parent;
        prev = parent, parent = parent->GetParent()) {
     HTMLFieldSetElement* fieldset = HTMLFieldSetElement::FromNode(parent);
     if (fieldset && (!prev || fieldset->GetFirstLegend() != prev)) {
       if (mFieldSet == fieldset) {
         // We already have the right fieldset;
         return;
       }
 
@@ -2866,9 +2866,9 @@ already_AddRefed<ElementInternals> nsGen
     return nullptr;
   }
 
   // 6. Set element's attached internals to true.
   ceData->AttachedInternals();
 
   // 7. Create a new ElementInternals instance targeting element, and return it.
   return MakeAndAddRef<ElementInternals>(this);
-}
\ No newline at end of file
+}