<?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>27874</bug_id>
          
          <creation_ts>2015-01-21 12:27:35 +0000</creation_ts>
          <short_desc>Microtasks and callbacks run from a queued task</short_desc>
          <delta_ts>2016-06-02 20:50:02 +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>WebIDL</component>
          <version>unspecified</version>
          <rep_platform>PC</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="Anne">annevk</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>adamk</cc>
    
    <cc>bugs</cc>
    
    <cc>d</cc>
    
    <cc>jsbell</cc>
    
    <cc>mike</cc>
    
    <cc>public-script-coord</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>117384</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-01-21 12:27:35 +0000</bug_when>
    <thetext>There&apos;s a problem with how we are defining microtasks and callbacks run from a queued task.

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3379

&lt;!DOCTYPE html&gt;
.&lt;script&gt;
 new MutationObserver(function() { w(2) }).observe(document.body, {attributes:true})
 document.body.addEventListener(&quot;mousemove&quot;, function() {
   w(1)
   document.body.setAttribute(&quot;test&quot;, &quot;x&quot;)
 })
 document.body.addEventListener(&quot;mousemove&quot;, function() {
   w(3)
 })
 document.body.dispatchEvent(new Event(&quot;mousemove&quot;))
&lt;/script&gt;

The dispatchEvent() method does not queue a task and therefore the order is 1, 3, 2. However, if you move the mouse around in the document the order is 1, 2, 3.

We are not capturing this at all.

Ian suggested IDL needs to invoke HTML&apos;s &quot;clean up after running a callback&quot; from IDL&apos;s &quot;Invoking callback functions&quot; section. However, that will not do the right thing as that would make the order 1, 2, 3 either way.

Related bugs:

* bug 18242
* bug 24403
* bug 25138</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117385</commentid>
    <comment_count>1</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2015-01-21 12:34:04 +0000</bug_when>
    <thetext>And the problem is?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117388</commentid>
    <comment_count>2</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2015-01-21 12:43:03 +0000</bug_when>
    <thetext>I would add some hook to webidl spec, which then
HTML spec used to explain when to run end-of-microtask callbacks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117395</commentid>
    <comment_count>3</comment_count>
    <who name="Adam Klein">adamk</who>
    <bug_when>2015-01-21 16:47:03 +0000</bug_when>
    <thetext>(In reply to Anne from comment #0)
&gt; Ian suggested IDL needs to invoke HTML&apos;s &quot;clean up after running a callback&quot;
&gt; from IDL&apos;s &quot;Invoking callback functions&quot; section. However, that will not do
&gt; the right thing as that would make the order 1, 2, 3 either way.

Ian&apos;s suggestion seems fine to me. The language of the &quot;clean up&quot; stuff that runs microtasks is:

&quot;3. If the stack of script settings objects is now empty, perform a microtask checkpoint.&quot;

It&apos;s the first part of that clause which causes the two different orderings.

I don&apos;t think there&apos;s any new bug here, just the same old one that WebIDL needs to be invoking callbacks via HTML spec methods.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126663</commentid>
    <comment_count>4</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2016-06-02 20:50:02 +0000</bug_when>
    <thetext>This was fixed in https://github.com/heycam/webidl/pull/113; Web IDL now calls HTML&apos;s prepare/cleanup steps for running script in its four callback-invoking algorithms.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>