Bug 1419310 - Part 2: Enqueue an attributeChanged reaction when mutating the value of an observed attribute to the same value; r=smaug
authorEdgar Chen <echen@mozilla.com>
Wed, 22 Nov 2017 23:48:34 +0800
changeset 447652 8cd877d4a07485dd228886e2351cf322e9564e84
parent 447651 61e8cef55c206612e48de2f86d37a8783aa44d62
child 447653 f7b7bdd7b05c992b4fb435a26a6278829063748b
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1419310
milestone59.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 1419310 - Part 2: Enqueue an attributeChanged reaction when mutating the value of an observed attribute to the same value; r=smaug MozReview-Commit-ID: GyRL6Xt8HWt
dom/base/Element.cpp
dom/base/Element.h
testing/web-platform/meta/custom-elements/reactions/DOMStringMap.html.ini
testing/web-platform/meta/custom-elements/reactions/DOMTokenList.html.ini
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -2981,16 +2981,45 @@ Element::PostIdMaybeChange(int32_t aName
   if (aValue && !aValue->IsEmptyString()) {
     SetHasID();
     AddToIdTable(aValue->GetAtomValue());
   } else {
     ClearHasID();
   }
 }
 
+nsresult
+Element::OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
+                                const nsAttrValueOrString& aValue,
+                                bool aNotify)
+{
+  if (CustomElementRegistry::IsCustomElementEnabled()) {
+    // Only custom element which is in `custom` state could get the
+    // CustomElementDefinition.
+    CustomElementDefinition* definition = GetCustomElementDefinition();
+    if (definition && definition->IsInObservedAttributeList(aName)) {
+      nsAutoString ns;
+      nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns);
+
+      nsAutoString value(aValue.String());
+      LifecycleCallbackArgs args = {
+        nsDependentAtomString(aName),
+        value,
+        value,
+        (ns.IsEmpty() ? VoidString() : ns)
+      };
+
+      nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged,
+        this, &args, nullptr, definition);
+    }
+  }
+
+  return NS_OK;
+}
+
 EventListenerManager*
 Element::GetEventListenerManagerForAttr(nsAtom* aAttrName,
                                         bool* aDefer)
 {
   *aDefer = true;
   return GetOrCreateListenerManager();
 }
 
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1705,20 +1705,17 @@ protected:
    * @param aValue the value it's being set to represented as either a string or
    *        a parsed nsAttrValue.
    * @param aNotify Whether we plan to notify document observers.
    */
   // Note that this is inlined so that when subclasses call it it gets
   // inlined.  Those calls don't go through a vtable.
   virtual nsresult OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
                                           const nsAttrValueOrString& aValue,
-                                          bool aNotify)
-  {
-    return NS_OK;
-  }
+                                          bool aNotify);
 
   /**
    * Hook to allow subclasses to produce a different EventListenerManager if
    * needed for attachment of attribute-defined handlers
    */
   virtual EventListenerManager*
     GetEventListenerManagerForAttr(nsAtom* aAttrName, bool* aDefer);
 
deleted file mode 100644
--- a/testing/web-platform/meta/custom-elements/reactions/DOMStringMap.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[DOMStringMap.html]
-  type: testharness
-  [setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute to the same value]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/custom-elements/reactions/DOMTokenList.html.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-[DOMTokenList.html]
-  type: testharness
-  [remove on DOMTokenList must not enqueue an attributeChanged reaction when removing a non-existent value from an attribute]
-    expected: FAIL
-
-  [the stringifier of DOMTokenList must enqueue an attributeChanged reaction when the setter is called with the original value of the attribute]
-    expected: FAIL
-
-  [remove on DOMTokenList must enqueue an attributeChanged reaction even when removing a non-existent value from an attribute]
-    expected: FAIL
-