domenic/promises-unwrapping — pull request #31 by domenic (2013-09-19 06:51:16+00:00)
Title: Make subclassing work automatically

This is not final in any way, and as mentioned previously this is not urgent since `@@create` is the only way to make this relevant, but I wanted to get it out there.

Drawing heavily on Allen's work on `Array` and so on, this series of commits uses a series of techniques to make `Promise` subclasses Just Work(TM). The static methods will all return instances of the new type, and in fact will in most cases execute any special behavior for when you do something like:

```js
class InstrumentedPromise extends Promise {
constructor(resolver) {
super((resolve, reject) => {
resolver(
x => {
console.log("resolve called");
resolve(x);
},
r => {
console.log("reject called");
reject(r);
}
);
});
}
}
```

(stare at this example for long enough and I'm pretty sure it will make sense.)

`Promise.cast` is a bit special since we want to ensure it always gives you back whatever type you call it on (e.g. `InstrumentedPromise.cast(x)` always gives you an `InstrumentedPromise`). The technique used there is a bit tricky and could be strengthened; I'm not a huge fan of it right now but we'll see.