Bug 160857 - Promise API does not fully process microtask checkpoint: spec violation
Summary: Promise API does not fully process microtask checkpoint: spec violation
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-15 12:19 PDT by Aleksandar Totic
Modified: 2016-08-24 17:20 PDT (History)
4 users (show)

See Also:


Attachments
This file will demonstrate the bug (3.13 KB, text/html)
2016-08-15 12:19 PDT, Aleksandar Totic
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksandar Totic 2016-08-15 12:19:08 PDT
Created attachment 286076 [details]
This file will demonstrate the bug

Promises microtask queue does not fully process microtasks queued while microtask is running.
According to spec, microtask queue should loop until it is empty.

Why is this bug important?
Promises are often used by developers for scheduling. When they are,
developers assume Promise.resolve() means "execute this function right 
after this script returns". This bug violates this promise.

FF/Edge/Chrome get this right. It'd be great if all browsers worked the same.

Example:

Promise.resolved()
 .then(() => {
   console.log("Promise 1");
   return Promise.resolve();
 })
 .then(() => {
   console.log("Promise 2");
 }
window.setTimeout(function() {
  console.log('timeout');
}, 0);

Might also be related to Bug #140043. I've attached a test case.
Comment 1 Aleksandar Totic 2016-08-16 13:47:01 PDT
Noticed that my example was not clear. The example should print: 
Promise 1
Promise 2
timeout

In Safari, it prints
Promise 1
timeout
Promise 2