· javascript

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

Here is a program that, until July, never finished in Bun or Safari. const p = Promise.resolve(1); p.constructor = { get [Symbol.species]() { throw new Error("boom"); }, }; console.log("before"); await p; console.log("done");Don't worry if this looks confusing.


The JavaScript spec says that because the getter throws an error, then await p should also throw, and so the program should crash. It is neither fulfilled nor rejected, so it stays pending forever. I fixed it in WebKit/WebKit#68749, and the fix was only +16 lines!

Let's quickly brush up on promises. A simple userland implementation would look like this: function PromiseDotResolve(value) { if (value instanceof Promise && value.constructor === Promise) { return value; } return new Promise(resolve => resolve(value)); }The same is also true for literally writing await 42.

Related coverage

Also worth reading

  1. next.js 16.5.0-canary.50 released
  2. Node.js Brings Debounce, Throttle, and PKCS#12 Parsing Into Core Modules
  3. You could have invented transformers from memory
  4. Daemons can now send traces to Vercel Tracing
  5. FBI flash alert says Artex tool automating cyberattacks at ‘machine speed’