From bb356d988d516b0ab6b198839ee3549d3703668a Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 19 Feb 2020 22:06:09 +0000 Subject: [PATCH] Bug 1614546 part 1. Get rid of SVG uses of NS_ERROR_DOM_TYPE_ERR. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D62399 --HG-- extra : moz-landing-system : lando --- dom/svg/SVGAnimatedEnumeration.cpp | 8 ++++---- dom/svg/SVGAnimatedEnumeration.h | 4 +++- dom/svg/SVGAnimatedOrient.cpp | 15 ++++++++------- dom/svg/SVGAnimatedOrient.h | 5 +++-- dom/svg/SVGElement.cpp | 6 ++++-- dom/svg/SVGFragmentIdentifier.cpp | 3 +-- dom/svg/SVGMarkerElement.cpp | 2 +- ...GAnimatedEnumeration-SVGMarkerElement.html.ini | 4 ---- 8 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 testing/web-platform/meta/svg/types/scripted/SVGAnimatedEnumeration-SVGMarkerElement.html.ini diff --git a/dom/svg/SVGAnimatedEnumeration.cpp b/dom/svg/SVGAnimatedEnumeration.cpp index 5e19528627e3..e7584e30eae5 100644 --- a/dom/svg/SVGAnimatedEnumeration.cpp +++ b/dom/svg/SVGAnimatedEnumeration.cpp @@ -31,8 +31,8 @@ const SVGEnumMapping* SVGAnimatedEnumeration::GetMapping( return info.mEnumInfo[mAttrEnum].mMapping; } -nsresult SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue, - SVGElement* aSVGElement) { +bool SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue, + SVGElement* aSVGElement) { const SVGEnumMapping* mapping = GetMapping(aSVGElement); while (mapping && mapping->mKey) { @@ -49,12 +49,12 @@ nsresult SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue, // SVGElement::ParseAttribute under Element::SetAttr, // which takes care of notifying. } - return NS_OK; + return true; } mapping++; } - return NS_ERROR_DOM_TYPE_ERR; + return false; } nsAtom* SVGAnimatedEnumeration::GetBaseValueAtom(SVGElement* aSVGElement) { diff --git a/dom/svg/SVGAnimatedEnumeration.h b/dom/svg/SVGAnimatedEnumeration.h index 4a260cad82a5..89c5e2ab5875 100644 --- a/dom/svg/SVGAnimatedEnumeration.h +++ b/dom/svg/SVGAnimatedEnumeration.h @@ -43,7 +43,9 @@ class SVGAnimatedEnumeration { mIsBaseSet = false; } - nsresult SetBaseValueAtom(const nsAtom* aValue, SVGElement* aSVGElement); + // Returns whether aValue corresponded to a key in our mapping (in which case + // we actually set the base value) or not (in which case we did not). + bool SetBaseValueAtom(const nsAtom* aValue, SVGElement* aSVGElement); nsAtom* GetBaseValueAtom(SVGElement* aSVGElement); void SetBaseValue(uint16_t aValue, SVGElement* aSVGElement, ErrorResult& aRv); uint16_t GetBaseValue() const { return mBaseVal; } diff --git a/dom/svg/SVGAnimatedOrient.cpp b/dom/svg/SVGAnimatedOrient.cpp index 31f802d403be..1c456fa9d701 100644 --- a/dom/svg/SVGAnimatedOrient.cpp +++ b/dom/svg/SVGAnimatedOrient.cpp @@ -19,6 +19,7 @@ #include "mozAutoDocUpdate.h" #include "nsContentUtils.h" #include "nsTextFormatter.h" +#include "nsPrintfCString.h" using namespace mozilla::dom; using namespace mozilla::dom::SVGAngle_Binding; @@ -340,13 +341,12 @@ void SVGAnimatedOrient::SetBaseValue(float aValue, uint8_t aUnit, } } -nsresult SVGAnimatedOrient::SetBaseType(SVGEnumValue aValue, - SVGElement* aSVGElement) { +void SVGAnimatedOrient::SetBaseType(SVGEnumValue aValue, + SVGElement* aSVGElement, ErrorResult& aRv) { if (mBaseType == aValue) { - return NS_OK; + return; } - if (aValue == SVG_MARKER_ORIENT_AUTO || aValue == SVG_MARKER_ORIENT_ANGLE || - aValue == SVG_MARKER_ORIENT_AUTO_START_REVERSE) { + if (aValue == SVG_MARKER_ORIENT_AUTO || aValue == SVG_MARKER_ORIENT_ANGLE) { AutoChangeOrientNotifier notifier(this, aSVGElement); mBaseVal = .0f; @@ -357,9 +357,10 @@ nsresult SVGAnimatedOrient::SetBaseType(SVGEnumValue aValue, mAnimValUnit = mBaseValUnit; mAnimType = mBaseType; } - return NS_OK; + return; } - return NS_ERROR_DOM_TYPE_ERR; + nsPrintfCString err("Invalid base value %u for marker orient", aValue); + aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err)); } void SVGAnimatedOrient::SetAnimValue(float aValue, uint8_t aUnit, diff --git a/dom/svg/SVGAnimatedOrient.h b/dom/svg/SVGAnimatedOrient.h index 02d98440dd28..cf007955e6fe 100644 --- a/dom/svg/SVGAnimatedOrient.h +++ b/dom/svg/SVGAnimatedOrient.h @@ -62,7 +62,8 @@ class SVGAnimatedOrient { void SetBaseValue(float aValue, uint8_t aUnit, SVGElement* aSVGElement, bool aDoSetAttr); - nsresult SetBaseType(SVGEnumValue aValue, SVGElement* aSVGElement); + void SetBaseType(SVGEnumValue aValue, SVGElement* aSVGElement, + ErrorResult& aRv); void SetAnimValue(float aValue, uint8_t aUnit, SVGElement* aSVGElement); void SetAnimType(SVGEnumValue aValue, SVGElement* aSVGElement); @@ -112,7 +113,7 @@ class SVGAnimatedOrient { using mozilla::dom::DOMSVGAnimatedEnumeration::SetBaseVal; uint16_t BaseVal() override { return Sanitize(mVal->mBaseType); } void SetBaseVal(uint16_t aBaseVal, ErrorResult& aRv) override { - aRv = mVal->SetBaseType(aBaseVal, mSVGElement); + mVal->SetBaseType(aBaseVal, mSVGElement, aRv); } uint16_t AnimVal() override { // Script may have modified animation parameters or timeline -- DOM diff --git a/dom/svg/SVGElement.cpp b/dom/svg/SVGElement.cpp index 265469705ae8..a9db376f223c 100644 --- a/dom/svg/SVGElement.cpp +++ b/dom/svg/SVGElement.cpp @@ -490,8 +490,10 @@ bool SVGElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, for (i = 0; i < enumInfo.mEnumCount; i++) { if (aAttribute == enumInfo.mEnumInfo[i].mName) { RefPtr valAtom = NS_Atomize(aValue); - rv = enumInfo.mEnums[i].SetBaseValueAtom(valAtom, this); - if (NS_FAILED(rv)) { + 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); } else { aResult.SetTo(valAtom); diff --git a/dom/svg/SVGFragmentIdentifier.cpp b/dom/svg/SVGFragmentIdentifier.cpp index 31ed75306380..3f59060c4d75 100644 --- a/dom/svg/SVGFragmentIdentifier.cpp +++ b/dom/svg/SVGFragmentIdentifier.cpp @@ -98,8 +98,7 @@ class MOZ_RAII AutoSVGViewHandler { return false; } nsAtom* valAtom = NS_GetStaticAtom(aParams); - if (!valAtom || - NS_FAILED(mSVGView->mZoomAndPan.SetBaseValueAtom(valAtom, mRoot))) { + if (!valAtom || !mSVGView->mZoomAndPan.SetBaseValueAtom(valAtom, mRoot)) { return false; } } else { diff --git a/dom/svg/SVGMarkerElement.cpp b/dom/svg/SVGMarkerElement.cpp index ba5347e393c2..a284e186057b 100644 --- a/dom/svg/SVGMarkerElement.cpp +++ b/dom/svg/SVGMarkerElement.cpp @@ -107,7 +107,7 @@ already_AddRefed SVGMarkerElement::OrientAngle() { } void SVGMarkerElement::SetOrientToAuto() { - mOrient.SetBaseType(SVG_MARKER_ORIENT_AUTO, this); + mOrient.SetBaseType(SVG_MARKER_ORIENT_AUTO, this, IgnoreErrors()); } void SVGMarkerElement::SetOrientToAngle(DOMSVGAngle& angle, ErrorResult& rv) { diff --git a/testing/web-platform/meta/svg/types/scripted/SVGAnimatedEnumeration-SVGMarkerElement.html.ini b/testing/web-platform/meta/svg/types/scripted/SVGAnimatedEnumeration-SVGMarkerElement.html.ini deleted file mode 100644 index e958bfab17fa..000000000000 --- a/testing/web-platform/meta/svg/types/scripted/SVGAnimatedEnumeration-SVGMarkerElement.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[SVGAnimatedEnumeration-SVGMarkerElement.html] - [Use of SVGAnimatedEnumeration within SVGMarkerElement] - expected: FAIL -