Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] finally kill self-fulfillment #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/rsvp/-internal.js
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
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