dom/svg/nsISVGPoint.cpp
author J.C. Jones <jjones@mozilla.com>
Wed, 12 Jun 2019 23:22:22 +0000
changeset 478563 547109ab8d7bb037fa42996e1837f7d231b5d615
parent 451665 2d778b55d6bee9fcd82ad71b2719c2ae7b358674
child 494423 028bdd1fae711520c7e621811b940bb9bea64b37
permissions -rw-r--r--
Bug 1558977 - Upgrade NSS 3.45 r=keeler Differential Revision: https://phabricator.services.mozilla.com/D34784

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#include "nsISVGPoint.h"
#include "DOMSVGPointList.h"
#include "SVGPoint.h"
#include "SVGElement.h"
#include "nsError.h"
#include "mozilla/dom/SVGPointBinding.h"

// See the architecture comment in DOMSVGPointList.h.

using namespace mozilla;

// We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
// clear our list's weak ref to us to be safe. (The other option would be to
// not unlink and rely on the breaking of the other edges in the cycle, as
// NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsISVGPoint)

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsISVGPoint)
  // We may not belong to a list, so we must null check tmp->mList.
  if (tmp->mList) {
    tmp->mList->mItems[tmp->mListIndex] = nullptr;
  }
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mList)
  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsISVGPoint)
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsISVGPoint)
  NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END

NS_IMPL_CYCLE_COLLECTING_ADDREF(nsISVGPoint)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsISVGPoint)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsISVGPoint)
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  NS_INTERFACE_MAP_ENTRY(nsISVGPoint)
  NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

void nsISVGPoint::InsertingIntoList(DOMSVGPointList* aList, uint32_t aListIndex,
                                    bool aIsAnimValItem) {
  MOZ_ASSERT(!HasOwner(), "Inserting item that already has an owner");

  mList = aList;
  mListIndex = aListIndex;
  mIsReadonly = false;
  mIsAnimValItem = aIsAnimValItem;

  MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGPoint!");
}

void nsISVGPoint::RemovingFromList() {
  mPt = InternalItem();
  mList = nullptr;
  MOZ_ASSERT(!mIsReadonly, "mIsReadonly set for list");
  mIsAnimValItem = false;
}

SVGPoint& nsISVGPoint::InternalItem() {
  return mList->InternalList().mItems[mListIndex];
}

#ifdef DEBUG
bool nsISVGPoint::IndexIsValid() {
  return mListIndex < mList->InternalList().Length();
}
#endif