Bug 816778 Part 7: Convert SVGAnimatedNumberList to WebIDL r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 22 Dec 2012 23:54:21 -0500
changeset 126022 94ed53f03fd1374934534e3e4a2855e3732564f4
parent 126021 00c8e8d5fe04c1d1a29d2d04e06f61064eedaae5
child 126023 7fc1c750ee0cc54288a1190c8a4b57039f2e3337
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs816778
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816778 Part 7: Convert SVGAnimatedNumberList to WebIDL r=bz
content/svg/content/src/DOMSVGAnimatedNumberList.cpp
content/svg/content/src/DOMSVGAnimatedNumberList.h
dom/bindings/Bindings.conf
dom/webidl/SVGAnimatedNumberList.webidl
dom/webidl/WebIDL.mk
--- a/content/svg/content/src/DOMSVGAnimatedNumberList.cpp
+++ b/content/svg/content/src/DOMSVGAnimatedNumberList.cpp
@@ -4,56 +4,94 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DOMSVGAnimatedNumberList.h"
 #include "DOMSVGNumberList.h"
 #include "SVGAnimatedNumberList.h"
 #include "nsSVGElement.h"
 #include "nsCOMPtr.h"
 #include "nsSVGAttrTearoffTable.h"
+#include "mozilla/dom/SVGAnimatedNumberListBinding.h"
 
 // See the architecture comment in this file's header.
 
 namespace mozilla {
 
 static nsSVGAttrTearoffTable<SVGAnimatedNumberList, DOMSVGAnimatedNumberList>
   sSVGAnimatedNumberListTearoffTable;
 
-NS_SVG_VAL_IMPL_CYCLE_COLLECTION(DOMSVGAnimatedNumberList, mElement)
+NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGAnimatedNumberList)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGAnimatedNumberList)
+// No unlinking mElement, we'd need to null out the value pointer (the object it
+// points to is held by the element) and null-check it everywhere.
+NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGAnimatedNumberList)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGAnimatedNumberList)
+NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
+NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedNumberList)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedNumberList)
 
 } // namespace mozilla
 DOMCI_DATA(SVGAnimatedNumberList, mozilla::DOMSVGAnimatedNumberList)
 namespace mozilla {
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedNumberList)
+  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedNumberList)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedNumberList)
 NS_INTERFACE_MAP_END
 
