Commit a4fa1343 authored by Stefan Penner's avatar Stefan Penner

Merge pull request #1 from teddyzeenny/recursive-self-resolution

Fix infinite recursion with deep self fulfilling promises
parents 00d5aaed deeaba9a
This diff is collapsed.
This diff is collapsed.
...@@ -119,7 +119,11 @@ define( ...@@ -119,7 +119,11 @@ define(
fulfill(promise, value); fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) { } else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) { value.then(function(val) {
if (value !== val) {
resolve(promise, val); resolve(promise, val);
} else {
fulfill(promise, val);
}
}, function(val) { }, function(val) {
reject(promise, val); reject(promise, val);
}); });
......
...@@ -115,7 +115,11 @@ function resolve(promise, value) { ...@@ -115,7 +115,11 @@ function resolve(promise, value) {
fulfill(promise, value); fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) { } else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) { value.then(function(val) {
if (value !== val) {
resolve(promise, val); resolve(promise, val);
} else {
fulfill(promise, val);
}
}, function(val) { }, function(val) {
reject(promise, val); reject(promise, val);
}); });
......
...@@ -134,6 +134,27 @@ describe("RSVP extensions", function() { ...@@ -134,6 +134,27 @@ describe("RSVP extensions", function() {
}); });
}); });
it('should assimilate two levels deep, for fulfillment of self fulfilling promises', function(done) {
var originalPromise, promise;
originalPromise = new RSVP.Promise(function(resolve) {
setTimeout(function() {
resolve(originalPromise);
}, 0)
});
promise = new RSVP.Promise(function(resolve) {
setTimeout(function() {
resolve(originalPromise);
}, 0);
});
promise.then(function(value) {
assert.equal(value, originalPromise);
done();
});
});
it('should assimilate two levels deep, for fulfillment', function(done) { it('should assimilate two levels deep, for fulfillment', function(done) {
var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); }); var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); });
var nextPromise = new RSVP.Promise(function(resolve) { resolve(originalPromise); }); var nextPromise = new RSVP.Promise(function(resolve) { resolve(originalPromise); });
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment