promise-polyfill
Advanced tools
Comparing version 5.0.0 to 5.1.0
{ | ||
"name": "promise-polyfill", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Lightweight promise polyfill. A+ compliant", | ||
@@ -5,0 +5,0 @@ "main": "promise.js", |
@@ -98,3 +98,3 @@ (function (root) { | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
setTimeout(function() { | ||
asap(function() { | ||
if (!self._handled) { | ||
@@ -101,0 +101,0 @@ onUnhandledRejection(self._value); |
@@ -1,1 +0,1 @@ | ||
!function(e){function t(){}function n(e,t){return function(){e.apply(t,arguments)}}function o(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(e,this)}function i(e,t){for(;3===e._state;)e=e._value;return 0===e._state?void e._deferreds.push(t):(e._handled=!0,void a(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null===n)return void(1===e._state?r:f)(t.promise,e._value);var o;try{o=n(e._value)}catch(i){return void f(t.promise,i)}r(t.promise,o)}))}function r(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var i=t.then;if(t instanceof o)return e._state=3,e._value=t,void u(e);if("function"==typeof i)return void s(n(i,t),e)}e._state=1,e._value=t,u(e)}catch(r){f(e,r)}}function f(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&setTimeout(function(){e._handled||d(e._value)},1);for(var t=0,n=e._deferreds.length;n>t;t++)i(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,r(t,e))},function(e){n||(n=!0,f(t,e))})}catch(o){if(n)return;n=!0,f(t,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(e){l(e,1)},d=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var r=new o(t);return i(this,new c(e,n,r)),r},o.all=function(e){var t=Array.prototype.slice.call(e);return new o(function(e,n){function o(r,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(e){o(r,e)},n)}t[r]=f,0===--i&&e(t)}catch(c){n(c)}}if(0===t.length)return e([]);for(var i=t.length,r=0;r<t.length;r++)o(r,t[r])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(e){return new o(function(t,n){n(e)})},o.race=function(e){return new o(function(t,n){for(var o=0,i=e.length;i>o;o++)e[o].then(t,n)})},o._setImmediateFn=function(e){a=e},o._setUnhandledRejectionFn=function(e){d=e},"undefined"!=typeof module&&module.exports?module.exports=o:e.Promise||(e.Promise=o)}(this); | ||
!function(e){function t(){}function n(e,t){return function(){e.apply(t,arguments)}}function o(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(e,this)}function r(e,t){for(;3===e._state;)e=e._value;return 0===e._state?void e._deferreds.push(t):(e._handled=!0,void a(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null===n)return void(1===e._state?i:f)(t.promise,e._value);var o;try{o=n(e._value)}catch(r){return void f(t.promise,r)}i(t.promise,o)}))}function i(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var r=t.then;if(t instanceof o)return e._state=3,e._value=t,void u(e);if("function"==typeof r)return void s(n(r,t),e)}e._state=1,e._value=t,u(e)}catch(i){f(e,i)}}function f(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&a(function(){e._handled||d(e._value)},1);for(var t=0,n=e._deferreds.length;n>t;t++)r(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,i(t,e))},function(e){n||(n=!0,f(t,e))})}catch(o){if(n)return;n=!0,f(t,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(e){l(e,1)},d=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var i=new o(t);return r(this,new c(e,n,i)),i},o.all=function(e){var t=Array.prototype.slice.call(e);return new o(function(e,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(e){o(i,e)},n)}t[i]=f,0===--r&&e(t)}catch(c){n(c)}}if(0===t.length)return e([]);for(var r=t.length,i=0;i<t.length;i++)o(i,t[i])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(e){return new o(function(t,n){n(e)})},o.race=function(e){return new o(function(t,n){for(var o=0,r=e.length;r>o;o++)e[o].then(t,n)})},o._setImmediateFn=function(e){a=e},o._setUnhandledRejectionFn=function(e){d=e},"undefined"!=typeof module&&module.exports?module.exports=o:e.Promise||(e.Promise=o)}(this); |
@@ -14,4 +14,2 @@ <a href="http://promises-aplus.github.com/promises-spec"> | ||
This implementation is based on [then/promise](https://github.com/then/promise). It has been changed to use the prototype for performance and memory reasons. | ||
For API information about Promises, please check out this article [HTML5Rocks article](http://www.html5rocks.com/en/tutorials/es6/promises/). | ||
@@ -50,5 +48,4 @@ | ||
// Do something when async done | ||
prom.then(function() { | ||
... | ||
prom.then(function(result) { | ||
// Do something when async done | ||
}); | ||
@@ -55,0 +52,0 @@ ``` |
@@ -10,2 +10,8 @@ var Promise = require('../promise'); | ||
describe('Promise._setImmediateFn', function () { | ||
afterEach(function() { | ||
Promise._setImmediateFn((typeof setImmediate === 'function' && setImmediate) || | ||
function (fn) { | ||
setTimeout(fn, 1); | ||
}); | ||
}); | ||
it('changes immediate fn', function () { | ||
@@ -79,3 +85,3 @@ var spy = sinon.spy(); | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -89,3 +95,3 @@ it('error single Promise', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -101,3 +107,3 @@ it('multi promise error', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -113,3 +119,3 @@ it('promise catch no error', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -127,3 +133,3 @@ it('promise catch no error', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -135,3 +141,3 @@ it('promise reject error', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -146,3 +152,3 @@ it('promise reject error late', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
@@ -154,5 +160,5 @@ it('promise reject error late', function (done) { | ||
done(); | ||
}, 200); | ||
}, 50); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
465
82