<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>16392</bug_id>
          
          <creation_ts>2012-03-15 22:03:38 +0000</creation_ts>
          <short_desc>MutationObserver invocation order should be fixed at the beginning of each loop</short_desc>
          <delta_ts>2012-03-20 10:50:43 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adam Klein">adamk</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bugs</cc>
    
    <cc>mike</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>65632</commentid>
    <comment_count>0</comment_count>
    <who name="Adam Klein">adamk</who>
    <bug_when>2012-03-15 22:03:38 +0000</bug_when>
    <thetext>From www-dom:

http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-mo-invokedescribes
an algorithm for delivering MutationRecords to MutationObservers.
In particular, it describes an order of delivery, and I wonder if tweaking
it a little bit would make it simpler to implement. Note that I don&apos;t think
the particular order is of much importance: it&apos;s just important that there
is a well-defined order.  In particular, there are two cases I&apos;m worried
about:

1. Assume observers A, B, and C (created in the order A, B, C). Say that at
the beginning of the algorithm, only A and C have non-empty queues. But
during A&apos;s callback, it mutates DOM that causes a record to be added to B&apos;s
queue.

2. Assume an observer A with a non-empty queue. During its callback, it
creates a new observer B, starts B observing, and mutates DOM that adds a
record to both A&apos;s and B&apos;s queue.

By the spec, case (1) would result in the delivery order A-B-C. And (2)
would be A-B-A.

In the WebKit implementation, though, only the &quot;active&quot; observers (those
with records in their queues) are kept in a list (this makes it fast in the
common case that there&apos;s no delivery necessary). This makes our algorithm
more like this:

I. Make a copy of the existing &quot;active&quot; list, clear the list, and then
iterate over the copy.
II. When that iteration is complete, the active list is checked again; if
it&apos;s non-empty, go back to step I.

When applied to the cases above, (1) results in the order A-C-B (B doesn&apos;t
get notified until the next time around the loop), and (2) results in A-A-B
(again, the newly-added observer doesn&apos;t get notified until the second time
through the loop).
...

I&apos;ve implemented the aforementioned algorithm in WebKit. Per the thread, http://lists.w3.org/Archives/Public/www-dom/2012JanMar/0145.html, it sounds like Olli is fine with that algorithm too (CCing him just in case)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65811</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-03-20 10:50:43 +0000</bug_when>
    <thetext>https://bitbucket.org/ms2ger/dom-core/changeset/1c5fe3fae8b4</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>