Bug 648094. r=dholbert, a=dveditz.
authorJonathan Watt <jwatt@jwatt.org>
Sun, 08 May 2011 18:20:41 +0100
changeset 27407 2acbfab37f69ff5afd758cb5c06e39a4c752cc16
parent 27406 e97fac945e09ab380fdedf86b56ff1dd83248ccb
child 27408 ce0dd43871e2f8e1868ecc39f48b701a2a597a2a
push id2721
push userjwatt@jwatt.org
push dateSun, 08 May 2011 17:38:43 +0000
reviewersdholbert, dveditz
bugs648094
milestone1.9.1.20pre
Bug 648094. r=dholbert, a=dveditz.
content/svg/content/src/nsSVGLengthList.cpp
content/svg/content/src/nsSVGPoint.h
content/svg/content/src/nsSVGPointList.cpp
--- a/content/svg/content/src/nsSVGLengthList.cpp
+++ b/content/svg/content/src/nsSVGLengthList.cpp
@@ -209,17 +209,18 @@ NS_IMETHODIMP nsSVGLengthList::Clear()
   DidModify();
   return NS_OK;
 }
 
 /* nsIDOMSVGLength initialize (in nsIDOMSVGLength newItem); */
 NS_IMETHODIMP nsSVGLengthList::Initialize(nsIDOMSVGLength *newItem,
                                           nsIDOMSVGLength **_retval)
 {
-  if (!newItem) {
+  nsCOMPtr<nsISVGLength> length = do_QueryInterface(newItem);
+  if (!length) {
     *_retval = nsnull;
     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
   }
   Clear();
   return AppendItem(newItem, _retval);
 }
 
 /* nsIDOMSVGLength getItem (in unsigned long index); */
--- a/content/svg/content/src/nsSVGPoint.h
+++ b/content/svg/content/src/nsSVGPoint.h
@@ -38,16 +38,25 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_SVGPOINT_H__
 #define __NS_SVGPOINT_H__
 
 #include "nsIDOMSVGPoint.h"
 #include "gfxPoint.h"
 
+#define NS_ENSURE_NATIVE_SVG_POINT(obj, retval)                \
+  {                                                            \
+    nsresult rv;                                               \
+    if (retval)                                                \
+      *retval = nsnull;                                        \
+    nsCOMPtr<nsISVGValue> point = do_QueryInterface(obj, &rv); \
+    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SVG_WRONG_TYPE_ERR);    \
+  }
+
 nsresult
 NS_NewSVGPoint(nsIDOMSVGPoint** result, float x = 0.0f, float y = 0.0f);
 
 nsresult
 NS_NewSVGPoint(nsIDOMSVGPoint** result, const gfxPoint& point);
 
 nsresult
 NS_NewSVGReadonlyPoint(nsIDOMSVGPoint** result, float x = 0.0f, float y = 0.0f);
--- a/content/svg/content/src/nsSVGPointList.cpp
+++ b/content/svg/content/src/nsSVGPointList.cpp
@@ -260,20 +260,17 @@ NS_IMETHODIMP nsSVGPointList::Clear()
   DidModify();
   return NS_OK;
 }
 
 /* nsIDOMSVGPoint initialize (in nsIDOMSVGPoint newItem); */
 NS_IMETHODIMP nsSVGPointList::Initialize(nsIDOMSVGPoint *newItem,
                                          nsIDOMSVGPoint **_retval)
 {
-  if (!newItem) {
-    *_retval = nsnull;
-    return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
-  }
+  NS_ENSURE_NATIVE_SVG_POINT(newItem, _retval);
   Clear();
   return AppendItem(newItem, _retval);
 }
 
 /* nsIDOMSVGPoint getItem (in unsigned long index); */
 NS_IMETHODIMP nsSVGPointList::GetItem(PRUint32 index, nsIDOMSVGPoint **_retval)
 {
   if (index >= static_cast<PRUint32>(mPoints.Count())) {
@@ -331,19 +328,18 @@ NS_IMETHODIMP nsSVGPointList::RemoveItem
 /* nsIDOMSVGPoint appendItem (in nsIDOMSVGPoint newItem); */
 NS_IMETHODIMP nsSVGPointList::AppendItem(nsIDOMSVGPoint *newItem,
                                          nsIDOMSVGPoint **_retval)
 {
   // XXX The SVG specs state that 'if newItem is already in a list, it
   // is removed from its previous list before it is inserted into this
   // list'. We don't do that. Should we?
   
+  NS_ENSURE_NATIVE_SVG_POINT(newItem, _retval);
   *_retval = newItem;
-  if (!newItem)
-    return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
   AppendElement(newItem);
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
 // nsISVGValueObserver methods