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 24725 - Use the microtask queue for MutationObserver
Summary: Use the microtask queue for MutationObserver
Status: RESOLVED DUPLICATE of bug 24810
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-19 07:24 UTC by Philip Jägenstedt
Modified: 2014-03-18 09:17 UTC (History)
3 users (show)

See Also:


Attachments

Description Philip Jägenstedt 2014-02-19 07:24:31 UTC
http://www.whatwg.org/specs/web-apps/current-work/#perform-a-microtask-checkpoint

There's a note there that says "This will be removed once mutation observers have been updated to use the microtask queue."

Make it so!

The reason I want this is that if one is able to queue two MutationObserver microtasks before and after another microtask that doesn't run scripts, it would be possible to test with precision that the microtask in the middle runs exactly when it should and does what it should. (For this to work, each MutationObserver must queue a microtask separately, they can't be batched as they currently are.)
Comment 1 Rafael Weinstein 2014-02-19 11:19:29 UTC
Mutation Observers won't behave the way you are wanting because they require a delivery order which isn't based on the time of the mutation (it's based on the time the mutation observers are created).

However, ES Promises will work the way you want.

Once https://codereview.chromium.org/167683003/ lands, ES microtask work will be scheduled correctly relative to DOM microtask work and you'll be able to verify this with tests.
Comment 2 Philip Jägenstedt 2014-02-19 15:13:08 UTC
(In reply to Rafael Weinstein from comment #1)
> Mutation Observers won't behave the way you are wanting because they require
> a delivery order which isn't based on the time of the mutation (it's based
> on the time the mutation observers are created).

That sounds like it would work as well, as long as invoking the callbacks isn't batched together in a single microtask.

> However, ES Promises will work the way you want.
> 
> Once https://codereview.chromium.org/167683003/ lands, ES microtask work
> will be scheduled correctly relative to DOM microtask work and you'll be
> able to verify this with tests.

Cool, what kind of code would one write to have a callback run in a microtask? (Searched for "promises microtask" without finding anything concrete.)
Comment 4 Anne 2014-03-18 09:17:33 UTC
Ian provided more detail on what to do.

*** This bug has been marked as a duplicate of bug 24810 ***