Bug 983285 - Add a generic destructor for property values allocated with new. r=kats, r=bz

This commit is contained in:
Gorman Ho 2014-03-25 09:25:47 -04:00
parent fceee9b5aa
commit 2f3c5ba795
15 changed files with 34 additions and 185 deletions

View File

@ -691,6 +691,15 @@ public:
bool aTransfer = false,
void **aOldValue = nullptr);
/**
* A generic destructor for property values allocated with new.
*/
template<class T>
static void DeleteProperty(void *, nsIAtom *, void *aPropertyValue, void *)
{
delete static_cast<T *>(aPropertyValue);
}
/**
* Destroys a property associated with this node. The value is destroyed
* using the destruction function given when that value was set.

View File

@ -251,14 +251,6 @@ Element::LockedStyleStates() const
return nsEventStates();
}
static void
nsEventStatesPropertyDtor(void *aObject, nsIAtom *aProperty,
void *aPropertyValue, void *aData)
{
nsEventStates *states = static_cast<nsEventStates*>(aPropertyValue);
delete states;
}
void
Element::NotifyStyleStateChange(nsEventStates aStates)
{
@ -286,7 +278,8 @@ Element::LockStyleStates(nsEventStates aStates)
*locks &= ~NS_EVENT_STATE_VISITED;
}
SetProperty(nsGkAtoms::lockedStyleStates, locks, nsEventStatesPropertyDtor);
SetProperty(nsGkAtoms::lockedStyleStates, locks,
nsINode::DeleteProperty<nsEventStates>);
SetHasLockedStyleStates();
NotifyStyleStateChange(aStates);
@ -305,7 +298,8 @@ Element::UnlockStyleStates(nsEventStates aStates)
delete locks;
}
else {
SetProperty(nsGkAtoms::lockedStyleStates, locks, nsEventStatesPropertyDtor);
SetProperty(nsGkAtoms::lockedStyleStates, locks,
nsINode::DeleteProperty<nsEventStates>);
}
NotifyStyleStateChange(aStates);

View File

@ -2186,15 +2186,6 @@ nsINode::IsEqualNode(nsIDOMNode* aOther, bool* aReturn)
return NS_OK;
}
static void
nsCOMArrayDeleter(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
nsCOMArray<nsISupports>* objects =
static_cast<nsCOMArray<nsISupports>*>(aPropertyValue);
delete objects;
}
void
nsINode::BindObject(nsISupports* aObject)
{
@ -2202,7 +2193,8 @@ nsINode::BindObject(nsISupports* aObject)
static_cast<nsCOMArray<nsISupports>*>(GetProperty(nsGkAtoms::keepobjectsalive));
if (!objects) {
objects = new nsCOMArray<nsISupports>();
SetProperty(nsGkAtoms::keepobjectsalive, objects, nsCOMArrayDeleter, true);
SetProperty(nsGkAtoms::keepobjectsalive, objects,
nsINode::DeleteProperty< nsCOMArray<nsISupports> >, true);
}
objects->AppendObject(aObject);
}

View File

@ -302,16 +302,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsRange)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
static void
RangeHashTableDtor(void* aObject, nsIAtom* aPropertyName, void* aPropertyValue,
void* aData)
{
nsRange::RangeHashTable* ranges =
static_cast<nsRange::RangeHashTable*>(aPropertyValue);
delete ranges;
}
static void MarkDescendants(nsINode* aNode)
{
// Set NodeIsDescendantOfCommonAncestorForRangeInSelection on aNode's
@ -366,7 +356,8 @@ nsRange::RegisterCommonAncestor(nsINode* aNode)
static_cast<RangeHashTable*>(aNode->GetProperty(nsGkAtoms::range));
if (!ranges) {
ranges = new RangeHashTable;
aNode->SetProperty(nsGkAtoms::range, ranges, RangeHashTableDtor, true);
aNode->SetProperty(nsGkAtoms::range, ranges,
nsINode::DeleteProperty<nsRange::RangeHashTable>, true);
}
ranges->PutEntry(this);
aNode->SetCommonAncestorForRangeInSelection();

View File

@ -2411,20 +2411,6 @@ CanvasRenderingContext2D::MeasureText(const nsAString& rawText,
return new TextMetrics(width);
}
#ifdef ACCESSIBILITY
// Callback function, for freeing hit regions bounds values stored in property table
static void
ReleaseBBoxPropertyValue(void* aObject, /* unused */
nsIAtom* aPropertyName, /* unused */
void* aPropertyValue,
void* aData /* unused */)
{
nsRect* valPtr =
static_cast<nsRect*>(aPropertyValue);
delete valPtr;
}
#endif
void
CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorResult& error)
{
@ -2466,7 +2452,7 @@ CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorRes
*nsBounds = nsLayoutUtils::RoundGfxRectToAppRect(rect, AppUnitsPerCSSPixel());
options.mControl->DeleteProperty(nsGkAtoms::hitregion);
options.mControl->SetProperty(nsGkAtoms::hitregion, nsBounds,
ReleaseBBoxPropertyValue);
nsINode::DeleteProperty<nsRect>);
}
#endif

