This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27874 - Microtasks and callbacks run from a queued task
Summary: Microtasks and callbacks run from a queued task
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-21 12:27 UTC by Anne
Modified: 2016-06-02 20:50 UTC (History)
6 users (show)

See Also:


Attachments

Description Anne 2015-01-21 12:27:35 UTC
There'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

<!DOCTYPE html>
.<script>
 new MutationObserver(function() { w(2) }).observe(document.body, {attributes:true})
 document.body.addEventListener("mousemove", function() {
   w(1)
   document.body.setAttribute("test", "x")
 })
 document.body.addEventListener("mousemove", function() {
   w(3)
 })
 document.body.dispatchEvent(new Event("mousemove"))
</script>

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's "clean up after running a callback" from IDL's "Invoking callback functions" 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
Comment 1 Olli Pettay 2015-01-21 12:34:04 UTC
And the problem is?
Comment 2 Olli Pettay 2015-01-21 12:43:03 UTC
I would add some hook to webidl spec, which then
HTML spec used to explain when to run end-of-microtask callbacks.
Comment 3 Adam Klein 2015-01-21 16:47:03 UTC
(In reply to Anne from comment #0)
> Ian suggested IDL needs to invoke HTML's "clean up after running a callback"
> from IDL's "Invoking callback functions" section. However, that will not do
> the right thing as that would make the order 1, 2, 3 either way.

Ian's suggestion seems fine to me. The language of the "clean up" stuff that runs microtasks is:

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

It's the first part of that clause which causes the two different orderings.

I don't think there's any new bug here, just the same old one that WebIDL needs to be invoking callbacks via HTML spec methods.
Comment 4 Domenic Denicola 2016-06-02 20:50:02 UTC
This was fixed in https://github.com/heycam/webidl/pull/113; Web IDL now calls HTML's prepare/cleanup steps for running script in its four callback-invoking algorithms.