diff --git a/content/svg/content/src/DOMSVGLengthList.cpp b/content/svg/content/src/DOMSVGLengthList.cpp index 1c57a55240c..16389c7b95f 100644 --- a/content/svg/content/src/DOMSVGLengthList.cpp +++ b/content/svg/content/src/DOMSVGLengthList.cpp @@ -176,7 +176,18 @@ DOMSVGLengthList::Initialize(nsIDOMSVGLength *newItem, return InsertItemBefore(newItem, 0, error); } -nsIDOMSVGLength* +already_AddRefed +DOMSVGLengthList::GetItem(uint32_t index, ErrorResult& error) +{ + bool found; + nsRefPtr item = IndexedGetter(index, found, error); + if (!found) { + error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + } + return item.forget(); +} + +already_AddRefed DOMSVGLengthList::IndexedGetter(uint32_t index, bool& found, ErrorResult& error) { if (IsAnimValList()) { @@ -184,8 +195,7 @@ DOMSVGLengthList::IndexedGetter(uint32_t index, bool& found, ErrorResult& error) } found = index < LengthNoFlush(); if (found) { - EnsureItemAt(index); - return mItems[index]; + return GetItemAt(index); } return nullptr; } @@ -307,13 +317,12 @@ DOMSVGLengthList::RemoveItem(uint32_t index, // internal value. MaybeRemoveItemFromAnimValListAt(index); - // We have to return the removed item, so make sure it exists: - EnsureItemAt(index); + // We have to return the removed item, so get it, creating it if necessary: + nsCOMPtr result = GetItemAt(index); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: mItems[index]->RemovingFromList(); - nsCOMPtr result = mItems[index]; InternalList().RemoveItem(index); mItems.RemoveElementAt(index); @@ -327,12 +336,16 @@ DOMSVGLengthList::RemoveItem(uint32_t index, return result.forget(); } -void -DOMSVGLengthList::EnsureItemAt(uint32_t aIndex) +already_AddRefed +DOMSVGLengthList::GetItemAt(uint32_t aIndex) { + MOZ_ASSERT(aIndex < mItems.Length()); + if (!mItems[aIndex]) { mItems[aIndex] = new DOMSVGLength(this, AttrEnum(), aIndex, IsAnimValList()); } + nsRefPtr result = mItems[aIndex]; + return result.forget(); } void diff --git a/content/svg/content/src/DOMSVGLengthList.h b/content/svg/content/src/DOMSVGLengthList.h index 74bc6ae63c8..4a8c049d5eb 100644 --- a/content/svg/content/src/DOMSVGLengthList.h +++ b/content/svg/content/src/DOMSVGLengthList.h @@ -103,17 +103,10 @@ public: void Clear(ErrorResult& aError); already_AddRefed Initialize(nsIDOMSVGLength *newItem, ErrorResult& error); - nsIDOMSVGLength* GetItem(uint32_t index, ErrorResult& error) - { - bool found; - nsIDOMSVGLength* item = IndexedGetter(index, found, error); - if (!found) { - error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); - } - return item; - } - nsIDOMSVGLength* IndexedGetter(uint32_t index, bool& found, - ErrorResult& error); + already_AddRefed GetItem(uint32_t index, + ErrorResult& error); + already_AddRefed IndexedGetter(uint32_t index, bool& found, + ErrorResult& error); already_AddRefed InsertItemBefore(nsIDOMSVGLength *newItem, uint32_t index, ErrorResult& error); @@ -163,8 +156,8 @@ private: */ SVGLengthList& InternalList() const; - /// Creates a DOMSVGLength for aIndex, if it doesn't already exist. - void EnsureItemAt(uint32_t aIndex); + /// Returns the nsIDOMSVGLength at aIndex, creating it if necessary. + already_AddRefed GetItemAt(uint32_t aIndex); void MaybeInsertNullInAnimValListAt(uint32_t aIndex); void MaybeRemoveItemFromAnimValListAt(uint32_t aIndex); diff --git a/content/svg/content/src/crashtests/880544-2.svg b/content/svg/content/src/crashtests/880544-2.svg new file mode 100644 index 00000000000..7570c7cbfeb --- /dev/null +++ b/content/svg/content/src/crashtests/880544-2.svg @@ -0,0 +1,15 @@ + + + + foo + + diff --git a/content/svg/content/src/crashtests/crashtests.list b/content/svg/content/src/crashtests/crashtests.list index ae80b918922..67ef24a905d 100644 --- a/content/svg/content/src/crashtests/crashtests.list +++ b/content/svg/content/src/crashtests/crashtests.list @@ -67,3 +67,4 @@ load 837450-1.svg load 842463-1.html load 864509.svg load 880544-1.svg +load 880544-2.svg diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index d20ca962565..c3b7ae1495d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -933,8 +933,7 @@ DOMInterfaces = { 'SVGLengthList': { 'nativeType': 'mozilla::DOMSVGLengthList', - 'headerFile': 'DOMSVGLengthList.h', - 'resultNotAddRefed': [ 'getItem' ] + 'headerFile': 'DOMSVGLengthList.h' }, 'SVGLinearGradientElement': {