Commit c9233289 authored by Teddy Zeenny's avatar Teddy Zeenny

Reject promise if resolver function throws an exception

parent 40b8bf24
...@@ -41,7 +41,11 @@ var Promise = function(resolver) { ...@@ -41,7 +41,11 @@ var Promise = function(resolver) {
this.trigger('error', { detail: event.detail }); this.trigger('error', { detail: event.detail });
}, this); }, this);
try {
resolver(resolvePromise, rejectPromise); resolver(resolvePromise, rejectPromise);
} catch(e) {
rejectPromise(e);
}
}; };
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
......
...@@ -81,6 +81,15 @@ describe("RSVP extensions", function() { ...@@ -81,6 +81,15 @@ describe("RSVP extensions", function() {
}, TypeError); }, TypeError);
}); });
it('should reject on resolver exception', function(done) {
var promise = RSVP.Promise(function() {
throw 'error';
}).then(null, function(e) {
assert.equal(e, 'error');
done();
});
});
describe('assimilation', function() { describe('assimilation', function() {
it('should assimilate if `resolve` is called with a fulfilled promise', function(done) { it('should assimilate if `resolve` is called with a fulfilled promise', function(done) {
var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); }); var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); });
......
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