Bug 1687195 - Invalid enums should return the initial value, not the unknown value try: -b d -p linux64 -u reftest-t none draft bug1687195
authorlongsonr <longsonr@gmail.com>
Sun, 17 Jan 2021 19:50:47 +0000
changeset 3456991 d4c8f1cd20648e1ab1a0e45598e8bf0ff9b14aed
parent 3456182 1c14bc8527e7dee848e867d86a614ceedc396cb0
child 3674469 50cbab89d7a40003ab2e549d9a2a2d90c52cc3f8
push id643088
push userlongsonr@gmail.com
push dateMon, 18 Jan 2021 13:48:18 +0000
treeherdertry@d4c8f1cd2064 [default view] [failures only]
bugs1687195
milestone86.0a1
Bug 1687195 - Invalid enums should return the initial value, not the unknown value try: -b d -p linux64 -u reftest-t none Reviewers: emilio Tags: #secure-revision Bug #: 1687195 Differential Revision: https://phabricator.services.mozilla.com/D102131
dom/svg/SVGAnimatedEnumeration.cpp
dom/svg/SVGElement.cpp
dom/svg/SVGElement.h
layout/reftests/svg/filters/feBlend-1-ref.svg
testing/web-platform/meta/css/filter-effects/svgfeblendelement-mode-001.html.ini
--- a/dom/svg/SVGAnimatedEnumeration.cpp
+++ b/dom/svg/SVGAnimatedEnumeration.cpp
@@ -59,18 +59,18 @@ const SVGEnumMapping* SVGAnimatedEnumera
 }
 
 bool SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue,
                                               SVGElement* aSVGElement) {
   const SVGEnumMapping* mapping = GetMapping(aSVGElement);
 
   while (mapping && mapping->mKey) {
     if (aValue == mapping->mKey) {
-      mIsBaseSet = true;
-      if (mBaseVal != mapping->mVal) {
+      if (!mIsBaseSet || mBaseVal != mapping->mVal) {
+        mIsBaseSet = true;
         // We don't need to call DidChange* here - we're only called by
         // SVGElement::ParseAttribute under Element::SetAttr,
         // which takes care of notifying.
         AutoChangeEnumNotifier notifier(this, aSVGElement, false);
 
         mBaseVal = mapping->mVal;
         if (!mIsAnimated) {
           mAnimVal = mBaseVal;
@@ -99,18 +99,18 @@ nsAtom* SVGAnimatedEnumeration::GetBaseV
 
 void SVGAnimatedEnumeration::SetBaseValue(uint16_t aValue,
                                           SVGElement* aSVGElement,
                                           ErrorResult& aRv) {
   const SVGEnumMapping* mapping = GetMapping(aSVGElement);
 
   while (mapping && mapping->mKey) {
     if (mapping->mVal == aValue) {
-      mIsBaseSet = true;
-      if (mBaseVal != uint8_t(aValue)) {
+      if (!mIsBaseSet || mBaseVal != uint8_t(aValue)) {
+        mIsBaseSet = true;
         AutoChangeEnumNotifier notifier(this, aSVGElement);
 
         mBaseVal = uint8_t(aValue);
         if (!mIsAnimated) {
           mAnimVal = mBaseVal;
         }
       }
       return;
--- a/dom/svg/SVGElement.cpp
+++ b/dom/svg/SVGElement.cpp
@@ -24,17 +24,16 @@
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/SMILAnimationController.h"
 #include "mozilla/StaticPrefs_layout.h"
 #include "mozilla/SVGContentUtils.h"
 #include "mozilla/Unused.h"
 
-#include "DOMSVGAnimatedEnumeration.h"
 #include "mozAutoDocUpdate.h"
 #include "nsAttrValueOrString.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsContentUtils.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsICSSDeclaration.h"
 #include "nsIContentInlines.h"
@@ -516,17 +515,17 @@ bool SVGElement::ParseAttribute(int32_t 
       EnumAttributesInfo enumInfo = GetEnumInfo();
       for (i = 0; i < enumInfo.mEnumCount; i++) {
         if (aAttribute == enumInfo.mEnumInfo[i].mName) {
           RefPtr<nsAtom> valAtom = NS_Atomize(aValue);
           if (!enumInfo.mEnums[i].SetBaseValueAtom(valAtom, this)) {
             // Exact error value does not matter; we just need to mark the
             // parse as failed.
             rv = NS_ERROR_FAILURE;
-            enumInfo.SetUnknownValue(i);
+            enumInfo.Reset(i);
           } else {
             aResult.SetTo(valAtom);
             didSetResult = true;
           }
           foundMatch = true;
           break;
         }
       }
@@ -1962,21 +1961,16 @@ void SVGElement::DidAnimateBoolean(uint8
 SVGElement::EnumAttributesInfo SVGElement::GetEnumInfo() {
   return EnumAttributesInfo(nullptr, nullptr, 0);
 }
 
 void SVGElement::EnumAttributesInfo::Reset(uint8_t aAttrEnum) {
   mEnums[aAttrEnum].Init(aAttrEnum, mEnumInfo[aAttrEnum].mDefaultValue);
 }
 
-void SVGElement::EnumAttributesInfo::SetUnknownValue(uint8_t aAttrEnum) {
-  // Fortunately in SVG every enum's unknown value is 0
-  mEnums[aAttrEnum].Init(aAttrEnum, 0);
-}
-
 void SVGElement::DidChangeEnum(uint8_t aAttrEnum) {
   EnumAttributesInfo info = GetEnumInfo();
 
   NS_ASSERTION(info.mEnumCount > 0,
                "DidChangeEnum on element with no enum attribs");
   NS_ASSERTION(aAttrEnum < info.mEnumCount, "aAttrEnum out of range");
 
   nsAttrValue attrValue(info.mEnums[aAttrEnum].GetBaseValueAtom(this));
--- a/dom/svg/SVGElement.h
+++ b/dom/svg/SVGElement.h
@@ -517,17 +517,16 @@ class SVGElement : public SVGElementBase
     const EnumInfo* const mEnumInfo;
     const uint32_t mEnumCount;
 
     EnumAttributesInfo(SVGAnimatedEnumeration* aEnums, EnumInfo* aEnumInfo,
                        uint32_t aEnumCount)
         : mEnums(aEnums), mEnumInfo(aEnumInfo), mEnumCount(aEnumCount) {}
 
     void Reset(uint8_t aAttrEnum);
-    void SetUnknownValue(uint8_t aAttrEnum);
   };
 
   struct NumberListInfo {
     nsStaticAtom* const mName;
   };
 
   struct NumberListAttributesInfo {
     SVGAnimatedNumberList* const mNumberLists;
--- a/layout/reftests/svg/filters/feBlend-1-ref.svg
+++ b/layout/reftests/svg/filters/feBlend-1-ref.svg
@@ -11,9 +11,10 @@
 <rect x="0" y="50" width="50" height="50" fill="#DFB53F"/>
 <rect x="50" y="50" width="50" height="50" fill="#B5DF3F"/>
 <rect x="100" y="50" width="50" height="50" fill="#DFDF3F"/>
 <rect x="150" y="50" width="50" height="50" fill="#DFDF3F"/>
 <rect x="200" y="50" width="50" height="50" fill="#DFC88E"/>
 <rect x="250" y="50" width="50" height="50" fill="#B5DF3F"/>
 <rect x="300" y="50" width="50" height="50" fill="#DFC88E"/>
 <rect x="350" y="50" width="50" height="50" fill="#B5CC3F"/>
+<rect x="0" y="100" width="50" height="50" fill="#DFB53F"/>
 </svg>
deleted file mode 100644
--- a/testing/web-platform/meta/css/filter-effects/svgfeblendelement-mode-001.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[svgfeblendelement-mode-001.html]
-  [SVGFEBlendElement.prototype.mode, getter, invalid value]
-    expected: FAIL
-
-  [SVGFEBlendElement.prototype.mode, setter, numeric value for "normal"]
-    expected: FAIL
-