· 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.



