void DOMSVGPointList::InternalListWillChangeTo(const SVGPointList& aNewValue) { // When the number of items in our internal counterpart changes, we MUST stay // in sync. Everything in the scary comment in // DOMSVGLengthList::InternalBaseValListWillChangeTo applies here too! PRUint32 oldLength = mItems.Length(); PRUint32 newLength = aNewValue.Length(); if (newLength > DOMSVGPoint::MaxListIndex()) { // It's safe to get out of sync with our internal list as long as we have // FEWER items than it does. newLength = DOMSVGPoint::MaxListIndex(); } // If our length will decrease, notify the items that will be removed: for (PRUint32 i = newLength; i < oldLength; ++i) { if (mItems[i]) { mItems[i]->RemovingFromList(); } } if (!mItems.SetLength(newLength)) { // We silently ignore SetLength OOM failure since being out of sync is safe // so long as we have *fewer* items than our internal list. mItems.Clear(); return; } // If our length has increased, null out the new pointers: for (PRUint32 i = oldLength; i < newLength; ++i) { mItems[i] = nsnull; } }
nsresult SVGPointList::CopyFrom(const SVGPointList& rhs) { if (!SetCapacity(rhs.Length())) { // Yes, we do want fallible alloc here return NS_ERROR_OUT_OF_MEMORY; } mItems = rhs.mItems; return NS_OK; }
void DOMSVGPointList::InternalListWillChangeTo(const SVGPointList& aNewValue) { // When the number of items in our internal counterpart changes, we MUST stay // in sync. Everything in the scary comment in // DOMSVGLengthList::InternalBaseValListWillChangeTo applies here too! uint32_t oldLength = mItems.Length(); uint32_t newLength = aNewValue.Length(); if (newLength > nsISVGPoint::MaxListIndex()) { // It's safe to get out of sync with our internal list as long as we have // FEWER items than it does. newLength = nsISVGPoint::MaxListIndex(); } RefPtr<DOMSVGPointList> kungFuDeathGrip; if (newLength < oldLength) { // RemovingFromList() might clear last reference to |this|. // Retain a temporary reference to keep from dying before returning. kungFuDeathGrip = this; } // If our length will decrease, notify the items that will be removed: for (uint32_t i = newLength; i < oldLength; ++i) { if (mItems[i]) { mItems[i]->RemovingFromList(); } } if (!mItems.SetLength(newLength, fallible)) { // We silently ignore SetLength OOM failure since being out of sync is safe // so long as we have *fewer* items than our internal list. mItems.Clear(); return; } // If our length has increased, null out the new pointers: for (uint32_t i = oldLength; i < newLength; ++i) { mItems[i] = nullptr; } }