stefanpenner/rsvp.js — pull request #1 by teddyzeenny (2013-04-19 22:30:18+00:00)
Title: Fix infinite recursion with deep self fulfilling promises

The following code in the `resolve` method:

```javascript

else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) {
resolve(promise, val); // <=====
}, function(val) {
reject(promise, val);
});
}
```

assumes that `val` is never equal to `value` (i.e the promise never resolves to itself). But after the latest update, promises now might resolve to themselves which means `val` might equal to `value`, which means `resolve(promise, value) === resolve(promise, val)` which causes the infinite recursion.

It was failing when a promise A resolves to a self fulfilling promise B.

```javascript

var promise, selfFulfillingPromise;

selfFulfillingPromise = new Promise( function(resolve) {
setTimeout(function() {
resolve(selfFulfillingPromise);
});
});

promise = new Promise(function(resolve) {
resolve(selfFulfillingPromise);
});

```

This solution is still Promises/A+-compliant compatible (passes all the tests).