NewsCrawler.org

Fixing a WebKit bug to see if promises are made of train tracks

The author describes a short program that, until July, never finished in Bun or Safari 26. Node.js finishes it, as the JavaScript spec requires. The program defines a species getter on a promise's constructor that throws an error, so the spec says await should throw too. Instead, Bun 1.3.14 and Safari 26 printed 'before', reported the error, and hung, because the promise stayed pending[1] forever: it was neither fulfilled nor rejected.

The cause was WebKit bug 318399. The author fixed it in WebKit/WebKit#68749, and the fix was 16 lines. Bun and Safari both embed JavaScriptCore, so they behave the same way.

The article then explains how resolve works. If a value has a .then() method, it is treated as a thenable[2], and resolve reads .then, which can run a getter that throws. A failure can be passed to reject at once, but a successful value may arrive later, so the extra check happens only in resolve. The author also notes that "resolved" is not a real promise state, because a resolved promise can still be pending.

Read the original alistair.shDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page