2 lines
45 KiB
JavaScript
Raw Normal View History

2025-09-05 14:59:21 +08:00
const t="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0;if(!t)throw new Error("WebAssembly is not supported in this environment");function e(t,e){if(null===t||"object"!=typeof t)throw new TypeError(`${e} must be an object. Received ${null===t?"null":typeof t}`)}function n(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function r(t,e){if("function"!=typeof t)throw new TypeError(`${e} must be a function. Received ${null===t?"null":typeof t}`)}function i(t,e){if(void 0!==t)throw new TypeError(`${e} must be undefined. Received ${null===t?"null":typeof t}`)}function s(t){return!(!t||"object"!=typeof t&&"function"!=typeof t||"function"!=typeof t.then)}function o(t,e){const n=Object.create(null);return Object.keys(t).forEach((r=>{const i=t[r];Object.defineProperty(n,r,{enumerable:!0,value:e(i,r)})})),n}function a(t,e,n){return"function"==typeof SharedArrayBuffer&&t.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(t.buffer.constructor)?t.slice(e,n):t.subarray(e,n)}const c=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function u(t,e,n,r){if("function"!=typeof t.exports[r]||n<=0)return{wasm64:e,dataPtr:16,start:e?32:24,end:1024};const i=t.exports[r],s=e?Number(i(BigInt(16)+BigInt(n))):i(8+n);if(0===s)throw new Error("Allocate asyncify data failed");return e?{wasm64:e,dataPtr:s,start:s+16,end:s+16+n}:{wasm64:e,dataPtr:s,start:s+8,end:s+8+n}}class f{constructor(){this.value=void 0,this.exports=void 0,this.dataPtr=0}init(e,n,r){var i,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(e instanceof t.Memory))throw new TypeError("Require WebAssembly.Memory object");const o=n.exports;for(let t=0;t<c.length;++t)if("function"!=typeof o[c[t]])throw new TypeError("Invalid asyncify wasm");let a;const f=Boolean(r.wasm64);a=r.tryAllocate?!0===r.tryAllocate?u(n,f,4096,"malloc"):u(n,f,null!==(i=r.tryAllocate.size)&&void 0!==i?i:4096,null!==(s=r.tryAllocate.name)&&void 0!==s?s:"malloc"):{wasm64:f,dataPtr:16,start:f?32:24,end:1024},this.dataPtr=a.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(e.buffer,this.dataPtr).set([a.start,a.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(t.Instance.prototype);return Object.defineProperty(h,"exports",{value:this.exports}),h}assertState(){if(0!==this.exports.asyncify_get_state())throw new Error("Asyncify state error")}wrapImportFunction(t){const e=this;return function(){for(;2===e.exports.asyncify_get_state();)return e.exports.asyncify_stop_rewind(),e.value;e.assertState();const n=t.apply(this,arguments);if(!s(n))return n;e.exports.asyncify_start_unwind(e.dataPtr),e.value=n}}wrapImports(t){const e={};return Object.keys(t).forEach((n=>{const r=t[n],i={};Object.keys(r).forEach((t=>{const e=r[t];i[t]="function"==typeof e?this.wrapImportFunction(e):e})),e[n]=i})),e}wrapExportFunction(t){const e=this;return async function(){e.assertState();let n=t.apply(this,arguments);for(;1===e.exports.asyncify_get_state();)e.exports.asyncify_stop_unwind(),e.value=await e.value,e.assertState(),e.exports.asyncify_start_rewind(e.dataPtr),n=t.call(this);return e.assertState(),n}}wrapExports(t,e){return o(t,((t,n)=>{let r=-1!==c.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function h(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function g(e,n){return"undefined"!=typeof wx&&"undefined"!=typeof __wxConfig?t.instantiate(e,n):fetch(e).then((t=>t.arrayBuffer())).then((e=>t.instantiate(e,n)))}function d(e,n){let r;if(h(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);if(e instanceof t.Module)return t.instantiate(e,n).then((t=>({instance:t,module:e})));if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typ