Skip to content

Commit

Permalink
Bug 1614546 part 1. Get rid of SVG uses of NS_ERROR_DOM_TYPE_ERR. r=h…
Browse files Browse the repository at this point in the history
…eycam

Differential Revision: https://phabricator.services.mozilla.com/D62399

--HG--
extra : moz-landing-system : lando
  • Loading branch information
bzbarsky committed Feb 19, 2020
1 parent b7f5c4a commit bb356d9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
8 changes: 4 additions & 4 deletions dom/svg/SVGAnimatedEnumeration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion dom/svg/SVGAnimatedEnumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
15 changes: 8 additions & 7 deletions dom/svg/SVGAnimatedOrient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions dom/svg/SVGAnimatedOrient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions dom/svg/SVGElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsAtom> 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);
Expand Down
3 changes: 1 addition & 2 deletions dom/svg/SVGFragmentIdentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGMarkerElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ already_AddRefed<DOMSVGAnimatedAngle> 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) {
Expand Down

This file was deleted.

0 comments on commit bb356d9

Please sign in to comment.