Commit 73d624d1 authored by Stefan Penner's avatar Stefan Penner

Merge pull request #70 from stefanpenner/master

correctly test and fix self fulfillment
parents 05e09ef3 66aac64b
...@@ -479,7 +479,10 @@ define("rsvp/promise", ...@@ -479,7 +479,10 @@ define("rsvp/promise",
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
function resolve(promise, value) { function resolve(promise, value) {
if (objectOrFunction(value) && isFunction(value.then)) {
if (promise === value) {
fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) { value.then(function(val) {
if (value !== val) { if (value !== val) {
resolve(promise, val); resolve(promise, val);
......
This diff is collapsed.
...@@ -115,7 +115,10 @@ define( ...@@ -115,7 +115,10 @@ define(
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
function resolve(promise, value) { function resolve(promise, value) {
if (objectOrFunction(value) && isFunction(value.then)) {
if (promise === value) {
fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) { value.then(function(val) {
if (value !== val) { if (value !== val) {
resolve(promise, val); resolve(promise, val);
......
...@@ -111,7 +111,10 @@ Promise.prototype = { ...@@ -111,7 +111,10 @@ Promise.prototype = {
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
function resolve(promise, value) { function resolve(promise, value) {
if (objectOrFunction(value) && isFunction(value.then)) {
if (promise === value) {
fulfill(promise, value);
} else if (objectOrFunction(value) && isFunction(value.then)) {
value.then(function(val) { value.then(function(val) {
if (value !== val) { if (value !== val) {
resolve(promise, val); resolve(promise, val);
......
...@@ -3,21 +3,25 @@ describe("RSVP extensions", function() { ...@@ -3,21 +3,25 @@ describe("RSVP extensions", function() {
describe("self fulfillment", function(){ describe("self fulfillment", function(){
it("treats self fulfillment as the recursive base case", function(done){ it("treats self fulfillment as the recursive base case", function(done){
var aDefer = new RSVP.defer(), var aDefer = new RSVP.defer(),
bDefer = new RSVP.defer(); bDefer = new RSVP.defer(),
promiseA = aDefer.promise,
promiseB = bDefer.promise;
aDefer.promise.then(function(a){ promiseA.then(function(a){
setTimeout(function(){ setTimeout(function(){
bDefer.resolve(bDefer.promise); bDefer.resolve(promiseB);
}, 1); }, 1);
return bDefer.promise; return promiseB;
}); });
bDefer.promise.then(function(c){ promiseB.then(function(c){
done(); done();
}) })
aDefer.resolve(aDefer.promise); aDefer.resolve(promiseA);
});
});
}); });
}); });
......
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