rsnext/packages/next/compiled/abort-controller/abort-controller.js
Kiko Beats 0eba5b2558
web runtime: add AbortController & AbortSignal (#32089)
It adds AbortController and AbortSignal Web runtimes APIs to be used by the user at Edge Functions.

For doing that it delegates into `abort-controller` dependency that has been frozen to prevent any modification.

Co-authored-by: Zhang Zhi <20026577+fytriht@users.noreply.github.com>
2021-12-21 17:12:53 +00:00

1 line
No EOL
9.5 KiB
JavaScript

(()=>{"use strict";var e={27:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:true});var r=n(369);class AbortSignal extends r.EventTarget{constructor(){super();throw new TypeError("AbortSignal cannot be constructed directly")}get aborted(){const e=o.get(this);if(typeof e!=="boolean"){throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this===null?"null":typeof this}`)}return e}}r.defineEventAttribute(AbortSignal.prototype,"abort");function createAbortSignal(){const e=Object.create(AbortSignal.prototype);r.EventTarget.call(e);o.set(e,false);return e}function abortSignal(e){if(o.get(e)!==false){return}o.set(e,true);e.dispatchEvent({type:"abort"})}const o=new WeakMap;Object.defineProperties(AbortSignal.prototype,{aborted:{enumerable:true}});if(typeof Symbol==="function"&&typeof Symbol.toStringTag==="symbol"){Object.defineProperty(AbortSignal.prototype,Symbol.toStringTag,{configurable:true,value:"AbortSignal"})}class AbortController{constructor(){i.set(this,createAbortSignal())}get signal(){return getSignal(this)}abort(){abortSignal(getSignal(this))}}const i=new WeakMap;function getSignal(e){const t=i.get(e);if(t==null){throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${e===null?"null":typeof e}`)}return t}Object.defineProperties(AbortController.prototype,{signal:{enumerable:true},abort:{enumerable:true}});if(typeof Symbol==="function"&&typeof Symbol.toStringTag==="symbol"){Object.defineProperty(AbortController.prototype,Symbol.toStringTag,{configurable:true,value:"AbortController"})}t.AbortController=AbortController;t.AbortSignal=AbortSignal;t["default"]=AbortController;e.exports=AbortController;e.exports.AbortController=e.exports["default"]=AbortController;e.exports.AbortSignal=AbortSignal},369:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});const n=new WeakMap;const r=new WeakMap;function pd(e){const t=n.get(e);console.assert(t!=null,"'this' is expected an Event object, but got",e);return t}function setCancelFlag(e){if(e.passiveListener!=null){if(typeof console!=="undefined"&&typeof console.error==="function"){console.error("Unable to preventDefault inside passive event listener invocation.",e.passiveListener)}return}if(!e.event.cancelable){return}e.canceled=true;if(typeof e.event.preventDefault==="function"){e.event.preventDefault()}}function Event(e,t){n.set(this,{eventTarget:e,event:t,eventPhase:2,currentTarget:e,canceled:false,stopped:false,immediateStopped:false,passiveListener:null,timeStamp:t.timeStamp||Date.now()});Object.defineProperty(this,"isTrusted",{value:false,enumerable:true});const r=Object.keys(t);for(let e=0;e<r.length;++e){const t=r[e];if(!(t in this)){Object.defineProperty(this,t,defineRedirectDescriptor(t))}}}Event.prototype={get type(){return pd(this).event.type},get target(){return pd(this).eventTarget},get currentTarget(){return pd(this).currentTarget},composedPath(){const e=pd(this).currentTarget;if(e==null){return[]}return[e]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return pd(this).eventPhase},stopPropagation(){const e=pd(this);e.stopped=true;if(typeof e.event.stopPropagation==="function"){e.event.stopPropagation()}},stopImmediatePropagation(){const e=pd(this);e.stopped=true;e.immediateStopped=true;if(typeof e.event.stopImmediatePropagation==="function"){e.event.stopImmediatePropagation()}},get bubbles(){return Boolean(pd(this).event.bubbles)},get cancelable(){return Boolean(pd(this).event.cancelable)},preventDefault(){setCancelFlag(pd(this))},get defaultPrevented(){return pd(this).canceled},get composed(){return Boolean(pd(this).event.composed)},get timeStamp(){return pd(this).timeStamp},get srcElement(){return pd(this).eventTarget},get cancelBubble(){return pd(this).stopped},set cancelBubble(e){if(!e){return}const t=pd(this);t.stopped=true;if(typeof t.event.cancelBubble==="boolean"){t.event.cancelBubble=true}},get returnValue(){return!pd(this).canceled},set returnValue(e){if(!e){setCancelFlag(pd(this))}},initEvent(){}};Object.defineProperty(Event.prototype,"constructor",{value:Event,configurable:true,writable:true});if(typeof window!=="undefined"&&typeof window.Event!=="undefined"){Object.setPrototypeOf(Event.prototype,window.Event.prototype);r.set(window.Event.prototype,Event)}function defineRedirectDescriptor(e){return{get(){return pd(this).event[e]},set(t){pd(this).event[e]=t},configurable:true,enumerable:true}}function defineCallDescriptor(e){return{value(){const t=pd(this).event;return t[e].apply(t,arguments)},configurable:true,enumerable:true}}function defineWrapper(e,t){const n=Object.keys(t);if(n.length===0){return e}function CustomEvent(t,n){e.call(this,t,n)}CustomEvent.prototype=Object.create(e.prototype,{constructor:{value:CustomEvent,configurable:true,writable:true}});for(let r=0;r<n.length;++r){const o=n[r];if(!(o in e.prototype)){const e=Object.getOwnPropertyDescriptor(t,o);const n=typeof e.value==="function";Object.defineProperty(CustomEvent.prototype,o,n?defineCallDescriptor(o):defineRedirectDescriptor(o))}}return CustomEvent}function getWrapper(e){if(e==null||e===Object.prototype){return Event}let t=r.get(e);if(t==null){t=defineWrapper(getWrapper(Object.getPrototypeOf(e)),e);r.set(e,t)}return t}function wrapEvent(e,t){const n=getWrapper(Object.getPrototypeOf(t));return new n(e,t)}function isStopped(e){return pd(e).immediateStopped}function setEventPhase(e,t){pd(e).eventPhase=t}function setCurrentTarget(e,t){pd(e).currentTarget=t}function setPassiveListener(e,t){pd(e).passiveListener=t}const o=new WeakMap;const i=1;const l=2;const s=3;function isObject(e){return e!==null&&typeof e==="object"}function getListeners(e){const t=o.get(e);if(t==null){throw new TypeError("'this' is expected an EventTarget object, but got another value.")}return t}function defineEventAttributeDescriptor(e){return{get(){const t=getListeners(this);let n=t.get(e);while(n!=null){if(n.listenerType===s){return n.listener}n=n.next}return null},set(t){if(typeof t!=="function"&&!isObject(t)){t=null}const n=getListeners(this);let r=null;let o=n.get(e);while(o!=null){if(o.listenerType===s){if(r!==null){r.next=o.next}else if(o.next!==null){n.set(e,o.next)}else{n.delete(e)}}else{r=o}o=o.next}if(t!==null){const o={listener:t,listenerType:s,passive:false,once:false,next:null};if(r===null){n.set(e,o)}else{r.next=o}}},configurable:true,enumerable:true}}function defineEventAttribute(e,t){Object.defineProperty(e,`on${t}`,defineEventAttributeDescriptor(t))}function defineCustomEventTarget(e){function CustomEventTarget(){EventTarget.call(this)}CustomEventTarget.prototype=Object.create(EventTarget.prototype,{constructor:{value:CustomEventTarget,configurable:true,writable:true}});for(let t=0;t<e.length;++t){defineEventAttribute(CustomEventTarget.prototype,e[t])}return CustomEventTarget}function EventTarget(){if(this instanceof EventTarget){o.set(this,new Map);return}if(arguments.length===1&&Array.isArray(arguments[0])){return defineCustomEventTarget(arguments[0])}if(arguments.length>0){const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t){e[t]=arguments[t]}return defineCustomEventTarget(e)}throw new TypeError("Cannot call a class as a function")}EventTarget.prototype={addEventListener(e,t,n){if(t==null){return}if(typeof t!=="function"&&!isObject(t)){throw new TypeError("'listener' should be a function or an object.")}const r=getListeners(this);const o=isObject(n);const s=o?Boolean(n.capture):Boolean(n);const u=s?i:l;const a={listener:t,listenerType:u,passive:o&&Boolean(n.passive),once:o&&Boolean(n.once),next:null};let p=r.get(e);if(p===undefined){r.set(e,a);return}let c=null;while(p!=null){if(p.listener===t&&p.listenerType===u){return}c=p;p=p.next}c.next=a},removeEventListener(e,t,n){if(t==null){return}const r=getListeners(this);const o=isObject(n)?Boolean(n.capture):Boolean(n);const s=o?i:l;let u=null;let a=r.get(e);while(a!=null){if(a.listener===t&&a.listenerType===s){if(u!==null){u.next=a.next}else if(a.next!==null){r.set(e,a.next)}else{r.delete(e)}return}u=a;a=a.next}},dispatchEvent(e){if(e==null||typeof e.type!=="string"){throw new TypeError('"event.type" should be a string.')}const t=getListeners(this);const n=e.type;let r=t.get(n);if(r==null){return true}const o=wrapEvent(this,e);let i=null;while(r!=null){if(r.once){if(i!==null){i.next=r.next}else if(r.next!==null){t.set(n,r.next)}else{t.delete(n)}}else{i=r}setPassiveListener(o,r.passive?r.listener:null);if(typeof r.listener==="function"){try{r.listener.call(this,o)}catch(e){if(typeof console!=="undefined"&&typeof console.error==="function"){console.error(e)}}}else if(r.listenerType!==s&&typeof r.listener.handleEvent==="function"){r.listener.handleEvent(o)}if(isStopped(o)){break}r=r.next}setPassiveListener(o,null);setEventPhase(o,0);setCurrentTarget(o,null);return!o.defaultPrevented}};Object.defineProperty(EventTarget.prototype,"constructor",{value:EventTarget,configurable:true,writable:true});if(typeof window!=="undefined"&&typeof window.EventTarget!=="undefined"){Object.setPrototypeOf(EventTarget.prototype,window.EventTarget.prototype)}t.defineEventAttribute=defineEventAttribute;t.EventTarget=EventTarget;t["default"]=EventTarget;e.exports=EventTarget;e.exports.EventTarget=e.exports["default"]=EventTarget;e.exports.defineEventAttribute=defineEventAttribute}};var t={};function __nccwpck_require__(n){var r=t[n];if(r!==undefined){return r.exports}var o=t[n]={exports:{}};var i=true;try{e[n](o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete t[n]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n=__nccwpck_require__(27);module.exports=n})();