View File

@ -101,16 +101,6 @@ EventTargetIn(WidgetEvent* aEvent, nsIContent* aChild, nsIContent* aStop)
return false;
}
static void
DestroyMouseDownPoint(void * /*aObject*/,
nsIAtom * /*aPropertyName*/,
void * aPropertyValue,
void * /*aData*/)
{
LayoutDeviceIntPoint* pt = static_cast<LayoutDeviceIntPoint*>(aPropertyValue);
delete pt;
}
nsresult
HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
{
@ -139,7 +129,7 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
new LayoutDeviceIntPoint(mouseEvent->refPoint);
SetProperty(nsGkAtoms::labelMouseDownPtProperty,
static_cast<void*>(curPoint),
DestroyMouseDownPoint);
nsINode::DeleteProperty<LayoutDeviceIntPoint>);
}
break;

View File

@ -1043,26 +1043,13 @@ SVGSVGElement::ShouldSynthesizeViewBox() const
!GetParent();
}
// Callback function, for freeing SVGPreserveAspectRatio values stored in property table
static void
ReleasePreserveAspectRatioPropertyValue(void* aObject, /* unused */
nsIAtom* aPropertyName, /* unused */
void* aPropertyValue,
void* aData /* unused */)
{
SVGPreserveAspectRatio* valPtr =
static_cast<SVGPreserveAspectRatio*>(aPropertyValue);
delete valPtr;
}
bool
SVGSVGElement::SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR)
{
SVGPreserveAspectRatio* pAROverridePtr = new SVGPreserveAspectRatio(aPAR);
nsresult rv = SetProperty(nsGkAtoms::overridePreserveAspectRatio,
pAROverridePtr,
ReleasePreserveAspectRatioPropertyValue,
nsINode::DeleteProperty<SVGPreserveAspectRatio>,
true);
NS_ABORT_IF_FALSE(rv != NS_PROPTABLE_PROP_OVERWRITTEN,
"Setting override value when it's already set...?");
@ -1158,25 +1145,13 @@ SVGSVGElement::FlushImageTransformInvalidation()
}
}
// Callback function, for freeing nsSVGViewBoxRect values stored in property table
static void
ReleaseViewBoxPropertyValue(void* aObject, /* unused */
nsIAtom* aPropertyName, /* unused */
void* aPropertyValue,
void* aData /* unused */)
{
nsSVGViewBoxRect* valPtr =
static_cast<nsSVGViewBoxRect*>(aPropertyValue);
delete valPtr;
}
bool
SVGSVGElement::SetViewBoxProperty(const nsSVGViewBoxRect& aViewBox)
{
nsSVGViewBoxRect* pViewBoxOverridePtr = new nsSVGViewBoxRect(aViewBox);
nsresult rv = SetProperty(nsGkAtoms::viewBox,
pViewBoxOverridePtr,
ReleaseViewBoxPropertyValue,
nsINode::DeleteProperty<nsSVGViewBoxRect>,
true);
NS_ABORT_IF_FALSE(rv != NS_PROPTABLE_PROP_OVERWRITTEN,
"Setting override value when it's already set...?");
@ -1235,25 +1210,13 @@ SVGSVGElement::ClearZoomAndPanProperty()
return UnsetProperty(nsGkAtoms::zoomAndPan);
}
// Callback function, for freeing SVGTransformList values stored in property table
static void
ReleaseTransformPropertyValue(void* aObject, /* unused */
nsIAtom* aPropertyName, /* unused */
void* aPropertyValue,
void* aData /* unused */)
{
SVGTransformList* valPtr =
static_cast<SVGTransformList*>(aPropertyValue);
delete valPtr;
}
bool
SVGSVGElement::SetTransformProperty(const SVGTransformList& aTransform)
{
SVGTransformList* pTransformOverridePtr = new SVGTransformList(aTransform);
nsresult rv = SetProperty(nsGkAtoms::transform,
pTransformOverridePtr,
ReleaseTransformPropertyValue,
nsINode::DeleteProperty<SVGTransformList>,
true);
NS_ABORT_IF_FALSE(rv != NS_PROPTABLE_PROP_OVERWRITTEN,
"Setting override value when it's already set...?");

View File

@ -322,21 +322,6 @@ nsDOMWindowUtils::GetViewportInfo(uint32_t aDisplayWidth,
return NS_OK;
}
static void DestroyDisplayPortPropertyData(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
DisplayPortPropertyData* data =
static_cast<DisplayPortPropertyData*>(aPropertyValue);
delete data;
}
static void DestroyNsRect(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
nsRect* rect = static_cast<nsRect*>(aPropertyValue);
delete rect;
}
static void
MaybeReflowForInflationScreenWidthChange(nsPresContext *aPresContext)
{
@ -422,7 +407,7 @@ nsDOMWindowUtils::SetDisplayPortForElement(float aXPx, float aYPx,
content->SetProperty(nsGkAtoms::DisplayPort,
new DisplayPortPropertyData(displayport, aPriority),
DestroyDisplayPortPropertyData);
nsINode::DeleteProperty<DisplayPortPropertyData>);
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
if (rootScrollFrame) {
@ -505,7 +490,7 @@ nsDOMWindowUtils::SetCriticalDisplayPortForElement(float aXPx, float aYPx,
nsPresContext::CSSPixelsToAppUnits(aWidthPx),
nsPresContext::CSSPixelsToAppUnits(aHeightPx));
content->SetProperty(nsGkAtoms::CriticalDisplayPort, new nsRect(criticalDisplayport),
DestroyNsRect);
nsINode::DeleteProperty<nsRect>);
nsIFrame* rootFrame = presShell->GetRootFrame();
if (rootFrame) {

View File

@ -1510,15 +1510,6 @@ struct nsGenConInitializer {
: mNode(aNode), mList(aList), mDirtyAll(aDirtyAll) {}
};
static void
DestroyGenConInitializer(void* aFrame,
nsIAtom* aPropertyName,
void* aPropertyValue,
void* aDtorData)
{
delete static_cast<nsGenConInitializer*>(aPropertyValue);
}
already_AddRefed<nsIContent>
nsCSSFrameConstructor::CreateGenConTextNode(nsFrameConstructorState& aState,
const nsString& aString,
@ -1532,7 +1523,7 @@ nsCSSFrameConstructor::CreateGenConTextNode(nsFrameConstructorState& aState,
}
if (aInitializer) {
content->SetProperty(nsGkAtoms::genConInitializerProperty, aInitializer,
DestroyGenConInitializer);
nsINode::DeleteProperty<nsGenConInitializer>);
aState.mGeneratedTextNodesWithInitializer.AppendObject(content);
}
return content.forget();

View File

@ -3359,15 +3359,6 @@ static void ScrollToShowRect(nsIFrame* aFrame,
}
}
static void
DeleteScrollIntoViewData(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
PresShell::ScrollIntoViewData* data =
static_cast<PresShell::ScrollIntoViewData*>(aPropertyValue);
delete data;
}
nsresult
PresShell::ScrollContentIntoView(nsIContent* aContent,
nsIPresShell::ScrollAxis aVertical,
@ -3389,7 +3380,7 @@ PresShell::ScrollContentIntoView(nsIContent* aContent,
data->mContentScrollHAxis = aHorizontal;
data->mContentToScrollToFlags = aFlags;
if (NS_FAILED(mContentToScrollTo->SetProperty(nsGkAtoms::scrolling, data,
::DeleteScrollIntoViewData))) {
nsINode::DeleteProperty<PresShell::ScrollIntoViewData>))) {
mContentToScrollTo = nullptr;
}

View File

@ -13,15 +13,6 @@
using namespace mozilla;
void
IntPointDtorFunc(void *aObject, nsIAtom *aPropertyName,
void *aPropertyValue, void *aData)
{
nsIntPoint *propertyValue = static_cast<nsIntPoint*>(aPropertyValue);
delete propertyValue;
}
typedef nsImageFrame nsImageControlFrameSuper;
class nsImageControlFrame : public nsImageControlFrameSuper,
public nsIFormControlFrame
@ -107,7 +98,7 @@ nsImageControlFrame::Init(nsIContent* aContent,
mContent->SetProperty(nsGkAtoms::imageClickedPoint,
new nsIntPoint(0, 0),
IntPointDtorFunc);
nsINode::DeleteProperty<nsIntPoint>);
}
NS_QUERYFRAME_HEAD(nsImageControlFrame)

View File

@ -603,12 +603,6 @@ struct FlowLengthProperty {
// The offset of the next fixed continuation after mStartOffset, or
// of the end of the text if there is none
int32_t mEndFlowOffset;
static void Destroy(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
delete static_cast<FlowLengthProperty*>(aPropertyValue);
}
};
int32_t nsTextFrame::GetInFlowContentLength() {
@ -641,7 +635,7 @@ int32_t nsTextFrame::GetInFlowContentLength() {
if (!flowLength) {
flowLength = new FlowLengthProperty;
if (NS_FAILED(mContent->SetProperty(nsGkAtoms::flowlength, flowLength,
FlowLengthProperty::Destroy))) {
nsINode::DeleteProperty<FlowLengthProperty>))) {
delete flowLength;
flowLength = nullptr;
}
@ -7573,12 +7567,6 @@ struct NewlineProperty {
int32_t mStartOffset;
// The offset of the first \n after mStartOffset, or -1 if there is none
int32_t mNewlineOffset;
static void Destroy(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
delete static_cast<NewlineProperty*>(aPropertyValue);
}
};
nsresult
@ -8110,7 +8098,7 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
if (!cachedNewlineOffset) {
cachedNewlineOffset = new NewlineProperty;
if (NS_FAILED(mContent->SetProperty(nsGkAtoms::newline, cachedNewlineOffset,
NewlineProperty::Destroy))) {
nsINode::DeleteProperty<NewlineProperty>))) {
delete cachedNewlineOffset;
cachedNewlineOffset = nullptr;
}

View File

@ -679,13 +679,6 @@ nsSVGRenderingObserverList::RemoveAll()
}
}
static void
DestroyObservers(void *aObject, nsIAtom *aPropertyName,
void *aPropertyValue, void *aData)
{
delete static_cast<nsSVGRenderingObserverList*>(aPropertyValue);
}
void
nsSVGEffects::AddRenderingObserver(Element *aElement, nsSVGRenderingObserver *aObserver)
{
@ -694,7 +687,8 @@ nsSVGEffects::AddRenderingObserver(Element *aElement, nsSVGRenderingObserver *aO
observerList = new nsSVGRenderingObserverList();
if (!observerList)
return;
aElement->SetProperty(nsGkAtoms::renderingobserverlist, observerList, DestroyObservers);
aElement->SetProperty(nsGkAtoms::renderingobserverlist, observerList,
nsINode::DeleteProperty<nsSVGRenderingObserverList>);
}
aElement->SetHasRenderingObservers(true);
observerList->Add(aObserver);

View File

@ -447,15 +447,6 @@ nsResizerFrame::ResizeContent(nsIContent* aContent, const Direction& aDirection,
}
}
/* static */ void
nsResizerFrame::SizeInfoDtorFunc(void *aObject, nsIAtom *aPropertyName,
void *aPropertyValue, void *aData)
{
nsResizerFrame::SizeInfo *propertyValue =
static_cast<nsResizerFrame::SizeInfo*>(aPropertyValue);
delete propertyValue;
}
/* static */ void
nsResizerFrame::MaybePersistOriginalSize(nsIContent* aContent,
const SizeInfo& aSizeInfo)
@ -468,7 +459,7 @@ nsResizerFrame::MaybePersistOriginalSize(nsIContent* aContent,
nsAutoPtr<SizeInfo> sizeInfo(new SizeInfo(aSizeInfo));
rv = aContent->SetProperty(nsGkAtoms::_moz_original_size, sizeInfo.get(),
&SizeInfoDtorFunc);
nsINode::DeleteProperty<nsResizerFrame::SizeInfo>);
if (NS_SUCCEEDED(rv))
sizeInfo.forget();
}

View File

@ -323,14 +323,6 @@ APZCCallbackHelper::AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollI
}
}
static void
DestroyCSSPoint(void* aObject, nsIAtom* aPropertyName,
void* aPropertyValue, void* aData)
{
CSSPoint* point = static_cast<CSSPoint*>(aPropertyValue);
delete point;
}
void
APZCCallbackHelper::UpdateCallbackTransform(const FrameMetrics& aApzcMetrics, const FrameMetrics& aActualMetrics)
{
@ -339,7 +331,8 @@ APZCCallbackHelper::UpdateCallbackTransform(const FrameMetrics& aApzcMetrics, co
return;
}
CSSPoint scrollDelta = aApzcMetrics.GetScrollOffset() - aActualMetrics.GetScrollOffset();
content->SetProperty(nsGkAtoms::apzCallbackTransform, new CSSPoint(scrollDelta), DestroyCSSPoint);
content->SetProperty(nsGkAtoms::apzCallbackTransform, new CSSPoint(scrollDelta),
nsINode::DeleteProperty<CSSPoint>);
}
CSSPoint