RESOLVED FIXED 208047
[intersection-observer] Accept a Document as an explicit root
https://bugs.webkit.org/show_bug.cgi?id=208047
Summary [intersection-observer] Accept a Document as an explicit root
Attachments
IDL changes (879 bytes, patch)
2020-02-21 03:57 PST, Frédéric Wang (:fredw)
no flags
Patch (WIP) (6.06 KB, patch)
2020-02-21 08:22 PST, Frédéric Wang (:fredw)
no flags
Patch (9.99 KB, patch)
2020-02-22 03:48 PST, Frédéric Wang (:fredw)
no flags
Patch (77.09 KB, patch)
2020-02-24 00:08 PST, Frédéric Wang (:fredw)
no flags
Patch (78.87 KB, patch)
2020-02-25 02:15 PST, Frédéric Wang (:fredw)
no flags
Patch (13.86 KB, patch)
2020-03-03 23:22 PST, Frédéric Wang (:fredw)
no flags
Patch (19.15 KB, patch)
2020-03-05 01:09 PST, Frédéric Wang (:fredw)
simon.fraser: review+
Patch for landing (19.44 KB, patch)
2020-03-06 02:54 PST, Frédéric Wang (:fredw)
no flags
patch for ews (646 bytes, patch)
2020-03-17 07:31 PDT, Frédéric Wang (:fredw)
no flags
Patch (address post-landing review comment) (1.28 KB, patch)
2020-03-18 00:09 PDT, Frédéric Wang (:fredw)
no flags
Patch (address post-landing review comment) (918 bytes, patch)
2020-03-18 00:17 PDT, Frédéric Wang (:fredw)
no flags
Patch (address post-landing review comment) (2.88 KB, patch)
2020-03-18 00:35 PDT, Frédéric Wang (:fredw)
no flags
Patch for landing (3.87 KB, patch)
2020-03-18 10:01 PDT, Frédéric Wang (:fredw)
no flags
Frédéric Wang (:fredw)
Comment 1 2020-02-21 08:22:37 PST
Created attachment 391401 [details] Patch (WIP)
Frédéric Wang (:fredw)
Comment 2 2020-02-22 03:48:31 PST
Frédéric Wang (:fredw)
Comment 3 2020-02-24 00:08:21 PST
Ali Juma
Comment 4 2020-02-24 07:06:02 PST
Comment on attachment 391516 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391516&action=review Thanks for working on this! The patch generally looks great. A few comments: > Source/JavaScriptCore/ChangeLog:7 > + IntersectionObserverDocumentAsExplicitRootEnabled that enables a recent Do we need a flag for this? It seems like a small change that has already shipped in another browser, so adding a flag probably adds more complexity than it's worth. > Source/WebCore/dom/Document.cpp:7719 > + Document's destructor needs to iterate over m_documentExplicitIntersectionObserverData and call observer->rootDestroyed() on each one, just like Element's destructor does (see Element::disconnectFromIntersectionObservers()). > Source/WebCore/page/IntersectionObserver.cpp:145 > +Document* IntersectionObserver::trackingDocument() const I believe the existing implementation (in the ..h) file will already do what's needed, since m_root->document() will return itself when m_root is a Document. > Source/WebCore/page/IntersectionObserver.idl:51 > + // FIXME(fwang): Ideally, this should be written '(Element or Document)? = null' but that's not properly supported by WebKit's IDL generator. Please file a bug for this if you haven't already.
Frédéric Wang (:fredw)
Comment 5 2020-02-24 23:41:17 PST
Comment on attachment 391516 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391516&action=review >> Source/JavaScriptCore/ChangeLog:7 >> + IntersectionObserverDocumentAsExplicitRootEnabled that enables a recent > > Do we need a flag for this? It seems like a small change that has already shipped in another browser, so adding a flag probably adds more complexity than it's worth. Yes, I'm not really sure about this. Let's see what other reviewers say. >> Source/WebCore/dom/Document.cpp:7719 >> + > > Document's destructor needs to iterate over m_documentExplicitIntersectionObserverData and call observer->rootDestroyed() on each one, just like Element's destructor does (see Element::disconnectFromIntersectionObservers()). Good catch! I guess this will depend on where the this is stored at the end. > Source/WebCore/dom/Document.h:1829 > + // FIXME(fwang): Make this a rare data? I guess that's more a question for reviewers than a follow-up task. Basically I see three options: (1) Keep it as it (increase the size) (2) Use rare data in Node (maybe move the Element's one too? that might affect the size of other Nodes) (3) New rare data in Document (that will still increase the size though) >> Source/WebCore/page/IntersectionObserver.cpp:145 >> +Document* IntersectionObserver::trackingDocument() const > > I believe the existing implementation (in the ..h) file will already do what's needed, since m_root->document() will return itself when m_root is a Document. I think you are correct. I was not sure whether I would have to do some special handling for the Document case, that's why I move it to cpp, but that does not seem necessary. >> Source/WebCore/page/IntersectionObserver.idl:51 >> + // FIXME(fwang): Ideally, this should be written '(Element or Document)? = null' but that's not properly supported by WebKit's IDL generator. > > Please file a bug for this if you haven't already. Yes, I'll take care of that.
Frédéric Wang (:fredw)
Comment 6 2020-02-25 02:15:18 PST
Frédéric Wang (:fredw)
Comment 7 2020-02-25 02:19:10 PST
Comment on attachment 391516 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391516&action=review >>> Source/WebCore/dom/Document.cpp:7719 >>> + >> >> Document's destructor needs to iterate over m_documentExplicitIntersectionObserverData and call observer->rootDestroyed() on each one, just like Element's destructor does (see Element::disconnectFromIntersectionObservers()). > > Good catch! I guess this will depend on where the this is stored at the end. Done. >> Source/WebCore/dom/Document.h:1829 >> + // FIXME(fwang): Make this a rare data? > > I guess that's more a question for reviewers than a follow-up task. Basically I see three options: > (1) Keep it as it (increase the size) > (2) Use rare data in Node (maybe move the Element's one too? that might affect the size of other Nodes) > (3) New rare data in Document (that will still increase the size though) For now the patch still uses (1). I noticed that IntersectionObserverRegistration is useless for Document, though. >>> Source/WebCore/page/IntersectionObserver.cpp:145 >>> +Document* IntersectionObserver::trackingDocument() const >> >> I believe the existing implementation (in the ..h) file will already do what's needed, since m_root->document() will return itself when m_root is a Document. > > I think you are correct. I was not sure whether I would have to do some special handling for the Document case, that's why I move it to cpp, but that does not seem necessary. Done. >>> Source/WebCore/page/IntersectionObserver.idl:51 >>> + // FIXME(fwang): Ideally, this should be written '(Element or Document)? = null' but that's not properly supported by WebKit's IDL generator. >> >> Please file a bug for this if you haven't already. > > Yes, I'll take care of that. OK, I was finally able to do the proper C++ changes so that we can use the same IDL as the spec.
Simon Fraser (smfr)
Comment 8 2020-03-03 13:14:04 PST
Comment on attachment 391642 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391642&action=review Let's do a patch without the flag. > Source/JavaScriptCore/ChangeLog:6 > + This patch introduces a new runtime flag I don't think we need a runtime flag. > Source/JavaScriptCore/ChangeLog:13 > + Reviewed by NOBODY (OOPS!). This line goes above the description (prepare-Changelogs does this for you). > Source/WebCore/dom/Document.cpp:7716 > +IntersectionObserverData& Document::ensureDocumentExplicitIntersectionObserverData() Just intersectionObserverData > Source/WebCore/dom/Document.cpp:7723 > +IntersectionObserverData* Document::documentExplicitIntersectionObserverData() intersectionObserverDataIfExists() > Source/WebCore/dom/Document.cpp:7725 > + return m_documentExplicitIntersectionObserverData ? m_documentExplicitIntersectionObserverData.get() : nullptr; Just return m_documentExplicitIntersectionObserverData; > Source/WebCore/dom/Document.h:1830 > + // FIXME(fwang): Make this a rare data? > + std::unique_ptr<IntersectionObserverData> m_documentExplicitIntersectionObserverData; Adding one pointer to Document is fine. The "documentExplicit" name is confusing. Maybe just m_intersectionObserverData? Or m_documentRootIntersectionObserverData
Frédéric Wang (:fredw)
Comment 9 2020-03-03 19:46:30 PST
Comment on attachment 391642 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=391642&action=review >> Source/WebCore/dom/Document.h:1830 >> + std::unique_ptr<IntersectionObserverData> m_documentExplicitIntersectionObserverData; > > Adding one pointer to Document is fine. > > The "documentExplicit" name is confusing. Maybe just m_intersectionObserverData? Or m_documentRootIntersectionObserverData I think the idea is that if you don't specify the { root: ... } option, the root is implicitly the topmost document and in that case the observer data is not needed on that document (as that's the case now).
Frédéric Wang (:fredw)
Comment 10 2020-03-03 23:22:19 PST
Simon Fraser (smfr)
Comment 11 2020-03-04 11:06:45 PST
Comment on attachment 392379 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=392379&action=review > Source/WebCore/dom/Document.cpp:638 > + // Inform observers that this document is destroyed. Comment is not necessary. > Source/WebCore/dom/Document.cpp:640 > + for (const auto& observer : m_intersectionObserverData->observers) > + observer->rootDestroyed(); Observers are weak references, so you need to null-check each one. > Source/WebCore/dom/Document.h:1394 > + IntersectionObserverData& intersectionObserverDataIfExists() { return *m_intersectionObserverData; } This has to return a pointer! You don't have crashing tests, so this indicates that test coverage is insufficient. > Source/WebCore/dom/Document.h:1829 > + std::unique_ptr<IntersectionObserverData> m_intersectionObserverData; You could add a comment saying that this is only non-null when the document is an explicit root.
Frédéric Wang (:fredw)
Comment 12 2020-03-04 12:43:07 PST
Comment on attachment 392379 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=392379&action=review >> Source/WebCore/dom/Document.cpp:640 >> + observer->rootDestroyed(); > > Observers are weak references, so you need to null-check each one. OK, note that this cleanup code as well as the version of intersectionObserverDataIfExists() from the previous patch were copied from what we currently do for Element. So I guess I should fix these as well? >> Source/WebCore/dom/Document.h:1394 >> + IntersectionObserverData& intersectionObserverDataIfExists() { return *m_intersectionObserverData; } > > This has to return a pointer! > > You don't have crashing tests, so this indicates that test coverage is insufficient. OK, I'll change the signature. I feel silly to ask but how do you see that a crash can happen? As I see this function is only called in the destructor of IntersectionObserver when document is an explicit root, and in that case the constructor would have called ensureIntersectionObserverData() for the same document. Currently, the only WPT test with an explicit document root is with only one explicit document root and only one observer. That can definitely be improved to have multiple observer and multiple explicit document roots and different lifetime of objetcs, but I still don't see which configuration would cause a crash in the current patch. >> Source/WebCore/dom/Document.h:1829 >> + std::unique_ptr<IntersectionObserverData> m_intersectionObserverData; > > You could add a comment saying that this is only non-null when the document is an explicit root. Right, will do. That was the purpose of the former "document explicit" name.
Frédéric Wang (:fredw)
Comment 13 2020-03-05 01:09:42 PST
Simon Fraser (smfr)
Comment 14 2020-03-05 15:47:44 PST
Comment on attachment 392546 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=392546&action=review > Source/WebCore/page/IntersectionObserver.cpp:126 > + auto& observerData = downcast<Document>(m_root)->ensureIntersectionObserverData(); Nicer as: downcast<Document>(*m_root).ensureIntersectionObserverData(); since the is<> null-checks. > Source/WebCore/page/IntersectionObserver.cpp:130 > + auto& observerData = downcast<Element>(m_root)->ensureIntersectionObserverData(); Ditto. > Source/WebCore/page/IntersectionObserver.cpp:142 > + downcast<Document>(m_root)->intersectionObserverDataIfExists()->observers.removeFirst(this); Ditto. > Source/WebCore/page/IntersectionObserver.cpp:145 > + downcast<Element>(m_root)->intersectionObserverDataIfExists()->observers.removeFirst(this); Ditto.
Frédéric Wang (:fredw)
Comment 15 2020-03-06 02:54:54 PST
Created attachment 392698 [details] Patch for landing
WebKit Commit Bot
Comment 16 2020-03-06 03:53:14 PST
The commit-queue encountered the following flaky tests while processing attachment 392698 [details]: editing/spelling/spellcheck-async-remove-frame.html bug 158401 (authors: morrita@google.com, rniwa@webkit.org, and tony@chromium.org) The commit-queue is continuing to process your patch.
WebKit Commit Bot
Comment 17 2020-03-06 03:53:53 PST
Comment on attachment 392698 [details] Patch for landing Clearing flags on attachment: 392698 Committed r257976: <https://trac.webkit.org/changeset/257976>
WebKit Commit Bot
Comment 18 2020-03-06 03:53:56 PST
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 19 2020-03-06 03:54:22 PST
Darin Adler
Comment 20 2020-03-06 10:03:22 PST
Comment on attachment 392698 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=392698&action=review > Source/WebCore/page/IntersectionObserver.h:77 > + Node* root() const { return m_root; } How about ContainerNode instead of Node?
Frédéric Wang (:fredw)
Comment 21 2020-03-17 07:31:13 PDT
Created attachment 393752 [details] patch for ews
Frédéric Wang (:fredw)
Comment 22 2020-03-18 00:07:47 PDT
Reopening to attach new patch
Frédéric Wang (:fredw)
Comment 23 2020-03-18 00:09:40 PDT
Created attachment 393823 [details] Patch (address post-landing review comment)
Frédéric Wang (:fredw)
Comment 24 2020-03-18 00:17:07 PDT
Created attachment 393824 [details] Patch (address post-landing review comment)
Frédéric Wang (:fredw)
Comment 25 2020-03-18 00:35:55 PDT
Created attachment 393826 [details] Patch (address post-landing review comment)
Rob Buis
Comment 26 2020-03-18 09:49:29 PDT
Comment on attachment 393826 [details] Patch (address post-landing review comment) LGTM.
Frédéric Wang (:fredw)
Comment 27 2020-03-18 10:01:44 PDT
Created attachment 393873 [details] Patch for landing
WebKit Commit Bot
Comment 28 2020-03-18 10:55:17 PDT
Comment on attachment 393873 [details] Patch for landing Clearing flags on attachment: 393873 Committed r258648: <https://trac.webkit.org/changeset/258648>
WebKit Commit Bot
Comment 29 2020-03-18 10:55:19 PDT
All reviewed patches have been landed. Closing bug.
Darin Adler
Comment 30 2020-03-18 12:09:09 PDT
Comment on attachment 393873 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=393873&action=review > Source/WebCore/page/IntersectionObserver.h:44 > +class ContainerNode; Should move to the top to re-sort at some point.
Simon Fraser (smfr)
Comment 31 2021-04-08 10:55:51 PDT
*** Bug 224324 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.