From 6fb72d4a3fa006c084526f60bb25b6e3ab41f55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 10 Feb 2022 00:38:45 +0000 Subject: [PATCH] Bug 1754579 - Don't keep so much alive when returning DOMRects & co. r=smaug We keep the parent alive for wrapping. It's unnecessary to keep alive the individual element / range / etc. Pass the relevant global / document. Differential Revision: https://phabricator.services.mozilla.com/D138357 --- dom/base/DOMIntersectionObserver.cpp | 8 ++++---- dom/base/Element.cpp | 2 +- dom/base/ResizeObserver.cpp | 10 +++++----- dom/base/nsRange.cpp | 9 ++++----- dom/events/PaintRequest.cpp | 2 +- dom/xul/XULPopupElement.cpp | 3 ++- dom/xul/XULTreeElement.cpp | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index 6fea5781beb7..16e1733b6c31 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -724,17 +724,17 @@ void DOMIntersectionObserver::QueueIntersectionObserverEntry( bool aIsIntersecting, double aIntersectionRatio) { RefPtr rootBounds; if (aRootRect.isSome()) { - rootBounds = new DOMRect(this); + rootBounds = new DOMRect(mOwner); rootBounds->SetLayoutRect(aRootRect.value()); } - RefPtr boundingClientRect = new DOMRect(this); + RefPtr boundingClientRect = new DOMRect(mOwner); boundingClientRect->SetLayoutRect(aTargetRect); - RefPtr intersectionRect = new DOMRect(this); + RefPtr intersectionRect = new DOMRect(mOwner); if (aIntersectionRect.isSome()) { intersectionRect->SetLayoutRect(aIntersectionRect.value()); } RefPtr entry = new DOMIntersectionObserverEntry( - this, time, rootBounds.forget(), boundingClientRect.forget(), + mOwner, time, rootBounds.forget(), boundingClientRect.forget(), intersectionRect.forget(), aIsIntersecting, aTarget, aIntersectionRatio); mQueuedEntries.AppendElement(entry.forget()); } diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 9db1f6ec0351..2e97ad69ec30 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1029,7 +1029,7 @@ nsRect Element::GetClientAreaRect() { } already_AddRefed Element::GetBoundingClientRect() { - RefPtr rect = new DOMRect(this); + RefPtr rect = new DOMRect(ToSupports(OwnerDoc())); nsIFrame* frame = GetPrimaryFrame(FlushType::Layout); if (!frame) { diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 5448ac4cccbb..a1fb0ce6daf1 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -325,7 +325,7 @@ uint32_t ResizeObserver::BroadcastActiveObservations() { gfx::Size devicePixelContentBoxSize = CalculateBoxSize( target, ResizeObserverBoxOptions::Device_pixel_content_box); RefPtr entry = - new ResizeObserverEntry(this, *target, borderBoxSize, contentBoxSize, + new ResizeObserverEntry(mOwner, *target, borderBoxSize, contentBoxSize, devicePixelContentBoxSize); if (!entries.AppendElement(entry.forget(), fallible)) { @@ -413,7 +413,7 @@ void ResizeObserverEntry::GetDevicePixelContentBoxSize( void ResizeObserverEntry::SetBorderBoxSize(const gfx::Size& aSize) { nsIFrame* frame = mTarget->GetPrimaryFrame(); const WritingMode wm = frame ? frame->GetWritingMode() : WritingMode(); - mBorderBoxSize = new ResizeObserverSize(this, aSize, wm); + mBorderBoxSize = new ResizeObserverSize(mOwner, aSize, wm); } void ResizeObserverEntry::SetContentRectAndSize(const gfx::Size& aSize) { @@ -425,19 +425,19 @@ void ResizeObserverEntry::SetContentRectAndSize(const gfx::Size& aSize) { // our contentRect. nsRect rect(nsPoint(padding.left, padding.top), CSSPixel::ToAppUnits(CSSSize::FromUnknownSize(aSize))); - RefPtr contentRect = new DOMRect(this); + RefPtr contentRect = new DOMRect(mOwner); contentRect->SetLayoutRect(rect); mContentRect = std::move(contentRect); // 2. Update mContentBoxSize. const WritingMode wm = frame ? frame->GetWritingMode() : WritingMode(); - mContentBoxSize = new ResizeObserverSize(this, aSize, wm); + mContentBoxSize = new ResizeObserverSize(mOwner, aSize, wm); } void ResizeObserverEntry::SetDevicePixelContentSize(const gfx::Size& aSize) { nsIFrame* frame = mTarget->GetPrimaryFrame(); const WritingMode wm = frame ? frame->GetWritingMode() : WritingMode(); - mDevicePixelContentBoxSize = new ResizeObserverSize(this, aSize, wm); + mDevicePixelContentBoxSize = new ResizeObserverSize(mOwner, aSize, wm); } NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ResizeObserverSize, mOwner) diff --git a/dom/base/nsRange.cpp b/dom/base/nsRange.cpp index 96425a6743b3..66815388be97 100644 --- a/dom/base/nsRange.cpp +++ b/dom/base/nsRange.cpp @@ -94,7 +94,7 @@ DocGroup* nsRange::GetDocGroup() const { } /****************************************************** - * stack based utilty class for managing monitor + * stack based utility class for managing monitor ******************************************************/ static void InvalidateAllFrames(nsINode* aNode) { @@ -2785,7 +2785,7 @@ void nsRange::CollectClientRectsAndText( already_AddRefed nsRange::GetBoundingClientRect(bool aClampToEdge, bool aFlushLayout) { - RefPtr rect = new DOMRect(ToSupports(this)); + RefPtr rect = new DOMRect(ToSupports(mOwner)); if (!mIsPositioned) { return rect.forget(); } @@ -2810,8 +2810,7 @@ already_AddRefed nsRange::GetClientRects(bool aClampToEdge, return nullptr; } - RefPtr rectList = - new DOMRectList(static_cast(this)); + RefPtr rectList = new DOMRectList(ToSupports(mOwner)); nsLayoutUtils::RectListBuilder builder(rectList); @@ -2830,7 +2829,7 @@ void nsRange::GetClientRectsAndTexts(mozilla::dom::ClientRectsAndTexts& aResult, return; } - aResult.mRectList = new DOMRectList(static_cast(this)); + aResult.mRectList = new DOMRectList(ToSupports(mOwner)); nsLayoutUtils::RectListBuilder builder(aResult.mRectList); diff --git a/dom/events/PaintRequest.cpp b/dom/events/PaintRequest.cpp index 9790e7cc2244..0cb4fbd9406d 100644 --- a/dom/events/PaintRequest.cpp +++ b/dom/events/PaintRequest.cpp @@ -33,7 +33,7 @@ JSObject* PaintRequest::WrapObject(JSContext* aCx, } already_AddRefed PaintRequest::ClientRect() { - RefPtr clientRect = new DOMRect(this); + RefPtr clientRect = new DOMRect(mParent); clientRect->SetLayoutRect(mRequest); return clientRect.forget(); } diff --git a/dom/xul/XULPopupElement.cpp b/dom/xul/XULPopupElement.cpp index c4ee7c56b978..ab0acc0f2c27 100644 --- a/dom/xul/XULPopupElement.cpp +++ b/dom/xul/XULPopupElement.cpp @@ -12,6 +12,7 @@ #include "nsView.h" #include "mozilla/AppUnits.h" #include "mozilla/dom/DOMRect.h" +#include "mozilla/dom/Document.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/XULPopupElement.h" @@ -256,7 +257,7 @@ Element* XULPopupElement::GetAnchorNode() const { } already_AddRefed XULPopupElement::GetOuterScreenRect() { - RefPtr rect = new DOMRect(ToSupports(this)); + RefPtr rect = new DOMRect(ToSupports(OwnerDoc())); // Return an empty rectangle if the popup is not open. nsMenuPopupFrame* menuPopupFrame = diff --git a/dom/xul/XULTreeElement.cpp b/dom/xul/XULTreeElement.cpp index 7e86190d6dfe..640a17852b90 100644 --- a/dom/xul/XULTreeElement.cpp +++ b/dom/xul/XULTreeElement.cpp @@ -351,8 +351,8 @@ already_AddRefed XULTreeElement::GetCoordsForCellItem( nsIntRect rect = GetCoordsForCellItem(aRow, &aCol, aElement, rv); aRv = rv; - RefPtr domRect = - new DOMRect(this, rect.x, rect.y, rect.width, rect.height); + RefPtr domRect = new DOMRect(ToSupports(OwnerDoc()), rect.x, rect.y, + rect.width, rect.height); return domRect.forget(); }