@building-block/idl-domexception
Version:
DOMException polyfill
3 lines (2 loc) • 11.9 kB
JavaScript
;function e(e,r){return e(r={exports:{}},r.exports),r.exports}var r,t=e(function(e,r){function t(e,r){return`${r&&r.context?r.context:"Value"} ${e}.`}function o(e){return i(Math.trunc(e))}function n(e){return e<0?-1:1}function i(e){return 0===e?0:e}function a(e,r){const a=!r.unsigned;let u,p;64===e?(p=Math.pow(2,53)-1,u=a?1-Math.pow(2,53):0):a?(u=-Math.pow(2,e-1),p=Math.pow(2,e-1)-1):(u=0,p=Math.pow(2,e)-1);const l=Math.pow(2,e),c=Math.pow(2,e-1);return(e,r)=>{void 0===r&&(r={});let f=+e;if(f=i(f),r.enforceRange){if(!Number.isFinite(f))throw new TypeError(t("is not a finite number",r));if((f=o(f))<u||f>p)throw new TypeError(t(`is outside the accepted range of ${u} to ${p}, inclusive`,r));return f}return!Number.isNaN(f)&&r.clamp?f=function(e){return i(e>0&&e%1==.5&&0==(1&e)||e<0&&e%1==-.5&&1==(1&e)?Math.floor(e):Math.round(e))}(f=Math.min(Math.max(f,u),p)):Number.isFinite(f)&&0!==f?(f=o(f))>=u&&f<=p?f:(f=function(e,r){const t=e%r;return n(r)!==n(t)?t+r:t}(f,l),a&&f>=c?f-l:f):0}}function u(e,r){if("function"!=typeof e)throw new TypeError(t("is not a function",r));return e}r.any=(e=>e),r.void=function(){},r.boolean=function(e){return!!e},r.byte=a(8,{unsigned:!1}),r.octet=a(8,{unsigned:!0}),r.short=a(16,{unsigned:!1}),r["unsigned short"]=a(16,{unsigned:!0}),r.long=a(32,{unsigned:!1}),r["unsigned long"]=a(32,{unsigned:!0}),r["long long"]=a(64,{unsigned:!1}),r["unsigned long long"]=a(64,{unsigned:!0}),r.double=((e,r)=>{const o=+e;if(!Number.isFinite(o))throw new TypeError(t("is not a finite floating-point value",r));return o}),r["unrestricted double"]=(e=>+e),r.float=((e,r)=>{const o=+e;if(!Number.isFinite(o))throw new TypeError(t("is not a finite floating-point value",r));if(Object.is(o,-0))return o;const n=Math.fround(o);if(!Number.isFinite(n))throw new TypeError(t("is outside the range of a single-precision floating-point value",r));return n}),r["unrestricted float"]=(e=>{const r=+e;return isNaN(r)?r:Object.is(r,-0)?r:Math.fround(r)}),r.DOMString=function(e,r){if(void 0===r&&(r={}),r.treatNullAsEmptyString&&null===e)return"";if("symbol"==typeof e)throw new TypeError(t("is a symbol, which cannot be converted to a string",r));return String(e)},r.ByteString=((e,o)=>{const n=r.DOMString(e,o);let i;for(let e=0;void 0!==(i=n.codePointAt(e));++e)if(i>255)throw new TypeError(t("is not a valid ByteString",o));return n}),r.USVString=((e,t)=>{const o=r.DOMString(e,t),n=o.length,i=[];for(let e=0;e<n;++e){const r=o.charCodeAt(e);if(r<55296||r>57343)i.push(String.fromCodePoint(r));else if(56320<=r&&r<=57343)i.push(String.fromCodePoint(65533));else if(e===n-1)i.push(String.fromCodePoint(65533));else{const t=o.charCodeAt(e+1);56320<=t&&t<=57343?(i.push(String.fromCodePoint(65536+1024*(1023&r)+(1023&t))),++e):i.push(String.fromCodePoint(65533))}}return i.join("")}),r.object=((e,r)=>{if("Object"!==function(e){if(null===e)return"Null";switch(typeof e){case"undefined":return"Undefined";case"boolean":return"Boolean";case"number":return"Number";case"string":return"String";case"symbol":return"Symbol";case"object":case"function":default:return"Object"}}(e))throw new TypeError(t("is not an object",r));return e}),[Error,ArrayBuffer,DataView,Int8Array,Int16Array,Int32Array,Uint8Array,Uint16Array,Uint32Array,Uint8ClampedArray,Float32Array,Float64Array].forEach(e=>{const o=e.name,n=/^[AEIOU]/.test(o)?"an":"a";r[o]=((r,i)=>{if(!(r instanceof e))throw new TypeError(t(`is not ${n} ${o} object`,i));return r})}),r.ArrayBufferView=((e,r)=>{if(!ArrayBuffer.isView(e))throw new TypeError(t("is not a view on an ArrayBuffer object",r));return e}),r.BufferSource=((e,r)=>{if(!(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))throw new TypeError(t("is not an ArrayBuffer object or a view on one",r));return e}),r.DOMTimeStamp=r["unsigned long long"],r.Function=u,r.VoidFunction=u}),o=e(function(e,r){function t(e){return Object.getPrototypeOf(e)===Buffer.prototype?e:e instanceof ArrayBuffer?Buffer.from(e):Buffer.from(e.buffer,e.byteOffset,e.byteLength)}const o=Symbol("wrapper"),n=Symbol("impl"),i=Symbol("SameObject caches");function a(e){return e?e[o]:null}function u(e){return e?e[n]:null}const p=Symbol("internal"),l=Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));e.exports={isObject:function(e){return"object"==typeof e&&null!==e||"function"==typeof e},getReferenceToBytes:t,getCopyToBytes:function(e){return Buffer.from(t(e))},mixin:function(e,r){const t=Object.getOwnPropertyNames(r);for(let o=0;o<t.length;++o)t[o]in e||Object.defineProperty(e,t[o],Object.getOwnPropertyDescriptor(r,t[o]))},wrapperSymbol:o,implSymbol:n,getSameObject:function(e,r,t){return e[i]||(e[i]=Object.create(null)),r in e[i]?e[i][r]:(e[i][r]=t(),e[i][r])},wrapperForImpl:a,implForWrapper:u,tryWrapperForImpl:function(e){return a(e)||e},tryImplForWrapper:function(e){return u(e)||e},iterInternalSymbol:p,IteratorPrototype:l}}),n=(r={IndexSizeError:1,DOMStringSizeError:2,HierarchyRequestError:3,WrongDocumentError:4,InvalidCharacterError:5,NoDataAllowedError:6,NoModificationAllowedError:7,NotFoundError:8,NotSupportedError:9,InUseAttributeError:10,InvalidStateError:11,InvalidModificationError:13,NamespaceError:14,InvalidAccessError:15,ValidationError:16,TypeMismatchError:17,SecurityError:18,NetworkError:19,AbortError:20,URLMismatchError:21,QuotaExceededError:22,TimeoutError:23,InvalidNodeTypeError:24,DataCloneError:25,default:{IndexSizeError:1,DOMStringSizeError:2,HierarchyRequestError:3,WrongDocumentError:4,InvalidCharacterError:5,NoDataAllowedError:6,NoModificationAllowedError:7,NotFoundError:8,NotSupportedError:9,InUseAttributeError:10,InvalidStateError:11,SyntaxError:12,InvalidModificationError:13,NamespaceError:14,InvalidAccessError:15,ValidationError:16,TypeMismatchError:17,SecurityError:18,NetworkError:19,AbortError:20,URLMismatchError:21,QuotaExceededError:22,TimeoutError:23,InvalidNodeTypeError:24,DataCloneError:25}})&&r.default||r,i=class{constructor([e,r]){this.name=r,this.message=e}get code(){return n[this.name]||0}},a=e=>{if(Error.captureStackTrace){const r=o.wrapperForImpl(e);Error.captureStackTrace(r,r.constructor)}},u=e(function(e){const r=o.implSymbol;function n(){const e=[];for(let r=0;r<arguments.length&&r<2;++r)e[r]=arguments[r];e[0]=void 0!==e[0]?t.DOMString(e[0],{context:"Failed to construct 'DOMException': parameter 1"}):"",e[1]=void 0!==e[1]?t.DOMString(e[1],{context:"Failed to construct 'DOMException': parameter 2"}):"Error",u.setup(this,e)}Object.defineProperty(n,"prototype",{value:n.prototype,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(n.prototype,"name",{get(){return this[r].name},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"message",{get(){return this[r].message},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"code",{get(){return this[r].code},enumerable:!0,configurable:!0}),Object.defineProperty(n,"INDEX_SIZE_ERR",{value:1,enumerable:!0}),Object.defineProperty(n.prototype,"INDEX_SIZE_ERR",{value:1,enumerable:!0}),Object.defineProperty(n,"DOMSTRING_SIZE_ERR",{value:2,enumerable:!0}),Object.defineProperty(n.prototype,"DOMSTRING_SIZE_ERR",{value:2,enumerable:!0}),Object.defineProperty(n,"HIERARCHY_REQUEST_ERR",{value:3,enumerable:!0}),Object.defineProperty(n.prototype,"HIERARCHY_REQUEST_ERR",{value:3,enumerable:!0}),Object.defineProperty(n,"WRONG_DOCUMENT_ERR",{value:4,enumerable:!0}),Object.defineProperty(n.prototype,"WRONG_DOCUMENT_ERR",{value:4,enumerable:!0}),Object.defineProperty(n,"INVALID_CHARACTER_ERR",{value:5,enumerable:!0}),Object.defineProperty(n.prototype,"INVALID_CHARACTER_ERR",{value:5,enumerable:!0}),Object.defineProperty(n,"NO_DATA_ALLOWED_ERR",{value:6,enumerable:!0}),Object.defineProperty(n.prototype,"NO_DATA_ALLOWED_ERR",{value:6,enumerable:!0}),Object.defineProperty(n,"NO_MODIFICATION_ALLOWED_ERR",{value:7,enumerable:!0}),Object.defineProperty(n.prototype,"NO_MODIFICATION_ALLOWED_ERR",{value:7,enumerable:!0}),Object.defineProperty(n,"NOT_FOUND_ERR",{value:8,enumerable:!0}),Object.defineProperty(n.prototype,"NOT_FOUND_ERR",{value:8,enumerable:!0}),Object.defineProperty(n,"NOT_SUPPORTED_ERR",{value:9,enumerable:!0}),Object.defineProperty(n.prototype,"NOT_SUPPORTED_ERR",{value:9,enumerable:!0}),Object.defineProperty(n,"INUSE_ATTRIBUTE_ERR",{value:10,enumerable:!0}),Object.defineProperty(n.prototype,"INUSE_ATTRIBUTE_ERR",{value:10,enumerable:!0}),Object.defineProperty(n,"INVALID_STATE_ERR",{value:11,enumerable:!0}),Object.defineProperty(n.prototype,"INVALID_STATE_ERR",{value:11,enumerable:!0}),Object.defineProperty(n,"SYNTAX_ERR",{value:12,enumerable:!0}),Object.defineProperty(n.prototype,"SYNTAX_ERR",{value:12,enumerable:!0}),Object.defineProperty(n,"INVALID_MODIFICATION_ERR",{value:13,enumerable:!0}),Object.defineProperty(n.prototype,"INVALID_MODIFICATION_ERR",{value:13,enumerable:!0}),Object.defineProperty(n,"NAMESPACE_ERR",{value:14,enumerable:!0}),Object.defineProperty(n.prototype,"NAMESPACE_ERR",{value:14,enumerable:!0}),Object.defineProperty(n,"INVALID_ACCESS_ERR",{value:15,enumerable:!0}),Object.defineProperty(n.prototype,"INVALID_ACCESS_ERR",{value:15,enumerable:!0}),Object.defineProperty(n,"VALIDATION_ERR",{value:16,enumerable:!0}),Object.defineProperty(n.prototype,"VALIDATION_ERR",{value:16,enumerable:!0}),Object.defineProperty(n,"TYPE_MISMATCH_ERR",{value:17,enumerable:!0}),Object.defineProperty(n.prototype,"TYPE_MISMATCH_ERR",{value:17,enumerable:!0}),Object.defineProperty(n,"SECURITY_ERR",{value:18,enumerable:!0}),Object.defineProperty(n.prototype,"SECURITY_ERR",{value:18,enumerable:!0}),Object.defineProperty(n,"NETWORK_ERR",{value:19,enumerable:!0}),Object.defineProperty(n.prototype,"NETWORK_ERR",{value:19,enumerable:!0}),Object.defineProperty(n,"ABORT_ERR",{value:20,enumerable:!0}),Object.defineProperty(n.prototype,"ABORT_ERR",{value:20,enumerable:!0}),Object.defineProperty(n,"URL_MISMATCH_ERR",{value:21,enumerable:!0}),Object.defineProperty(n.prototype,"URL_MISMATCH_ERR",{value:21,enumerable:!0}),Object.defineProperty(n,"QUOTA_EXCEEDED_ERR",{value:22,enumerable:!0}),Object.defineProperty(n.prototype,"QUOTA_EXCEEDED_ERR",{value:22,enumerable:!0}),Object.defineProperty(n,"TIMEOUT_ERR",{value:23,enumerable:!0}),Object.defineProperty(n.prototype,"TIMEOUT_ERR",{value:23,enumerable:!0}),Object.defineProperty(n,"INVALID_NODE_TYPE_ERR",{value:24,enumerable:!0}),Object.defineProperty(n.prototype,"INVALID_NODE_TYPE_ERR",{value:24,enumerable:!0}),Object.defineProperty(n,"DATA_CLONE_ERR",{value:25,enumerable:!0}),Object.defineProperty(n.prototype,"DATA_CLONE_ERR",{value:25,enumerable:!0}),Object.defineProperty(n.prototype,Symbol.toStringTag,{value:"DOMException",writable:!1,enumerable:!1,configurable:!0});const u={mixedInto:[],is(t){if(t){if(t[r]instanceof i)return!0;for(let r=0;r<e.exports.mixedInto.length;++r)if(t instanceof e.exports.mixedInto[r])return!0}return!1},isImpl(r){if(r){if(r instanceof i)return!0;const t=o.wrapperForImpl(r);for(let r=0;r<e.exports.mixedInto.length;++r)if(t instanceof e.exports.mixedInto[r])return!0}return!1},convert(r,{context:t="The provided value"}={}){if(e.exports.is(r))return o.implForWrapper(r);throw new TypeError(`${t} is not of type 'DOMException'.`)},create(e,r){let t=Object.create(n.prototype);return this.setup(t,e,r),t},createImpl(e,r){let t=Object.create(n.prototype);return this.setup(t,e,r),o.implForWrapper(t)},_internalSetup(e){},setup(e,t,n){n||(n={}),n.wrapper=e,this._internalSetup(e),Object.defineProperty(e,r,{value:new i(t,n),writable:!1,enumerable:!1,configurable:!0}),e[r][o.wrapperSymbol]=e,a&&a(e[r])},interface:n,expose:{Window:{DOMException:n},Worker:{DOMException:n}}};e.exports=u}),p=e(function(e){e.exports=u.interface,Object.setPrototypeOf(e.exports.prototype,Error.prototype)});exports.polyfill=function(){try{new DOMException}catch(e){self.DOMException=p,self.DOMException.polyfill=!0}};
//# sourceMappingURL=domException.js.map