Skip to content

Commit

Permalink
Bug 1855836 - Make empty threshold list behavior match other browsers…
Browse files Browse the repository at this point in the history
…. r=smaug

Technically a broken test, but given other browsers' behavior and that
having no thresholds is useless, I don't think this edge-case is worth
fighting about.

See w3c/IntersectionObserver#516 for the spec
change.

Differential Revision: https://phabricator.services.mozilla.com/D189764
  • Loading branch information
emilio committed Oct 3, 2023
1 parent c2e7116 commit 9cee0ea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dom/base/DOMIntersectionObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ DOMIntersectionObserver::DOMIntersectionObserver(
dom::IntersectionCallback& aCb)
: mOwner(aOwner),
mDocument(mOwner->GetExtantDoc()),
mCallback(RefPtr<dom::IntersectionCallback>(&aCb)),
mConnected(false) {}
mCallback(RefPtr<dom::IntersectionCallback>(&aCb)) {}

already_AddRefed<DOMIntersectionObserver> DOMIntersectionObserver::Constructor(
const GlobalObject& aGlobal, dom::IntersectionCallback& aCb,
Expand Down Expand Up @@ -128,6 +127,9 @@ already_AddRefed<DOMIntersectionObserver> DOMIntersectionObserver::Constructor(
observer->mThresholds.AppendElement(thresh);
}
observer->mThresholds.Sort();
if (observer->mThresholds.IsEmpty()) {
observer->mThresholds.AppendElement(0.0);
}
} else {
double thresh = aOptions.mThreshold.GetAsDouble();
if (thresh < 0.0 || thresh > 1.0) {
Expand Down Expand Up @@ -174,8 +176,7 @@ DOMIntersectionObserver::DOMIntersectionObserver(Document& aDocument,
NativeCallback aCallback)
: mOwner(aDocument.GetInnerWindow()),
mDocument(&aDocument),
mCallback(aCallback),
mConnected(false) {}
mCallback(aCallback) {}

already_AddRefed<DOMIntersectionObserver>
DOMIntersectionObserver::CreateLazyLoadObserver(Document& aDocument) {
Expand Down
4 changes: 2 additions & 2 deletions dom/base/DOMIntersectionObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class DOMIntersectionObserver final : public nsISupports,
Variant<RefPtr<dom::IntersectionCallback>, NativeCallback> mCallback;
RefPtr<nsINode> mRoot;
StyleRect<LengthPercentage> mRootMargin;
nsTArray<double> mThresholds;
AutoTArray<double, 1> mThresholds;

// These hold raw pointers which are explicitly cleared by UnlinkTarget().
//
Expand All @@ -195,7 +195,7 @@ class DOMIntersectionObserver final : public nsISupports,
nsTHashSet<Element*> mObservationTargetSet;

nsTArray<RefPtr<DOMIntersectionObserverEntry>> mQueuedEntries;
bool mConnected;
bool mConnected = false;
};

NS_DEFINE_STATIC_IID_ACCESSOR(DOMIntersectionObserver,
Expand Down

This file was deleted.

0 comments on commit 9cee0ea

Please sign in to comment.