@building-block/idl-domexception
Version:
DOMException polyfill
3 lines (2 loc) • 12 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.idlDomexception={})}(this,function(e){"use strict";function r(e,r){return e(r={exports:{}},r.exports),r.exports}var t,o=r(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}),n=r(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}}),i=(t={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}})&&t.default||t,a=class{constructor([e,r]){this.name=r,this.message=e}get code(){return i[this.name]||0}},u=e=>{if(Error.captureStackTrace){const r=n.wrapperForImpl(e);Error.captureStackTrace(r,r.constructor)}},p=r(function(e){const r=n.implSymbol;function t(){const e=[];for(let r=0;r<arguments.length&&r<2;++r)e[r]=arguments[r];e[0]=void 0!==e[0]?o.DOMString(e[0],{context:"Failed to construct 'DOMException': parameter 1"}):"",e[1]=void 0!==e[1]?o.DOMString(e[1],{context:"Failed to construct 'DOMException': parameter 2"}):"Error",i.setup(this,e)}Object.defineProperty(t,"prototype",{value:t.prototype,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(t.prototype,"name",{get(){return this[r].name},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"message",{get(){return this[r].message},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"code",{get(){return this[r].code},enumerable:!0,configurable:!0}),Object.defineProperty(t,"INDEX_SIZE_ERR",{value:1,enumerable:!0}),Object.defineProperty(t.prototype,"INDEX_SIZE_ERR",{value:1,enumerable:!0}),Object.defineProperty(t,"DOMSTRING_SIZE_ERR",{value:2,enumerable:!0}),Object.defineProperty(t.prototype,"DOMSTRING_SIZE_ERR",{value:2,enumerable:!0}),Object.defineProperty(t,"HIERARCHY_REQUEST_ERR",{value:3,enumerable:!0}),Object.defineProperty(t.prototype,"HIERARCHY_REQUEST_ERR",{value:3,enumerable:!0}),Object.defineProperty(t,"WRONG_DOCUMENT_ERR",{value:4,enumerable:!0}),Object.defineProperty(t.prototype,"WRONG_DOCUMENT_ERR",{value:4,enumerable:!0}),Object.defineProperty(t,"INVALID_CHARACTER_ERR",{value:5,enumerable:!0}),Object.defineProperty(t.prototype,"INVALID_CHARACTER_ERR",{value:5,enumerable:!0}),Object.defineProperty(t,"NO_DATA_ALLOWED_ERR",{value:6,enumerable:!0}),Object.defineProperty(t.prototype,"NO_DATA_ALLOWED_ERR",{value:6,enumerable:!0}),Object.defineProperty(t,"NO_MODIFICATION_ALLOWED_ERR",{value:7,enumerable:!0}),Object.defineProperty(t.prototype,"NO_MODIFICATION_ALLOWED_ERR",{value:7,enumerable:!0}),Object.defineProperty(t,"NOT_FOUND_ERR",{value:8,enumerable:!0}),Object.defineProperty(t.prototype,"NOT_FOUND_ERR",{value:8,enumerable:!0}),Object.defineProperty(t,"NOT_SUPPORTED_ERR",{value:9,enumerable:!0}),Object.defineProperty(t.prototype,"NOT_SUPPORTED_ERR",{value:9,enumerable:!0}),Object.defineProperty(t,"INUSE_ATTRIBUTE_ERR",{value:10,enumerable:!0}),Object.defineProperty(t.prototype,"INUSE_ATTRIBUTE_ERR",{value:10,enumerable:!0}),Object.defineProperty(t,"INVALID_STATE_ERR",{value:11,enumerable:!0}),Object.defineProperty(t.prototype,"INVALID_STATE_ERR",{value:11,enumerable:!0}),Object.defineProperty(t,"SYNTAX_ERR",{value:12,enumerable:!0}),Object.defineProperty(t.prototype,"SYNTAX_ERR",{value:12,enumerable:!0}),Object.defineProperty(t,"INVALID_MODIFICATION_ERR",{value:13,enumerable:!0}),Object.defineProperty(t.prototype,"INVALID_MODIFICATION_ERR",{value:13,enumerable:!0}),Object.defineProperty(t,"NAMESPACE_ERR",{value:14,enumerable:!0}),Object.defineProperty(t.prototype,"NAMESPACE_ERR",{value:14,enumerable:!0}),Object.defineProperty(t,"INVALID_ACCESS_ERR",{value:15,enumerable:!0}),Object.defineProperty(t.prototype,"INVALID_ACCESS_ERR",{value:15,enumerable:!0}),Object.defineProperty(t,"VALIDATION_ERR",{value:16,enumerable:!0}),Object.defineProperty(t.prototype,"VALIDATION_ERR",{value:16,enumerable:!0}),Object.defineProperty(t,"TYPE_MISMATCH_ERR",{value:17,enumerable:!0}),Object.defineProperty(t.prototype,"TYPE_MISMATCH_ERR",{value:17,enumerable:!0}),Object.defineProperty(t,"SECURITY_ERR",{value:18,enumerable:!0}),Object.defineProperty(t.prototype,"SECURITY_ERR",{value:18,enumerable:!0}),Object.defineProperty(t,"NETWORK_ERR",{value:19,enumerable:!0}),Object.defineProperty(t.prototype,"NETWORK_ERR",{value:19,enumerable:!0}),Object.defineProperty(t,"ABORT_ERR",{value:20,enumerable:!0}),Object.defineProperty(t.prototype,"ABORT_ERR",{value:20,enumerable:!0}),Object.defineProperty(t,"URL_MISMATCH_ERR",{value:21,enumerable:!0}),Object.defineProperty(t.prototype,"URL_MISMATCH_ERR",{value:21,enumerable:!0}),Object.defineProperty(t,"QUOTA_EXCEEDED_ERR",{value:22,enumerable:!0}),Object.defineProperty(t.prototype,"QUOTA_EXCEEDED_ERR",{value:22,enumerable:!0}),Object.defineProperty(t,"TIMEOUT_ERR",{value:23,enumerable:!0}),Object.defineProperty(t.prototype,"TIMEOUT_ERR",{value:23,enumerable:!0}),Object.defineProperty(t,"INVALID_NODE_TYPE_ERR",{value:24,enumerable:!0}),Object.defineProperty(t.prototype,"INVALID_NODE_TYPE_ERR",{value:24,enumerable:!0}),Object.defineProperty(t,"DATA_CLONE_ERR",{value:25,enumerable:!0}),Object.defineProperty(t.prototype,"DATA_CLONE_ERR",{value:25,enumerable:!0}),Object.defineProperty(t.prototype,Symbol.toStringTag,{value:"DOMException",writable:!1,enumerable:!1,configurable:!0});const i={mixedInto:[],is(t){if(t){if(t[r]instanceof a)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 a)return!0;const t=n.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 n.implForWrapper(r);throw new TypeError(`${t} is not of type 'DOMException'.`)},create(e,r){let o=Object.create(t.prototype);return this.setup(o,e,r),o},createImpl(e,r){let o=Object.create(t.prototype);return this.setup(o,e,r),n.implForWrapper(o)},_internalSetup(e){},setup(e,t,o){o||(o={}),o.wrapper=e,this._internalSetup(e),Object.defineProperty(e,r,{value:new a(t,o),writable:!1,enumerable:!1,configurable:!0}),e[r][n.wrapperSymbol]=e,u&&u(e[r])},interface:t,expose:{Window:{DOMException:t},Worker:{DOMException:t}}};e.exports=i}),l=r(function(e){e.exports=p.interface,Object.setPrototypeOf(e.exports.prototype,Error.prototype)});e.polyfill=function(){try{new DOMException}catch(e){self.DOMException=l,self.DOMException.polyfill=!0}}});
//# sourceMappingURL=domException.umd.js.map