UNPKG

her-promise

Version:

This is a polyfill of the ES6/ES9/ES11/ES12 Promise.

1 lines 6.07 kB
(()=>{var e={231:e=>{e.exports=function(){var e,t,r,n,o,i,u,c,s,f=0,a=new Array(1024);function l(){for(var e=0;e<f;++e)a[e](),a[e]=void 0;f=0}return"undefined"!=typeof window&&(e=window.MutationObserver||window.WebKitMutationObserver),t="function"==typeof Promise&&"function"==typeof Promise.resolve?(s=Promise.resolve(),function(){s.then(l,console.error)}):e?(i=1,u=new e(l),c=document.createTextNode(String(i)),u.observe(c,{characterData:!0}),function(){i=(i+1)%2,c.data=String(i)}):"function"==typeof importScripts&&"function"==typeof MessageChannel?((o=new MessageChannel).port1.onmessage=l,function(){o.port2.postMessage(0)}):"function"==typeof setImmediate?(n=setImmediate,function(){n(l)}):(r=setTimeout,function(){r(l,0)}),function(e){a[f]=e,1==++f&&t()}}()},264:(e,t,r)=>{"use strict";r.r(t);var n=r(593);(0,n.UB)(Promise,"allSettled",(function(e){return new Promise((function(t,r){if((0,n.H1)(e)){var o=e.length,i=new Array(o);if(0!==o)for(var u=0,c=function(t){(e[t]instanceof Promise?e[t]:Promise.resolve(e[t])).then((function(e){i[t]={status:"fulfilled",value:e},f()}),(function(e){i[t]={status:"rejected",reason:e},f()}))},s=0;s<o;++s)c(s);else t(i)}else r(new TypeError("The arguments must be Array."));function f(){++u===o&&t(i)}}))}))},88:(e,t,r)=>{"use strict";r.d(t,{B:()=>o});var n,o,i=r(593),u=(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});o="function"==typeof AggregateError?AggregateError:function(e){function t(t,r){void 0===r&&(r="All promises were rejected.");var n=e.call(this,r)||this;return n.errors=t,n}return u(t,e),t}(Error),(0,i.UB)(Promise,"any",(function(e){return new Promise((function(t,r){if((0,i.H1)(e)){var n=e.length,u=new Array(0);if(0!==n)for(var c=0,s=0;s<n;++s)(e[s]instanceof Promise?e[s]:Promise.resolve(e[s])).then(t,f);else r(new o(u))}else r(new TypeError("The arguments must be Array."));function f(e){u.push(e),++c===n&&r(new o(u))}}))}))},909:(e,t,r)=>{"use strict";r.r(t);var n=r(593);(0,n.UB)(Promise.prototype,"finally",(function(e){return this.then((function(t){return Promise.resolve((0,n.Wl)(e)?e():e).then((function(){return t}))}),(function(t){return Promise.resolve((0,n.Wl)(e)?e():e).then((function(){throw t}))}))}))},744:(e,t,r)=>{"use strict";r.d(t,{J:()=>l});var n=r(231),o=r.n(n),i=r(593),u="pending",c="fulfilled",s="rejected";function f(e,t,r,n,o,u){if(!(0,i.Wl)(e))return u===o&&console.error("Uncaught (in promise) ".concat(String(t))),void u(t);var c;try{c=e(t)}catch(e){return void o(e)}c!==r?a(c,n,o):o(new TypeError("Chaining cycle detected for promise #<Promise>"))}function a(e,t,r){if((0,i.lU)(e)){var n=void 0;try{n=e.then}catch(e){return void r(e)}if((0,i.Wl)(n))return void(e instanceof l?n.call(e,t,r):function(e,t,r,n){o()((function(){var o=!1;try{e.call(t,(function(e){o||(o=!0,a(e,r,n))}),(function(e){o||(o=!0,n(e))}))}catch(e){o||(o=!0,n(e))}}))}(n,e,t,r))}t(e)}var l=function(){function e(e){var t=this;this._state=u,this._value=void 0,this._reason=void 0,this._resolves=[],this._rejects=[];var r=this._resolves,n=function(e){if(t._state===u){t._state=c,t._value=e;var n=r.length;if(0===n)return;for(var o=0;o<n;++o)r[o]();r.length=0}},o=this._rejects,i=function(e){if(t._state===u){t._state=s,t._reason=e;var r=o.length;if(0===r)return;for(var n=0;n<r;++n)o[n]();o.length=0}};try{e((function(e){a(e,n,i)}),i)}catch(e){i(e)}}return e.all=function(t){return new e((function(e,r){if(!(0,i.H1)(t))return r(new TypeError("The arguments must be Array."));var n=t.length,o=new Array(n);if(0===n)return e(o);var u=0,c=!1;function s(e){c||(c=!0,r(e))}for(var f=function(r){a(t[r],(function(t){return function(t,r){c||(o[r]=t,++u===n&&e(o))}(t,r)}),s)},l=0;!c&&l<n;++l)f(l)}))},e.race=function(t){return new e((function(e,r){if(!(0,i.H1)(t))return r(new TypeError("The arguments must be Array."));for(var n=t.length,o=0;o<n;++o)a(t[o],e,r)}))},e.reject=function(t){return new e((function(e,r){return r(t)}))},e.resolve=function(t){return t instanceof e?t:new e((function(e){return e(t)}))},e.prototype.then=function(t,r){var n=this,i=new e((function(e,u){switch(n._state){case c:o()((function(){f(t,n._value,i,e,u,e)}));break;case s:o()((function(){f(r,n._reason,i,e,u,u)}));break;default:n._resolves.push((function(){o()((function(){f(t,n._value,i,e,u,e)}))})),n._rejects.push((function(){o()((function(){f(r,n._reason,i,e,u,u)}))}))}}));return i},e.prototype.catch=function(e){return this.then(void 0,e)},e}()},593:(e,t,r)=>{"use strict";function n(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}function o(e){return"function"==typeof e}r.d(t,{lU:()=>n,Wl:()=>o,H1:()=>i,UB:()=>u});var i=o(Array.isArray)?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};function u(e,t,r){o(e[t])||Object.defineProperty(e,t,{configurable:!0,enumerable:!1,value:r,writable:!0})}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{"use strict";var e="object"==typeof window?window:"object"==typeof r.g?r.g:self;"function"!=typeof e.Promise&&(e.Promise=r(744).J),r(909),r(264),e.AggregateError=r(88).B})()})();