EmbyCrackedClient/web/modules/polyfills/abortsignal.js

1 line
2.1 KiB
JavaScript
Raw Permalink Normal View History

2025-06-25 11:46:04 +08:00
class Emitter{constructor(){Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}addEventListener(type,callback,options){type in this.listeners||(this.listeners[type]=[]),this.listeners[type].push({callback:callback,options:options})}removeEventListener(type,callback){if(type in this.listeners){var stack=this.listeners[type];for(let i=0,l=stack.length;i<l;i++)if(stack[i].callback===callback)return void stack.splice(i,1)}}dispatchEvent(event){if(event.type in this.listeners){var stackToCall=this.listeners[event.type].slice();for(let i=0,l=stackToCall.length;i<l;i++){var listener=stackToCall[i];try{listener.callback.call(this,event)}catch(e){Promise.resolve().then(()=>{throw e})}listener.options&&listener.options.once&&this.removeEventListener(event.type,listener.callback)}return!event.defaultPrevented}}}class AbortSignalPolyfill extends Emitter{constructor(){super(),this.listeners||Emitter.call(this),Object.defineProperty(this,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(this,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"reason",{value:void 0,writable:!0,configurable:!0})}toString(){return"[object AbortSignal]"}dispatchEvent(event){"abort"===event.type&&(this.aborted=!0,"function"==typeof this.onabort)&&this.onabort.call(this,event),super.dispatchEvent(event)}}let isMissingRequestSignalSupport="function"==typeof globalThis.Request&&!Object.prototype.hasOwnProperty.call(globalThis.Request.prototype,"signal");"undefined"!=typeof AbortSignal&&!isMissingRequestSignalSupport||Object.defineProperty(globalThis,"AbortSignal",{writable:!0,enumerable:!1,configurable:!0,value:AbortSignalPolyfill}),AbortSignal.timeout||(AbortSignal.timeout=function(duration){let controller=new AbortController;return setTimeout(()=>controller.abort(),duration),controller.signal}),AbortSignal.prototype.throwIfAborted||(AbortSignal.prototype.throwIfAborted=function(){if(this.aborted){let reason=this.reason;throw reason||((reason=new Error("Aborted")).name="AbortError"),reason}});export default AbortSignalPolyfill;export{AbortSignalPolyfill};