Bug 539697 - valueAsString returns an incorrect failure code. r=jwatt
authorRobert Longson <longsonr@gmail.com>
Wed, 20 Jan 2010 19:58:58 +0000
changeset 37353 73ba1f723e0b06bc2c3d599ca168d40ae72e6f43
parent 37352 028722efe7a8cb7a547e965cb7f454b99bb4d32f
child 37354 02135cbe7432866204f9887786f1e9c1c040079b
push idunknown
push userunknown
push dateunknown
reviewersjwatt
bugs539697
milestone1.9.3a1pre
Bug 539697 - valueAsString returns an incorrect failure code. r=jwatt
content/svg/content/src/nsSVGAngle.cpp
content/svg/content/src/nsSVGBoolean.cpp
content/svg/content/src/nsSVGEnum.cpp
content/svg/content/src/nsSVGInteger.cpp
content/svg/content/src/nsSVGLength.cpp
content/svg/content/src/nsSVGLength2.cpp
content/svg/content/src/nsSVGLengthList.cpp
content/svg/content/src/nsSVGMarkerElement.cpp
content/svg/content/src/nsSVGNumber.cpp
content/svg/content/src/nsSVGNumber2.cpp
content/svg/content/src/nsSVGNumberList.cpp
content/svg/content/src/nsSVGPointList.cpp
content/svg/content/src/nsSVGPreserveAspectRatio.cpp
content/svg/content/src/nsSVGTransformList.cpp
content/svg/content/src/nsSVGViewBox.cpp
content/svg/content/test/Makefile.in
content/svg/content/test/test_valueAsString.xhtml
--- a/content/svg/content/src/nsSVGAngle.cpp
+++ b/content/svg/content/src/nsSVGAngle.cpp
@@ -71,23 +71,21 @@ public:
   NS_IMETHOD SetValueAsString(const nsAString& aValue)
     { return mVal.SetBaseValueString(aValue, nsnull, PR_FALSE); }
   NS_IMETHOD GetValueAsString(nsAString& aValue)
     { mVal.GetBaseValueString(aValue); return NS_OK; }
 
   NS_IMETHOD NewValueSpecifiedUnits(PRUint16 unitType,
                                     float valueInSpecifiedUnits)
     {
-      NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
-      mVal.NewValueSpecifiedUnits(unitType, valueInSpecifiedUnits, nsnull);
-      return NS_OK;
+      return mVal.NewValueSpecifiedUnits(unitType, valueInSpecifiedUnits, nsnull);
     }
 
   NS_IMETHOD ConvertToSpecifiedUnits(PRUint16 unitType)
-    { mVal.ConvertToSpecifiedUnits(unitType, nsnull); return NS_OK; }
+    { return mVal.ConvertToSpecifiedUnits(unitType, nsnull); }
 
 private:
   nsSVGAngle mVal;
 };
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGAngle::DOMBaseVal, mSVGElement)
 
 NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGAngle::DOMAnimVal, mSVGElement)
