promise-polyfill
Advanced tools
Comparing version 8.1.3 to 8.2.0
@@ -29,2 +29,50 @@ (function (global, factory) { | ||
function allSettled(arr) { | ||
var P = this; | ||
return new P(function(resolve, reject) { | ||
if (!(arr && typeof arr.length !== 'undefined')) { | ||
return reject( | ||
new TypeError( | ||
typeof arr + | ||
' ' + | ||
arr + | ||
' is not iterable(cannot read property Symbol(Symbol.iterator))' | ||
) | ||
); | ||
} | ||
var args = Array.prototype.slice.call(arr); | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
function res(i, val) { | ||
if (val && (typeof val === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call( | ||
val, | ||
function(val) { | ||
res(i, val); | ||
}, | ||
function(e) { | ||
args[i] = { status: 'rejected', reason: e }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
); | ||
return; | ||
} | ||
} | ||
args[i] = { status: 'fulfilled', value: val }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
} | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
@@ -233,2 +281,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers()) | ||
Promise.allSettled = allSettled; | ||
Promise.resolve = function(value) { | ||
@@ -297,8 +347,14 @@ if (value && typeof value === 'object' && value.constructor === Promise) { | ||
if (!('Promise' in globalNS)) { | ||
// Expose the polyfill if Promise is undefined or set to a | ||
// non-function value. The latter can be due to a named HTMLElement | ||
// being exposed by browsers for legacy reasons. | ||
// https://github.com/taylorhakes/promise-polyfill/issues/114 | ||
if (typeof globalNS['Promise'] !== 'function') { | ||
globalNS['Promise'] = Promise; | ||
} else if (!globalNS.Promise.prototype['finally']) { | ||
globalNS.Promise.prototype['finally'] = finallyConstructor; | ||
} else if (!globalNS.Promise.allSettled) { | ||
globalNS.Promise.allSettled = allSettled; | ||
} | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(e){return!(!e||"undefined"==typeof e.length)}function t(){}function o(e){if(!(this instanceof o))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=undefined,this._deferreds=[],c(e,this)}function r(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,o._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(r){return void f(n.promise,r)}i(n.promise,o)}else(1===e._state?i:f)(n.promise,e._value)})):e._deferreds.push(n)}function i(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var t=n.then;if(n instanceof o)return e._state=3,e._value=n,void u(e);if("function"==typeof t)return void c(function(e,n){return function(){e.apply(n,arguments)}}(t,n),e)}e._state=1,e._value=n,u(e)}catch(r){f(e,r)}}function f(e,n){e._state=2,e._value=n,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&o._immediateFn(function(){e._handled||o._unhandledRejectionFn(e._value)});for(var n=0,t=e._deferreds.length;t>n;n++)r(e,e._deferreds[n]);e._deferreds=null}function c(e,n){var t=!1;try{e(function(e){t||(t=!0,i(n,e))},function(e){t||(t=!0,f(n,e))})}catch(o){if(t)return;t=!0,f(n,o)}}var a=setTimeout;o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var o=new this.constructor(t);return r(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,n,o)),o},o.prototype["finally"]=e,o.all=function(e){return new o(function(t,o){function r(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var u=n.then;if("function"==typeof u)return void u.call(n,function(n){r(e,n)},o)}i[e]=n,0==--f&&t(i)}catch(c){o(c)}}if(!n(e))return o(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(n){n(e)})},o.reject=function(e){return new o(function(n,t){t(e)})},o.race=function(e){return new o(function(t,r){if(!n(e))return r(new TypeError("Promise.race accepts an array"));for(var i=0,f=e.length;f>i;i++)o.resolve(e[i]).then(t,r)})},o._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){a(e,0)},o._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=o}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}function t(e){return new this(function(t,n){function o(e,n){if(n&&("object"==typeof n||"function"==typeof n)){var f=n.then;if("function"==typeof f)return void f.call(n,function(t){o(e,t)},function(n){r[e]={status:"rejected",reason:n},0==--i&&t(r)})}r[e]={status:"fulfilled",value:n},0==--i&&t(r)}if(!e||"undefined"==typeof e.length)return n(new TypeError(typeof e+" "+e+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var r=Array.prototype.slice.call(e);if(0===r.length)return t([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})}function n(e){return!(!e||"undefined"==typeof e.length)}function o(){}function r(e){if(!(this instanceof r))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=undefined,this._deferreds=[],l(e,this)}function i(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,r._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var o;try{o=n(e._value)}catch(r){return void u(t.promise,r)}f(t.promise,o)}else(1===e._state?f:u)(t.promise,e._value)})):e._deferreds.push(t)}function f(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 n=t.then;if(t instanceof r)return e._state=3,e._value=t,void c(e);if("function"==typeof n)return void l(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,c(e)}catch(o){u(e,o)}}function u(e,t){e._state=2,e._value=t,c(e)}function c(e){2===e._state&&0===e._deferreds.length&&r._immediateFn(function(){e._handled||r._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;n>t;t++)i(e,e._deferreds[t]);e._deferreds=null}function l(e,t){var n=!1;try{e(function(e){n||(n=!0,f(t,e))},function(e){n||(n=!0,u(t,e))})}catch(o){if(n)return;n=!0,u(t,o)}}var a=setTimeout;r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){var n=new this.constructor(o);return i(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},r.prototype["finally"]=e,r.all=function(e){return new r(function(t,o){function r(e,n){try{if(n&&("object"==typeof n||"function"==typeof n)){var u=n.then;if("function"==typeof u)return void u.call(n,function(t){r(e,t)},o)}i[e]=n,0==--f&&t(i)}catch(c){o(c)}}if(!n(e))return o(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(e);if(0===i.length)return t([]);for(var f=i.length,u=0;i.length>u;u++)r(u,i[u])})},r.allSettled=t,r.resolve=function(e){return e&&"object"==typeof e&&e.constructor===r?e:new r(function(t){t(e)})},r.reject=function(e){return new r(function(t,n){n(e)})},r.race=function(e){return new r(function(t,o){if(!n(e))return o(new TypeError("Promise.race accepts an array"));for(var i=0,f=e.length;f>i;i++)r.resolve(e[i]).then(t,o)})},r._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){a(e,0)},r._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var s=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"function"!=typeof s.Promise?s.Promise=r:s.Promise.prototype["finally"]?s.Promise.allSettled||(s.Promise.allSettled=t):s.Promise.prototype["finally"]=e}); |
@@ -25,2 +25,50 @@ 'use strict'; | ||
function allSettled(arr) { | ||
var P = this; | ||
return new P(function(resolve, reject) { | ||
if (!(arr && typeof arr.length !== 'undefined')) { | ||
return reject( | ||
new TypeError( | ||
typeof arr + | ||
' ' + | ||
arr + | ||
' is not iterable(cannot read property Symbol(Symbol.iterator))' | ||
) | ||
); | ||
} | ||
var args = Array.prototype.slice.call(arr); | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
function res(i, val) { | ||
if (val && (typeof val === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call( | ||
val, | ||
function(val) { | ||
res(i, val); | ||
}, | ||
function(e) { | ||
args[i] = { status: 'rejected', reason: e }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
); | ||
return; | ||
} | ||
} | ||
args[i] = { status: 'fulfilled', value: val }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
} | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
@@ -229,2 +277,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers()) | ||
Promise.allSettled = allSettled; | ||
Promise.resolve = function(value) { | ||
@@ -231,0 +281,0 @@ if (value && typeof value === 'object' && value.constructor === Promise) { |
@@ -25,2 +25,50 @@ 'use strict'; | ||
function allSettled(arr) { | ||
var P = this; | ||
return new P(function(resolve, reject) { | ||
if (!(arr && typeof arr.length !== 'undefined')) { | ||
return reject( | ||
new TypeError( | ||
typeof arr + | ||
' ' + | ||
arr + | ||
' is not iterable(cannot read property Symbol(Symbol.iterator))' | ||
) | ||
); | ||
} | ||
var args = Array.prototype.slice.call(arr); | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
function res(i, val) { | ||
if (val && (typeof val === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call( | ||
val, | ||
function(val) { | ||
res(i, val); | ||
}, | ||
function(e) { | ||
args[i] = { status: 'rejected', reason: e }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
); | ||
return; | ||
} | ||
} | ||
args[i] = { status: 'fulfilled', value: val }; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
} | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
@@ -229,2 +277,4 @@ // other code modifying setTimeout (like sinon.useFakeTimers()) | ||
Promise.allSettled = allSettled; | ||
Promise.resolve = function(value) { | ||
@@ -293,6 +343,12 @@ if (value && typeof value === 'object' && value.constructor === Promise) { | ||
if (!('Promise' in globalNS)) { | ||
// Expose the polyfill if Promise is undefined or set to a | ||
// non-function value. The latter can be due to a named HTMLElement | ||
// being exposed by browsers for legacy reasons. | ||
// https://github.com/taylorhakes/promise-polyfill/issues/114 | ||
if (typeof globalNS['Promise'] !== 'function') { | ||
globalNS['Promise'] = Promise; | ||
} else if (!globalNS.Promise.prototype['finally']) { | ||
globalNS.Promise.prototype['finally'] = finallyConstructor; | ||
} else if (!globalNS.Promise.allSettled) { | ||
globalNS.Promise.allSettled = allSettled; | ||
} |
{ | ||
"name": "promise-polyfill", | ||
"version": "8.1.3", | ||
"version": "8.2.0", | ||
"description": "Lightweight promise polyfill. A+ compliant", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import promiseFinally from './finally'; | ||
import allSettled from './allSettled'; | ||
@@ -206,2 +207,4 @@ // Store setTimeout reference so promise-polyfill will be unaffected by | ||
Promise.allSettled = allSettled; | ||
Promise.resolve = function(value) { | ||
@@ -208,0 +211,0 @@ if (value && typeof value === 'object' && value.constructor === Promise) { |
import Promise from './index'; | ||
import promiseFinally from './finally'; | ||
import allSettled from './allSettled'; | ||
@@ -21,6 +22,12 @@ /** @suppress {undefinedVars} */ | ||
if (!('Promise' in globalNS)) { | ||
// Expose the polyfill if Promise is undefined or set to a | ||
// non-function value. The latter can be due to a named HTMLElement | ||
// being exposed by browsers for legacy reasons. | ||
// https://github.com/taylorhakes/promise-polyfill/issues/114 | ||
if (typeof globalNS['Promise'] !== 'function') { | ||
globalNS['Promise'] = Promise; | ||
} else if (!globalNS.Promise.prototype['finally']) { | ||
globalNS.Promise.prototype['finally'] = promiseFinally; | ||
} else if (!globalNS.Promise.allSettled) { | ||
globalNS.Promise.allSettled = allSettled; | ||
} |
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
49134
12
1265