From 2c4f1e2e3c7fef2b0097c957c5707eee96e05ffe Mon Sep 17 00:00:00 2001 From: xiaodongyang Date: Mon, 13 Jul 2015 17:53:48 +0800 Subject: [PATCH] fix misbehavior uncaught by the aplus-spec tests see https://github.com/promises-aplus/promises-tests/issues/59 --- index.js | 11 ----------- package.json | 2 +- promise.min.js | 2 +- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 6c9dd6e..a690f54 100644 --- a/index.js +++ b/index.js @@ -81,17 +81,6 @@ Handler.prototype = { , reject: function (x, unlock) { if (this.state > 1 && unlock !== 1) return - var then - try { - then = getThen(x) - } catch (e) { - this.reject(e) - return - } - if (then) { - this.follow(x, then) - return - } this.state = 3 this.reason = x next(this.errbacks, x) diff --git a/package.json b/package.json index a98493e..a1db9b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "in-promise", - "version": "0.1.0", + "version": "0.2.0", "description": "A minimal Promise/A+ implementation for browsers", "main": "index.js", "scripts": { diff --git a/promise.min.js b/promise.min.js index 3561139..8e05189 100644 --- a/promise.min.js +++ b/promise.min.js @@ -1 +1 @@ -!function(t){"use strict";function e(t){if(!(this instanceof e))throw new TypeError("Promise is intended to be called as a constructor");if("function"!=typeof t)throw new TypeError("Promise resolver "+t+" is not a function");var n=this,i=n._handler=new r;try{t(function(t){i.resolve(t)},function(t){i.reject(t)})}catch(t){i.reject(t)}}function r(){this.state=0,this.callbacks=[],this.errbacks=[],this.result=void 0,this.reason=void 0}function n(t,e,r,n){return function(i){var o;try{o=n.call(void 0,i)}catch(t){return void r(t)}return o===t?void r(new TypeError("Cannot resolve a promise with itself")):void e(o)}}function i(t,e){o(t)&&(t=[t]),t.forEach(function(t){setTimeout(function(){t.call(void 0,e)})})}function o(t){return"function"==typeof t}function s(t){if(!t||"object"!=typeof t&&"function"!=typeof t)return!1;var e=t.then;return o(e)&&e}e.prototype.then=function(t,r){var i,s,c=new e(function(t,e){i=t,s=e});return this._handler.then(o(t)?n(c,i,s,t):i,o(r)?n(c,i,s,r):s),c},r.prototype={constructor:r,then:function(t,e){this.callbacks.push(t),this.errbacks.push(e),2===this.state&&i(t,this.result),3===this.state&&i(e,this.reason)},resolve:function(t,e){if(!(this.state>1&&1!==e)){var r;try{r=s(t)}catch(t){return void this.reject(t)}if(r)return void this.follow(t,r);this.state=2,this.result=t,i(this.callbacks,t)}},reject:function(t,e){if(!(this.state>1&&1!==e)){var r;try{r=s(t)}catch(t){return void this.reject(t)}if(r)return void this.follow(t,r);this.state=3,this.reason=t,i(this.errbacks,t)}},follow:function(t,e){var r=this;r.state=1;var n=0;try{e.call(t,function(t){r.resolve(t,++n)},function(t){r.reject(t,++n)})}catch(t){r.reject(t,++n)}}},"undefined"!=typeof module?module.exports=e:t.Promise=e}(this); \ No newline at end of file +!function(t){"use strict";function e(t){if(!(this instanceof e))throw new TypeError("Promise is intended to be called as a constructor");if("function"!=typeof t)throw new TypeError("Promise resolver "+t+" is not a function");var r=this,i=r._handler=new n;try{t(function(t){i.resolve(t)},function(t){i.reject(t)})}catch(t){i.reject(t)}}function n(){this.state=0,this.callbacks=[],this.errbacks=[],this.result=void 0,this.reason=void 0}function r(t,e,n,r){return function(i){var o;try{o=r.call(void 0,i)}catch(t){return void n(t)}return o===t?void n(new TypeError("Cannot resolve a promise with itself")):void e(o)}}function i(t,e){o(t)&&(t=[t]),t.forEach(function(t){setTimeout(function(){t.call(void 0,e)})})}function o(t){return"function"==typeof t}function s(t){if(!t||"object"!=typeof t&&"function"!=typeof t)return!1;var e=t.then;return o(e)&&e}e.prototype.then=function(t,n){var i,s,c=new e(function(t,e){i=t,s=e});return this._handler.then(o(t)?r(c,i,s,t):i,o(n)?r(c,i,s,n):s),c},n.prototype={constructor:n,then:function(t,e){this.callbacks.push(t),this.errbacks.push(e),2===this.state&&i(t,this.result),3===this.state&&i(e,this.reason)},resolve:function(t,e){if(!(this.state>1&&1!==e)){var n;try{n=s(t)}catch(t){return void this.reject(t)}if(n)return void this.follow(t,n);this.state=2,this.result=t,i(this.callbacks,t)}},reject:function(t,e){this.state>1&&1!==e||(this.state=3,this.reason=t,i(this.errbacks,t))},follow:function(t,e){var n=this;n.state=1;var r=0;try{e.call(t,function(t){n.resolve(t,++r)},function(t){n.reject(t,++r)})}catch(t){n.reject(t,++r)}}},"undefined"!=typeof module?module.exports=e:t.Promise=e}(this); \ No newline at end of file