diff --git a/src/node.js b/src/node.js index 8cbb7312c8..2ac3b54ca4 100644 --- a/src/node.js +++ b/src/node.js @@ -233,7 +233,7 @@ var eventsModule = createInternalModule('events', function (exports) { exports.Promise.prototype.emitSuccess = function() { if (this.hasFired) return; - this.hasFired = true; + this.hasFired = 'success'; this._clearTimeout(); this._values = Array.prototype.slice.call(arguments); @@ -242,7 +242,7 @@ var eventsModule = createInternalModule('events', function (exports) { exports.Promise.prototype.emitError = function() { if (this.hasFired) return; - this.hasFired = true; + this.hasFired = 'error'; this._clearTimeout(); this._values = Array.prototype.slice.call(arguments); @@ -261,7 +261,7 @@ var eventsModule = createInternalModule('events', function (exports) { }; exports.Promise.prototype.addCallback = function (listener) { - if (this.hasFired) { + if (this.hasFired === 'success') { return listener.apply(this, this._values); } @@ -269,7 +269,7 @@ var eventsModule = createInternalModule('events', function (exports) { }; exports.Promise.prototype.addErrback = function (listener) { - if (this.hasFired) { + if (this.hasFired === 'error') { listener.apply(this, this._values); } diff --git a/test/mjsunit/test-promise.js b/test/mjsunit/test-promise.js index 9b314ea56e..2992f93665 100644 --- a/test/mjsunit/test-promise.js +++ b/test/mjsunit/test-promise.js @@ -19,12 +19,18 @@ a.addCallback(function(value) { assert.equal(TEST_VALUE, value); expectedCallbacks.a1--; }); +a.addErrback(function(error) { + assert.notEqual(TEST_VALUE, error, 'normal'); +}); a.emitSuccess(TEST_VALUE); a.addCallback(function(value) { assert.equal(TEST_VALUE, value); expectedCallbacks.a2--; }); +a.addErrback(function(error) { + assert.notEqual(TEST_VALUE, error, 'late'); +}); // Test regular & late errback binding var b = new Promise();