Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp

Issue 2046973003: IntersectionObserver: throw exceptions as spec mandates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
diff --git a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
index f853921b9106c69b9035349d8a1941f22c9884c2..a4ebbfc3e8ca2f1f42ca17acc2d3207e3f0231e6 100644
--- a/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
+++ b/third_party/WebKit/Source/core/dom/IntersectionObserver.cpp
@@ -158,7 +158,8 @@ void IntersectionObserver::clearWeakMembers(Visitor* visitor)
{
if (ThreadHeap::isHeapObjectAlive(m_root))
return;
- disconnect();
+ IgnorableExceptionState exceptionState;
+ disconnect(exceptionState);
m_root = nullptr;
}
@@ -170,9 +171,14 @@ LayoutObject* IntersectionObserver::rootLayoutObject() const
return toElement(node)->layoutObject();
}
-void IntersectionObserver::observe(Element* target)
+void IntersectionObserver::observe(Element* target, ExceptionState& exceptionState)
{
- if (!m_root || !target || m_root.get() == target)
+ if (!m_root) {
+ exceptionState.throwDOMException(InvalidStateError, "observe() called on an IntersectionObserver with an invalid root.");
+ return;
+ }
+
+ if (!target || m_root.get() == target)
return;
if (target->ensureIntersectionObserverData().getObservationFor(*this))
@@ -192,8 +198,13 @@ void IntersectionObserver::observe(Element* target)
rootFrameView->scheduleAnimation();
}
-void IntersectionObserver::unobserve(Element* target)
+void IntersectionObserver::unobserve(Element* target, ExceptionState& exceptionState)
{
+ if (!m_root) {
+ exceptionState.throwDOMException(InvalidStateError, "unobserve() called on an IntersectionObserver with an invalid root.");
+ return;
+ }
+
if (!target || !target->intersectionObserverData())
return;
// TODO(szager): unobserve callback
@@ -214,8 +225,13 @@ void IntersectionObserver::computeIntersectionObservations()
observation->computeIntersectionObservations(timestamp);
}
-void IntersectionObserver::disconnect()
+void IntersectionObserver::disconnect(ExceptionState& exceptionState)
{
+ if (!m_root) {
+ exceptionState.throwDOMException(InvalidStateError, "disconnect() called on an IntersectionObserver with an invalid root.");
+ return;
+ }
+
for (auto& observation : m_observations)
observation->clearRootAndRemoveFromTarget();
m_observations.clear();
@@ -226,10 +242,15 @@ void IntersectionObserver::removeObservation(IntersectionObservation& observatio
m_observations.remove(&observation);
}
-HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords()
+HeapVector<Member<IntersectionObserverEntry>> IntersectionObserver::takeRecords(ExceptionState& exceptionState)
{
HeapVector<Member<IntersectionObserverEntry>> entries;
- entries.swap(m_entries);
+
+ if (!m_root)
+ exceptionState.throwDOMException(InvalidStateError, "takeRecords() called on an IntersectionObserver with an invalid root.");
+ else
+ entries.swap(m_entries);
+
return entries;
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/IntersectionObserver.h ('k') | third_party/WebKit/Source/core/dom/IntersectionObserver.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698