-NS_IMETHODIMP
-DOMSVGAnimatedNumberList::GetBaseVal(nsIDOMSVGNumberList **_retval)
+JSObject*
+DOMSVGAnimatedNumberList::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
+{
+  return mozilla::dom::SVGAnimatedNumberListBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
+already_AddRefed<DOMSVGNumberList>
+DOMSVGAnimatedNumberList::BaseVal()
 {
   if (!mBaseVal) {
     mBaseVal = new DOMSVGNumberList(this, InternalAList().GetBaseValue());
   }
-  NS_ADDREF(*_retval = mBaseVal);
+  nsRefPtr<DOMSVGNumberList> baseVal = mBaseVal;
+  return baseVal.forget();
+}
+
+/* readonly attribute nsIDOMSVGNumberList baseVal; */
+NS_IMETHODIMP
+DOMSVGAnimatedNumberList::GetBaseVal(nsIDOMSVGNumberList** aBaseVal)
+{
+  *aBaseVal = BaseVal().get();
   return NS_OK;
 }
 
-NS_IMETHODIMP
-DOMSVGAnimatedNumberList::GetAnimVal(nsIDOMSVGNumberList **_retval)
+already_AddRefed<DOMSVGNumberList>
+DOMSVGAnimatedNumberList::AnimVal()
 {
   if (!mAnimVal) {
     mAnimVal = new DOMSVGNumberList(this, InternalAList().GetAnimValue());
   }
-  NS_ADDREF(*_retval = mAnimVal);
+  nsRefPtr<DOMSVGNumberList> animVal = mAnimVal;
+  return animVal.forget();
+}
+
+/* readonly attribute nsIDOMSVGNumberList animVal; */
+NS_IMETHODIMP
+DOMSVGAnimatedNumberList::GetAnimVal(nsIDOMSVGNumberList** aAnimVal)
+{
+  *aAnimVal = AnimVal().get();
   return NS_OK;
 }
 
 /* static */ already_AddRefed<DOMSVGAnimatedNumberList>
 DOMSVGAnimatedNumberList::GetDOMWrapper(SVGAnimatedNumberList *aList,
                                         nsSVGElement *aElement,
                                         uint8_t aAttrEnum)
 {
--- a/content/svg/content/src/DOMSVGAnimatedNumberList.h
+++ b/content/svg/content/src/DOMSVGAnimatedNumberList.h
@@ -6,16 +6,17 @@
 #ifndef MOZILLA_DOMSVGANIMATEDNUMBERLIST_H__
 #define MOZILLA_DOMSVGANIMATEDNUMBERLIST_H__
 
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDOMSVGAnimatedNumberList.h"
 #include "nsSVGElement.h"
+#include "nsWrapperCache.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 
 class DOMSVGNumberList;
 class SVGAnimatedNumberList;
 class SVGNumberList;
 
@@ -29,23 +30,24 @@ class SVGNumberList;
  * LENGTH list). The comment for that class largly applies to this one too
  * and will go a long way to helping you understand the architecture here.
  *
  * This class is strongly intertwined with DOMSVGNumberList and DOMSVGNumber.
  * Our DOMSVGNumberList base and anim vals are friends and take care of nulling
  * out our pointers to them when they die (making our pointers to them true
  * weak refs).
  */
-class DOMSVGAnimatedNumberList MOZ_FINAL : public nsIDOMSVGAnimatedNumberList
+class DOMSVGAnimatedNumberList MOZ_FINAL : public nsIDOMSVGAnimatedNumberList,
+                                           public nsWrapperCache
 {
   friend class DOMSVGNumberList;
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(DOMSVGAnimatedNumberList)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedNumberList)
   NS_DECL_NSIDOMSVGANIMATEDNUMBERLIST
 
   /**
    * Factory method to create and return a DOMSVGAnimatedNumberList wrapper
    * for a given internal SVGAnimatedNumberList object. The factory takes care
    * of caching the object that it returns so that the same object can be
    * returned for the given SVGAnimatedNumberList each time it is requested.
    * The cached object is only removed from the cache when it is destroyed due
@@ -83,16 +85,23 @@ public:
   void InternalAnimValListWillChangeTo(const SVGNumberList& aNewValue);
 
   /**
    * Returns true if our attribute is animating (in which case our animVal is
    * not simply a mirror of our baseVal).
    */
   bool IsAnimating() const;
 
+  // WebIDL
+  nsSVGElement* GetParentObject() const { return mElement; }
+  virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
+  // These aren't weak refs because mBaseVal and mAnimVal are weak
+  already_AddRefed<DOMSVGNumberList> BaseVal();
+  already_AddRefed<DOMSVGNumberList> AnimVal();
+
 private:
 
   /**
    * Only our static GetDOMWrapper() factory method may create objects of our
    * type.
    */
   DOMSVGAnimatedNumberList(nsSVGElement *aElement, uint8_t aAttrEnum)
     : mBaseVal(nullptr)
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -436,16 +436,21 @@ DOMInterfaces = {
     'resultNotAddRefed': [ "alpha", "blue", "green", "red" ]
 },
 
 'Screen': {
     'nativeType': 'nsScreen',
     'prefable': True,
 },
 
+'SVGAnimatedNumberList': {
+    'nativeType': 'mozilla::DOMSVGAnimatedNumberList',
+    'headerFile': 'DOMSVGAnimatedNumberList.h'
+},
+
 'SVGAnimatedPreserveAspectRatio': {
     'nativeType': 'mozilla::dom::DOMSVGAnimatedPreserveAspectRatio',
     'headerFile': 'SVGAnimatedPreserveAspectRatio.h'
 },
 
 'SVGAnimatedTransformList': {
     'nativeType': 'mozilla::DOMSVGAnimatedTransformList',
     'headerFile': 'DOMSVGAnimatedTransformList.h'
new file mode 100644
--- /dev/null
+++ b/dom/webidl/SVGAnimatedNumberList.webidl
@@ -0,0 +1,19 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is
+ * http://www.w3.org/TR/SVG2/
+ *
+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+
+interface SVGAnimatedNumberList {
+  [Constant]
+  readonly attribute SVGNumberList baseVal;
+  [Constant]
+  readonly attribute SVGNumberList animVal;
+};
+
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -63,16 +63,17 @@ webidl_files = \
   PaintRequest.webidl \
   PaintRequestList.webidl \
   PannerNode.webidl \
   Performance.webidl \
   PerformanceNavigation.webidl \
   PerformanceTiming.webidl \
   RGBColor.webidl \
   Screen.webidl \
+  SVGAnimatedNumberList.webidl \
   SVGAnimatedPreserveAspectRatio.webidl \
   SVGAnimatedTransformList.webidl \
   SVGLengthList.webidl \
   SVGMatrix.webidl \
   SVGNumberList.webidl \
   SVGPathSegList.webidl \
   SVGPoint.webidl \
   SVGPointList.webidl \