RESOLVED FIXED 70436
[MutationObservers] Implement basic subtree observation
https://bugs.webkit.org/show_bug.cgi?id=70436
Summary [MutationObservers] Implement basic subtree observation
Adam Klein
Reported 2011-10-19 13:38:07 PDT
[MutationObservers] Implement basic subtree observation
Attachments
Patch (13.46 KB, patch)
2011-10-19 13:45 PDT, Adam Klein
no flags
Extracted helper function (11.33 KB, patch)
2011-10-20 15:32 PDT, Adam Klein
no flags
Merged to r98133 (11.28 KB, patch)
2011-10-21 13:24 PDT, Adam Klein
no flags
Patch for landing (11.59 KB, patch)
2011-10-21 15:36 PDT, Adam Klein
no flags
Adam Klein
Comment 1 2011-10-19 13:45:55 PDT
Rafael Weinstein
Comment 2 2011-10-20 14:19:52 PDT
Comment on attachment 111668 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=111668&action=review > Source/WebCore/dom/Node.cpp:2695 > + const size_t size = observerEntries->size(); maybe extract a static utility function here?
Adam Klein
Comment 3 2011-10-20 14:33:18 PDT
Comment on attachment 111668 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=111668&action=review >> Source/WebCore/dom/Node.cpp:2695 >> + const size_t size = observerEntries->size(); > > maybe extract a static utility function here? That's how I started, but it the inner if-statement differs depending on whether we're looking at the node itself or one of its ancestors. This means that either we do extra checking inside the loop (bad for performance), or we extract the test out into a functor (bad for readability, imho). That's why I ended up "unrolling" the code manually. Let me know if you'd prefer the functor approach (I really don't want to do any more work in the inner loop than I have to).
Ryosuke Niwa
Comment 4 2011-10-20 15:18:37 PDT
Comment on attachment 111668 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=111668&action=review >>> Source/WebCore/dom/Node.cpp:2695 >> >> maybe extract a static utility function here? > > That's how I started, but it the inner if-statement differs depending on whether we're looking at the node itself or one of its ancestors. This means that either we do extra checking inside the loop (bad for performance), or we extract the test out into a functor (bad for readability, imho). That's why I ended up "unrolling" the code manually. Let me know if you'd prefer the functor approach (I really don't want to do any more work in the inner loop than I have to). I think we should keep matches to take MutationObserverOptions and do: if (Vector<MutationObserverEntry>* observerEntries = mutationObserverEntries()) addMatchedObserverEntriesToSet(observerSet, *observerEntries, type); for (Node* node = parentNode(); node; node = node->parentNode()) { if (Vector<MutationObserverEntry>* observerEntries = node->mutationObserverEntries()) addMatchedObserverEntriesToSet(observerSet, *observerEntries, type | WebKitMutationObserver::Subtree); }
Adam Klein
Comment 5 2011-10-20 15:32:42 PDT
Created attachment 111856 [details] Extracted helper function
Adam Klein
Comment 6 2011-10-20 15:33:23 PDT
Comment on attachment 111668 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=111668&action=review >>>> Source/WebCore/dom/Node.cpp:2695 >>>> + const size_t size = observerEntries->size(); >>> >>> maybe extract a static utility function here? >> >> That's how I started, but it the inner if-statement differs depending on whether we're looking at the node itself or one of its ancestors. This means that either we do extra checking inside the loop (bad for performance), or we extract the test out into a functor (bad for readability, imho). That's why I ended up "unrolling" the code manually. Let me know if you'd prefer the functor approach (I really don't want to do any more work in the inner loop than I have to). > > After talking to Rafael offline, came up with a fix (just make matches() stricter). I've now extracted the loop into its own function.
Adam Klein
Comment 7 2011-10-21 13:24:37 PDT
Ryosuke Niwa
Comment 8 2011-10-21 15:22:34 PDT
Comment on attachment 112009 [details] Merged to r98133 View in context: https://bugs.webkit.org/attachment.cgi?id=112009&action=review r=me provided problems listed below are all addressed. > Source/WebCore/ChangeLog:9 > + Note that this patch only implements "basic" subtree > + semantics, not the fully robust semantics described in Nit: semantics should probably on the previous line to avoid awkward line break. > Source/WebCore/ChangeLog:22 > + (WebCore::addMatchingObservers): Static helper method for the below. I'm not sure what you're referring to by "the below". Could you spell out the function name here? > Source/WebCore/dom/Node.cpp:2703 > + if (observerEntries) { We prefer early exiting over nesting ifs especially when the if statement appears at the beginning of a function and the normal flow is to do whatever inside the if. > LayoutTests/fast/mutation/observe-subtree.html:32 > + observer = new WebKitMutationObserver(function(m) { > + mutations = m; Nit: please avoid using one-letter variable. > LayoutTests/fast/mutation/observe-subtree.html:75 > + observer = new WebKitMutationObserver(function(m) { > + mutations = m; > + }); > + observer2 = new WebKitMutationObserver(function(m) { > + mutations2 = m; > + }); Ditto about one-letter variables. > LayoutTests/fast/mutation/observe-subtree.html:116 > + observer = new WebKitMutationObserver(function(m) { > + mutations = m; > + ++calls; > + }); Ditto.
Adam Klein
Comment 9 2011-10-21 15:36:15 PDT
Comment on attachment 112009 [details] Merged to r98133 View in context: https://bugs.webkit.org/attachment.cgi?id=112009&action=review >> Source/WebCore/ChangeLog:9 >> + semantics, not the fully robust semantics described in > > Nit: semantics should probably on the previous line to avoid awkward line break. Done. >> Source/WebCore/ChangeLog:22 >> + (WebCore::addMatchingObservers): Static helper method for the below. > > I'm not sure what you're referring to by "the below". Could you spell out the function name here? Done. >> Source/WebCore/dom/Node.cpp:2703 >> + if (observerEntries) { > > We prefer early exiting over nesting ifs especially when the if statement appears at the beginning of a function and the normal flow is to do whatever inside the if. Done. >> LayoutTests/fast/mutation/observe-subtree.html:32 >> + mutations = m; > > Nit: please avoid using one-letter variable. Done. >> LayoutTests/fast/mutation/observe-subtree.html:75 >> + }); > > Ditto about one-letter variables. Done. >> LayoutTests/fast/mutation/observe-subtree.html:116 >> + }); > > Ditto. Done.
Adam Klein
Comment 10 2011-10-21 15:36:47 PDT
Created attachment 112033 [details] Patch for landing
WebKit Review Bot
Comment 11 2011-10-21 15:51:39 PDT
Comment on attachment 112033 [details] Patch for landing Clearing flags on attachment: 112033 Committed r98163: <http://trac.webkit.org/changeset/98163>
WebKit Review Bot
Comment 12 2011-10-21 15:51:44 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.