Bug 198643 - async function resolution order
Summary: async function resolution order
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 12
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-06-06 21:29 PDT by John Plaisted
Modified: 2023-10-11 17:03 PDT (History)
6 users (show)

See Also:


Attachments
Test demonstrating differences in async / promise behavior (3.69 KB, text/html)
2019-06-06 21:29 PDT, John Plaisted
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Plaisted 2019-06-06 21:29:07 PDT
Created attachment 371556 [details]
Test demonstrating differences in async / promise behavior

Steps to reproduce:

The await keyword has a different resolution order than Promises, which seems incorrect (and fwiw Chrome's await matches promises; FireFox appears to share Safari's behavior).

I think I've found two different cases where the order is different from promises:

In some cases the await order determines when functions continue (rather than the resolve() order, assuming things resolve synchronously)
In some other cases it seems to be the opposite of the resolve AND await order when the are the same order. Maybe it is because one is an await <literal> and the other is an await promise?

Actual results:

The order of asynchronous code with an async function doesn't match the equivalent promise code.

When running the file:

async test fails
promise test passes
order of await determines order of async callbacks
order resolve() determines order of promise callbacks


Expected results:

The async function order matches the Promise equivalent.

When running the file:

async test passes
promise test passes
order of resolve() determines order of async callbacks
order resolve() determines order of promise callbacks
Comment 1 John Plaisted 2019-06-07 08:12:14 PDT
I did file a webkit bug as well:

https://bugs.webkit.org/show_bug.cgi?id=198643
Comment 2 John Plaisted 2019-06-07 08:12:45 PDT
Err, I filed a *FireFox* bug as well :)

https://bugzilla.mozilla.org/show_bug.cgi?id=1557611
Comment 3 Radar WebKit Bug Importer 2023-08-14 18:32:37 PDT
<rdar://problem/113883375>
Comment 4 Alexey Shvayka 2023-10-11 17:03:24 PDT
Hey John, thanks for filing the bugs and providing super well-written test case!

Per https://bugzilla.mozilla.org/show_bug.cgi?id=1557611#c7, the difference that was observed in 2019 was due to not all browsers (yet) implementing the spec change: https://github.com/tc39/ecma262/pull/1250.

All browsers, including Safari 16.1, are passing the tests.