@@ -200,28 +198,28 @@ static nsresult
 GetValueFromString(const nsAString &aValueAsString,
                    float *aValue,
                    PRUint16 *aUnitType)
 {
   NS_ConvertUTF16toUTF8 value(aValueAsString);
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   *aValue = float(PR_strtod(str, &rest));
   if (rest != str && NS_FloatIsFinite(*aValue)) {
     *aUnitType = GetUnitTypeForString(rest);
     if (IsValidUnitType(*aUnitType)) {
       return NS_OK;
     }
   }
   
-  return NS_ERROR_FAILURE;
+  return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
 float
 nsSVGAngle::GetUnitScaleFactor() const
 {
   switch (mSpecifiedUnitType) {
   case nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED:
   case nsIDOMSVGAngle::SVG_ANGLETYPE_DEG:
@@ -239,41 +237,45 @@ nsSVGAngle::GetUnitScaleFactor() const
 void
 nsSVGAngle::SetBaseValueInSpecifiedUnits(float aValue,
                                          nsSVGElement *aSVGElement)
 {
   mBaseVal = aValue;
   aSVGElement->DidChangeAngle(mAttrEnum, PR_TRUE);
 }
 
-void
+nsresult
 nsSVGAngle::ConvertToSpecifiedUnits(PRUint16 unitType,
                                     nsSVGElement *aSVGElement)
 {
   if (!IsValidUnitType(unitType))
-    return;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   float valueInUserUnits = mBaseVal / GetUnitScaleFactor();
   mSpecifiedUnitType = PRUint8(unitType);
   SetBaseValue(valueInUserUnits, aSVGElement);
+  return NS_OK;
 }
 
-void
+nsresult
 nsSVGAngle::NewValueSpecifiedUnits(PRUint16 unitType,
                                    float valueInSpecifiedUnits,
                                    nsSVGElement *aSVGElement)
 {
+  NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
+
   if (!IsValidUnitType(unitType))
-    return;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   mBaseVal = mAnimVal = valueInSpecifiedUnits;
   mSpecifiedUnitType = PRUint8(unitType);
   if (aSVGElement) {
     aSVGElement->DidChangeAngle(mAttrEnum, PR_TRUE);
   }
+  return NS_OK;
 }
 
 nsresult
 nsSVGAngle::ToDOMBaseVal(nsIDOMSVGAngle **aResult, nsSVGElement *aSVGElement)
 {
   *aResult = new DOMBaseVal(this, aSVGElement);
   if (!*aResult)
     return NS_ERROR_OUT_OF_MEMORY;
--- a/content/svg/content/src/nsSVGBoolean.cpp
+++ b/content/svg/content/src/nsSVGBoolean.cpp
@@ -56,17 +56,17 @@ nsSVGBoolean::SetBaseValueString(const n
 {
   PRBool val;
 
   if (aValueAsString.EqualsLiteral("true"))
     val = PR_TRUE;
   else if (aValueAsString.EqualsLiteral("false"))
     val = PR_FALSE;
   else
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
 
   mBaseVal = mAnimVal = val;
   return NS_OK;
 }
 
 void
 nsSVGBoolean::GetBaseValueString(nsAString & aValueAsString)
 {
--- a/content/svg/content/src/nsSVGEnum.cpp
+++ b/content/svg/content/src/nsSVGEnum.cpp
@@ -74,17 +74,17 @@ nsSVGEnum::SetBaseValueString(const nsAS
       mBaseVal = mAnimVal = tmp->mVal;
       return NS_OK;
     }
     tmp++;
   }
 
   // only a warning since authors may mistype attribute values
   NS_WARNING("unknown enumeration key");
-  return NS_ERROR_FAILURE;
+  return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
 void
 nsSVGEnum::GetBaseValueString(nsAString& aValue, nsSVGElement *aSVGElement)
 {
   nsSVGEnumMapping *tmp = GetMapping(aSVGElement);
 
   while (tmp && tmp->mKey) {
@@ -107,17 +107,17 @@ nsSVGEnum::SetBaseValue(PRUint16 aValue,
   while (tmp && tmp->mKey) {
     if (tmp->mVal == aValue) {
       mAnimVal = mBaseVal = PRUint8(aValue);
       aSVGElement->DidChangeEnum(mAttrEnum, aDoSetAttr);
       return NS_OK;
     }
     tmp++;
   }
-  return NS_ERROR_FAILURE;
+  return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
 nsresult
 nsSVGEnum::ToDOMAnimatedEnum(nsIDOMSVGAnimatedEnumeration **aResult,
                              nsSVGElement *aSVGElement)
 {
   *aResult = new DOMAnimatedEnum(this, aSVGElement);
   if (!*aResult)
--- a/content/svg/content/src/nsSVGInteger.cpp
+++ b/content/svg/content/src/nsSVGInteger.cpp
@@ -54,22 +54,22 @@ nsresult
 nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
                                  nsSVGElement *aSVGElement,
                                  PRBool aDoSetAttr)
 {
   NS_ConvertUTF16toUTF8 value(aValueAsString);
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   PRInt32 val = strtol(str, &rest, 10);
   if (rest == str || *rest != '\0') {
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   mBaseVal = mAnimVal = val;
   return NS_OK;
 }
 
 void
 nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
--- a/content/svg/content/src/nsSVGLength.cpp
+++ b/content/svg/content/src/nsSVGLength.cpp
@@ -391,53 +391,53 @@ nsSVGLength::SetValueAsString(const nsAS
       }
       if (IsValidUnitType(unitType) && NS_FloatIsFinite(value)) {
         WillModify();
         mValueInSpecifiedUnits = value;
         mSpecifiedUnitType     = unitType;
         DidModify();
       } else { // parse error
         // not a valid unit type
-        rv = NS_ERROR_FAILURE;
+        rv = NS_ERROR_DOM_SYNTAX_ERR;
       }
     }
     else { // parse error
       // no number
-      rv = NS_ERROR_FAILURE;
+      rv = NS_ERROR_DOM_SYNTAX_ERR;
     }
   }
 
   nsMemory::Free(str);
 
   return rv;
 }
 
 /* void newValueSpecifiedUnits (in unsigned short unitType, in float valueInSpecifiedUnits); */
 NS_IMETHODIMP
 nsSVGLength::NewValueSpecifiedUnits(PRUint16 unitType, float valueInSpecifiedUnits)
 {
   NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
 
   if (!IsValidUnitType(unitType))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   WillModify();
   mValueInSpecifiedUnits = valueInSpecifiedUnits;
   mSpecifiedUnitType     = unitType;
   DidModify();
 
   return NS_OK;
 }
 
 /* void convertToSpecifiedUnits (in unsigned short unitType); */
 NS_IMETHODIMP
 nsSVGLength::ConvertToSpecifiedUnits(PRUint16 unitType)
 {
   if (!IsValidUnitType(unitType))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   WillModify();
   float valueInUserUnits;
   GetValue(&valueInUserUnits);
   mSpecifiedUnitType = unitType;
   SetValue(valueInUserUnits);
   DidModify();
 
--- a/content/svg/content/src/nsSVGLength2.cpp
+++ b/content/svg/content/src/nsSVGLength2.cpp
@@ -165,28 +165,28 @@ static nsresult
 GetValueFromString(const nsAString &aValueAsString,
                    float *aValue,
                    PRUint16 *aUnitType)
 {
   NS_ConvertUTF16toUTF8 value(aValueAsString);
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   *aValue = float(PR_strtod(str, &rest));
   if (rest != str && NS_FloatIsFinite(*aValue)) {
     *aUnitType = GetUnitTypeForString(rest);
     if (IsValidUnitType(*aUnitType)) {
       return NS_OK;
     }
   }
   
-  return NS_ERROR_FAILURE;
+  return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
 float
 nsSVGLength2::GetMMPerPixel(nsSVGSVGElement *aCtx) const
 {
   if (!aCtx)
     return 1;
 
@@ -335,46 +335,51 @@ nsSVGLength2::SetBaseValueInSpecifiedUni
 
 #ifdef MOZ_SMIL
   if (mIsAnimated) {
     aSVGElement->AnimationNeedsResample();
   }
 #endif
 }
 
-void
+nsresult
 nsSVGLength2::ConvertToSpecifiedUnits(PRUint16 unitType,
                                       nsSVGElement *aSVGElement)
 {
   if (!IsValidUnitType(unitType))
-    return;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   float valueInUserUnits = 
     mBaseVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType);
   mSpecifiedUnitType = PRUint8(unitType);
   SetBaseValue(valueInUserUnits, aSVGElement);
+
+  return NS_OK;
 }
 
-void
+nsresult
 nsSVGLength2::NewValueSpecifiedUnits(PRUint16 unitType,
                                      float valueInSpecifiedUnits,
                                      nsSVGElement *aSVGElement)
 {
+  NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
+
   if (!IsValidUnitType(unitType))
-    return;
+    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 
   mBaseVal = mAnimVal = valueInSpecifiedUnits;
   mSpecifiedUnitType = PRUint8(unitType);
   aSVGElement->DidChangeLength(mAttrEnum, PR_TRUE);
 
 #ifdef MOZ_SMIL
   if (mIsAnimated) {
     aSVGElement->AnimationNeedsResample();
   }
 #endif
+  return NS_OK;
 }
 
 nsresult
 nsSVGLength2::ToDOMBaseVal(nsIDOMSVGLength **aResult, nsSVGElement *aSVGElement)
 {
   *aResult = sBaseSVGLengthTearoffTable.GetTearoff(this);
   if (!*aResult) {
     *aResult = new DOMBaseVal(this, aSVGElement);
--- a/content/svg/content/src/nsSVGLengthList.cpp
+++ b/content/svg/content/src/nsSVGLengthList.cpp
@@ -146,17 +146,17 @@ nsSVGLengthList::SetValueString(const ns
   char* rest = str;
   char* token;
   const char* delimiters = ",\x20\x9\xD\xA";
 
   while ((token = nsCRT::strtok(rest, delimiters, &rest))) {
     nsCOMPtr<nsISVGLength> length;
     NS_NewSVGLength(getter_AddRefs(length), NS_ConvertASCIItoUTF16(token));
     if (!length) {
-      rv = NS_ERROR_FAILURE;
+      rv = NS_ERROR_DOM_SYNTAX_ERR;
       break;
     }
     AppendElement(length);
   }
   
   nsMemory::Free(str);
   
   DidModify();
--- a/content/svg/content/src/nsSVGMarkerElement.cpp
+++ b/content/svg/content/src/nsSVGMarkerElement.cpp
@@ -109,17 +109,17 @@ nsSVGOrientType::SetBaseValue(PRUint16 a
     SetBaseValue(aValue);
     aSVGElement->SetAttr(
       kNameSpaceID_None, nsGkAtoms::orient, nsnull,
       (aValue ==nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_AUTO ?
         NS_LITERAL_STRING("auto") : NS_LITERAL_STRING("0")),
       PR_TRUE);
     return NS_OK;
   }
-  return NS_ERROR_FAILURE;
+  return NS_ERROR_DOM_SYNTAX_ERR;
 }
 
 nsresult
 nsSVGOrientType::ToDOMAnimatedEnum(nsIDOMSVGAnimatedEnumeration **aResult,
                                    nsSVGElement *aSVGElement)
 {
   *aResult = new DOMAnimatedEnum(this, aSVGElement);
   if (!*aResult)
--- a/content/svg/content/src/nsSVGNumber.cpp
+++ b/content/svg/content/src/nsSVGNumber.cpp
@@ -34,16 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsSVGNumber.h"
 #include "nsTextFormatter.h"
 #include "prdtoa.h"
+#include "nsDOMError.h"
 #include "nsSVGValue.h"
 #include "nsISVGValueUtils.h"
 #include "nsContentUtils.h"
 
 ////////////////////////////////////////////////////////////////////////
 // nsSVGNumber class
 
 class nsSVGNumber : public nsIDOMSVGNumber,
@@ -134,21 +135,20 @@ nsSVGNumber::SetValueString(const nsAStr
         rv = SetValue(val);
       }
       // skip trailing spaces
       while (*rest && isspace(*rest))
         ++rest;
 
       // check to see if there is trailing stuff...
       if (*rest != '\0') {
-        rv = NS_ERROR_FAILURE;
-        NS_ERROR("trailing data in number value");
+        rv = NS_ERROR_DOM_SYNTAX_ERR;
       }
     } else {
-      rv = NS_ERROR_FAILURE;
+      rv = NS_ERROR_DOM_SYNTAX_ERR;
       // no number
     }
   }
   DidModify();
   return rv;
 }
 
 //----------------------------------------------------------------------
--- a/content/svg/content/src/nsSVGNumber2.cpp
+++ b/content/svg/content/src/nsSVGNumber2.cpp
@@ -88,22 +88,22 @@ nsresult
 nsSVGNumber2::SetBaseValueString(const nsAString &aValueAsString,
                                  nsSVGElement *aSVGElement,
                                  PRBool aDoSetAttr)
 {
   NS_ConvertUTF16toUTF8 value(aValueAsString);
   const char *str = value.get();
 
   if (NS_IsAsciiWhitespace(*str))
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   
   char *rest;
   float val = float(PR_strtod(str, &rest));
   if (rest == str || *rest != '\0' || !NS_FloatIsFinite(val)) {
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   mBaseVal = mAnimVal = val;
 
   // XXX shouldn't we be calling DidChangeNumber here???
 
 #ifdef MOZ_SMIL
   if (mIsAnimated) {
--- a/content/svg/content/src/nsSVGNumberList.cpp
+++ b/content/svg/content/src/nsSVGNumberList.cpp
@@ -140,17 +140,17 @@ nsSVGNumberList::SetValueString(const ns
 
   while ((token = nsCRT::strtok(rest, delimiters, &rest))) {
     char *left;
     float val = float(PR_strtod(token, &left));
     if (token!=left && NS_FloatIsFinite(val)) {
       nsCOMPtr<nsIDOMSVGNumber> number;
       NS_NewSVGNumber(getter_AddRefs(number), val);
       if (!number) {
-        rv = NS_ERROR_FAILURE;
+        rv = NS_ERROR_DOM_SYNTAX_ERR;
         break;
       }
       AppendElement(number);
     }
   }
   
   nsMemory::Free(str);
   
--- a/content/svg/content/src/nsSVGPointList.cpp
+++ b/content/svg/content/src/nsSVGPointList.cpp
@@ -172,37 +172,37 @@ nsSVGPointList::SetValueString(const nsA
   
   while ( (token1 = nsCRT::strtok(rest, delimiters, &rest)) &&
           (token2 = nsCRT::strtok(rest, delimiters, &rest)) ) {
 
     char *end;
     
     float x = float(PR_strtod(token1, &end));
     if (*end != '\0' || !NS_FloatIsFinite(x)) {
-      rv = NS_ERROR_FAILURE;
+      rv = NS_ERROR_DOM_SYNTAX_ERR;
       break; // parse error
     }
     float y = float(PR_strtod(token2, &end));
     if (*end != '\0' || !NS_FloatIsFinite(y)) {
-      rv = NS_ERROR_FAILURE;
+      rv = NS_ERROR_DOM_SYNTAX_ERR;
       break; // parse error
     }
     
     nsCOMPtr<nsIDOMSVGPoint> point;
     NS_NewSVGPoint(getter_AddRefs(point), x, y);
     if (!point) {
       rv = NS_ERROR_OUT_OF_MEMORY;
       break;
     }
     points.AppendObject(point);
   }
 
   if (token1 || NS_FAILED(rv)) {
     // there was a parse error or we ran out of memory
-    rv = NS_ERROR_FAILURE;
+    rv = NS_ERROR_DOM_SYNTAX_ERR;
   } else {
     WillModify();
     ReleasePoints();
     PRInt32 count = points.Count();
     for (PRInt32 i=0; i<count; ++i) {
       AppendElement(points.ObjectAt(i));
     }
     DidModify();
--- a/content/svg/content/src/nsSVGPreserveAspectRatio.cpp
+++ b/content/svg/content/src/nsSVGPreserveAspectRatio.cpp
@@ -160,50 +160,54 @@ nsSVGPreserveAspectRatio::ToDOMAnimVal(n
 
 nsresult
 nsSVGPreserveAspectRatio::SetBaseValueString(const nsAString &aValueAsString,
                                              nsSVGElement *aSVGElement,
                                              PRBool aDoSetAttr)
 {
   if (aValueAsString.IsEmpty() ||
       NS_IsAsciiWhitespace(aValueAsString[0])) {
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   nsWhitespaceTokenizer tokenizer(aValueAsString);
   if (!tokenizer.hasMoreTokens()) {
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   }
   const nsAString &token = tokenizer.nextToken();
 
   nsresult rv;
   PreserveAspectRatio val;
 
   val.mDefer = token.EqualsLiteral("defer");
 
   if (val.mDefer) {
     if (!tokenizer.hasMoreTokens()) {
-      return NS_ERROR_FAILURE;
+      return NS_ERROR_DOM_SYNTAX_ERR;
     }
     rv = val.SetAlign(GetAlignForString(tokenizer.nextToken()));
   } else {
     rv = val.SetAlign(GetAlignForString(token));
   }
 
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_DOM_SYNTAX_ERR;
+  }
 
   if (tokenizer.hasMoreTokens()) {
     rv = val.SetMeetOrSlice(GetMeetOrSliceForString(tokenizer.nextToken()));
-    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+    if (NS_FAILED(rv)) {
+      return NS_ERROR_DOM_SYNTAX_ERR;
+    }
   } else {
     val.mMeetOrSlice = nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET;
   }
 
   if (tokenizer.hasMoreTokens()) {
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_SYNTAX_ERR;
   }
 
   mAnimVal = mBaseVal = val;
   aSVGElement->DidChangePreserveAspectRatio(aDoSetAttr);
   return NS_OK;
 }
 
 void
--- a/content/svg/content/src/nsSVGTransformList.cpp
+++ b/content/svg/content/src/nsSVGTransformList.cpp
@@ -174,17 +174,17 @@ nsSVGTransformList::SetValueString(const
 
   // parse transform attribute value
   nsCOMArray<nsIDOMSVGTransform> xforms;
   nsSVGTransformListParser parser(&xforms);
   rv = parser.Parse(aValue);
 
   if (NS_FAILED(rv)) {
     // there was a parse error.
-    rv = NS_ERROR_FAILURE;
+    rv = NS_ERROR_DOM_SYNTAX_ERR;
   }
   else {
     WillModify();
     ReleaseTransforms();
     PRInt32 count = xforms.Count();
     for (PRInt32 i=0; i<count; ++i) {
       AppendElement(xforms.ObjectAt(i));
     }
--- a/content/svg/content/src/nsSVGViewBox.cpp
+++ b/content/svg/content/src/nsSVGViewBox.cpp
@@ -120,17 +120,17 @@ nsSVGViewBox::SetBaseValueString(const n
     if (!(token = nsCRT::strtok(rest, delimiters, &rest))) break; // parse error
 
     char *end;
     vals[i] = float(PR_strtod(token, &end));
     if (*end != '\0' || !NS_FloatIsFinite(vals[i])) break; // parse error
   }
   if (i!=4 || nsCRT::strtok(rest, delimiters, &rest)!=0) {
     // there was a parse error.
-    rv = NS_ERROR_FAILURE;
+    rv = NS_ERROR_DOM_SYNTAX_ERR;
   } else {
     SetBaseValue(vals[0], vals[1], vals[2], vals[3], aSVGElement, aDoSetAttr);
   }
 
   nsMemory::Free(str);
 
   return rv;
 }
--- a/content/svg/content/test/Makefile.in
+++ b/content/svg/content/test/Makefile.in
@@ -63,15 +63,16 @@ include $(topsrcdir)/config/rules.mk
 		test_pointer-events.xhtml \
 		test_scientific.html \
 		scientific-helper.svg \
 		test_switch.xhtml \
 		switch-helper.svg \
 		test_text.html \
 		text-helper.svg \
 		test_transform.xhtml \
+		test_valueAsString.xhtml \
 		test_valueLeaks.xhtml \
 		viewport-helper.svg \
 		test_viewport.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/test_valueAsString.xhtml
@@ -0,0 +1,62 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=539697 
+-->
+<head>
+  <title>Test SVGTransform behavior</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=539697">Mozilla Bug 539697</a>
+<p id="display"></p>
+<div id="content">
+
+  <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1" id="svg">
+    <circle id='c' r='1em' display='none'/>
+    <marker id='m' orient='20rad' display='none'/>
+  </svg>
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+<![CDATA[
+
+SimpleTest.waitForExplicitFinish();
+
+function run()
+{
+  var c = document.getElementById('c');
+  var m = document.getElementById('m');
+
+  is(SVGLength.SVG_LENGTHTYPE_EMS, c.r.baseVal.unitType, 'unexpected units');
+  c.r.baseVal.valueAsString = '2px';
+  is(SVGLength.SVG_LENGTHTYPE_PX, c.r.baseVal.unitType, 'unexpected units');
+
+  try {
+    c.r.baseVal.valueAsString = 'rubbish';
+  } catch (e) {
+    is(DOMException.SYNTAX_ERR, e.code, 'syntax error expected');
+  }
+
+  is(SVGAngle.SVG_ANGLETYPE_RAD, m.orientAngle.baseVal.unitType, 'unexpected units');
+  m.orientAngle.baseVal.valueAsString = '2grad';
+  is(SVGAngle.SVG_ANGLETYPE_GRAD, m.orientAngle.baseVal.unitType, 'unexpected units');
+
+  try {
+    m.orientAngle.baseVal.valueAsString = 'rubbish';
+  } catch (e) {
+    is(DOMException.SYNTAX_ERR, e.code, 'syntax error expected');
+  }
+
+  SimpleTest.finish();
+}
+
+window.addEventListener("load", run, false);
+
+]]>
+</script>
+</pre>
+</body>
+</html>