Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/rsvp/-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function withOwnPromise() {
return new TypeError('A promises callback cannot return that same promise.');
}

function cycleDetected() {
return new TypeError('Chaining cycle detected for promise');
}

function noop() {}

var PENDING = void 0;
Expand Down Expand Up @@ -43,11 +47,7 @@ function handleForeignThenable(promise, thenable, then) {
var error = tryThen(then, thenable, function(value) {
if (sealed) { return; }
sealed = true;
if (thenable !== value) {
resolve(promise, value, undefined);
} else {
fulfill(promise, value);
}
resolve(promise, value);
}, function(reason) {
if (sealed) { return; }
sealed = true;
Expand All @@ -70,11 +70,7 @@ function handleOwnThenable(promise, thenable) {
reject(promise, thenable._result);
} else {
subscribe(thenable, undefined, function(value) {
if (thenable !== value) {
resolve(promise, value, undefined);
} else {
fulfill(promise, value);
}
resolve(promise, value);
}, function(reason) {
reject(promise, reason);
});
Expand All @@ -101,7 +97,7 @@ function handleMaybeThenable(promise, maybeThenable, then) {

function resolve(promise, value) {
if (promise === value) {
fulfill(promise, value);
reject(promise, cycleDetected());
} else if (objectOrFunction(value)) {
handleMaybeThenable(promise, value, getThen(value));
} else {
Expand Down
13 changes: 9 additions & 4 deletions test/extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ describe("RSVP extensions", function() {
}, 1);

return promiseB;
}).catch(function(c) {
assert.equal(c.message, 'Chaining cycle detected for promise');
done();
});

promiseB.then(function(c){
done();
})
promiseB.catch(done);

aDefer.resolve(promiseA);
});
Expand Down Expand Up @@ -342,7 +343,11 @@ describe("RSVP extensions", function() {
});

promise.then(function(value) {
assert.equal(value, originalPromise);
done("should not be fullfilled");
});

promise.catch(function(reason) {
assert.equal(reason.message, 'Chaining cycle detected for promise');
done();
});
});
Expand Down