@tybys/wasm-util 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -370,7 +370,7 @@ export declare class WASI {
370
370
  readonly wasiImport: Record<string, any>;
371
371
  static createSync(options?: SyncWASIOptions): WASI;
372
372
  static createAsync(options?: AsyncWASIOptions): Promise<WASI>;
373
- private constructor();
373
+ constructor(options?: SyncWASIOptions);
374
374
  start(instance: WebAssembly.Instance): number | undefined | Promise<number> | Promise<undefined>;
375
375
  initialize(instance: WebAssembly.Instance): void | Promise<void>;
376
376
  }
@@ -967,7 +967,7 @@ function checkWebAssemblyFunction() {
967
967
  if (typeof WebAssemblyFunction !== 'function') {
968
968
  throw new Error('WebAssembly.Function is not supported in this environment.' +
969
969
  ' If you are using V8 based browser like Chrome, try to specify' +
970
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
970
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
971
971
  }
972
972
  return WebAssemblyFunction;
973
973
  }
@@ -2544,25 +2544,27 @@ function validateOptions(options) {
2544
2544
  stdio
2545
2545
  };
2546
2546
  }
2547
+ function initWASI(setMemory, wrap) {
2548
+ this[kSetMemory] = setMemory;
2549
+ this.wasiImport = wrap;
2550
+ this[kStarted] = false;
2551
+ this[kExitCode] = 0;
2552
+ this[kInstance] = undefined;
2553
+ }
2547
2554
  /** @public */
2548
2555
  class WASI {
2549
- constructor(setMemory, wrap) {
2550
- this[kSetMemory] = setMemory;
2551
- this.wasiImport = wrap;
2552
- this[kStarted] = false;
2553
- this[kExitCode] = 0;
2554
- this[kInstance] = undefined;
2555
- }
2556
- static createSync(options = kEmptyObject) {
2556
+ constructor(options = kEmptyObject) {
2557
2557
  const { args, env, preopens, stdio } = validateOptions(options);
2558
2558
  const wrap = WASI$1.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
2559
2559
  const setMemory = wrap._setMemory;
2560
2560
  delete wrap._setMemory;
2561
- const _this = new WASI(setMemory, wrap);
2561
+ initWASI.call(this, setMemory, wrap);
2562
2562
  if (options.returnOnExit) {
2563
- wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2563
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
2564
2564
  }
2565
- return _this;
2565
+ }
2566
+ static createSync(options = kEmptyObject) {
2567
+ return new WASI(options);
2566
2568
  }
2567
2569
  static async createAsync(options = kEmptyObject) {
2568
2570
  const { args, env, preopens, stdio } = validateOptions(options);
@@ -2573,7 +2575,8 @@ class WASI {
2573
2575
  const wrap = await WASI$1.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
2574
2576
  const setMemory = wrap._setMemory;
2575
2577
  delete wrap._setMemory;
2576
- const _this = new WASI(setMemory, wrap);
2578
+ const _this = Object.create(WASI.prototype);
2579
+ initWASI.call(_this, setMemory, wrap);
2577
2580
  if (options.returnOnExit) {
2578
2581
  wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2579
2582
  }
@@ -967,7 +967,7 @@ function checkWebAssemblyFunction() {
967
967
  if (typeof WebAssemblyFunction !== 'function') {
968
968
  throw new Error('WebAssembly.Function is not supported in this environment.' +
969
969
  ' If you are using V8 based browser like Chrome, try to specify' +
970
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
970
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
971
971
  }
972
972
  return WebAssemblyFunction;
973
973
  }
@@ -2544,25 +2544,27 @@ function validateOptions(options) {
2544
2544
  stdio
2545
2545
  };
2546
2546
  }
2547
+ function initWASI(setMemory, wrap) {
2548
+ this[kSetMemory] = setMemory;
2549
+ this.wasiImport = wrap;
2550
+ this[kStarted] = false;
2551
+ this[kExitCode] = 0;
2552
+ this[kInstance] = undefined;
2553
+ }
2547
2554
  /** @public */
2548
2555
  class WASI {
2549
- constructor(setMemory, wrap) {
2550
- this[kSetMemory] = setMemory;
2551
- this.wasiImport = wrap;
2552
- this[kStarted] = false;
2553
- this[kExitCode] = 0;
2554
- this[kInstance] = undefined;
2555
- }
2556
- static createSync(options = kEmptyObject) {
2556
+ constructor(options = kEmptyObject) {
2557
2557
  const { args, env, preopens, stdio } = validateOptions(options);
2558
2558
  const wrap = WASI$1.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
2559
2559
  const setMemory = wrap._setMemory;
2560
2560
  delete wrap._setMemory;
2561
- const _this = new WASI(setMemory, wrap);
2561
+ initWASI.call(this, setMemory, wrap);
2562
2562
  if (options.returnOnExit) {
2563
- wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2563
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
2564
2564
  }
2565
- return _this;
2565
+ }
2566
+ static createSync(options = kEmptyObject) {
2567
+ return new WASI(options);
2566
2568
  }
2567
2569
  static async createAsync(options = kEmptyObject) {
2568
2570
  const { args, env, preopens, stdio } = validateOptions(options);
@@ -2573,7 +2575,8 @@ class WASI {
2573
2575
  const wrap = await WASI$1.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
2574
2576
  const setMemory = wrap._setMemory;
2575
2577
  delete wrap._setMemory;
2576
- const _this = new WASI(setMemory, wrap);
2578
+ const _this = Object.create(WASI.prototype);
2579
+ initWASI.call(_this, setMemory, wrap);
2577
2580
  if (options.returnOnExit) {
2578
2581
  wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2579
2582
  }
@@ -1 +1 @@
1
- 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}const a=["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 c{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<a.length;++t)if("function"!=typeof o[a[t]])throw new TypeError("Invalid asyncify wasm");let c;const f=Boolean(r.wasm64);c=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=c.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(c.start),BigInt(c.end)]):new Int32Array(e.buffer,this.dataPtr).set([c.start,c.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!==a.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function f(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function h(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 g(e,n){let r;if(f(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typeof t.instantiateStreaming){let i;try{i=fetch(e),r=t.instantiateStreaming(i,n).catch((()=>h(e,n)))}catch(t){r=h(e,n)}}else r=h(e,n);return r}function d(t,e,n){f(n),n=null!=n?n:{};const r=new c;return g(e,n=r.wrapImports(n)).then((e=>{var i;const s=e.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:e.module,instance:r.init(s,e.instance,t)}}))}function l(e,n){if(e instanceof ArrayBuffer&&!ArrayBuffer.isView(e))throw new TypeError("Invalid source");f(n),n=null!=n?n:{};const r=new t.Module(e);return{instance:new t.Instance(r,n),module:r}}function _(t,e,n){var r;f(n),n=null!=n?n:{};const i=new c,s=l(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}}const E=46,y=47;function p(t){return t===y}function I(...t){let e="",r=!1;for(let i=t.length-1;i>=-1&&!r;i--){const s=i>=0?t[i]:"/";n(s,"path"),0!==s.length&&(e=`${s}/${e}`,r=s.charCodeAt(0)===y)}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,u=0;for(let c=0;c<=t.length;++c){if(c<t.length)u=t.charCodeAt(c);else{if(r(u))break;u=y}if(r(u)){if(o===c-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==E||i.charCodeAt(i.length-2)!==E){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=c,a=0;continue}if(0!==i.length){i="",s=0,o=c,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,c)}`:i=t.slice(o+1,c),s=c-o-1;o=c,a=0}else u===E&&-1!==a?++a:a=-1}return i}(e,!r,"/",p),r?`/${e}`:e.length>0?e:"."}const b={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class m extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(m.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const A=b.FD_DATASYNC|b.FD_READ|b.FD_SEEK|b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_TELL|b.FD_WRITE|b.FD_ADVISE|b.FD_ALLOCATE|b.PATH_CREATE_DIRECTORY|b.PATH_CREATE_FILE|b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET|b.PATH_OPEN|b.FD_READDIR|b.PATH_READLINK|b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET|b.PATH_FILESTAT_GET|b.PATH_FILESTAT_SET_SIZE|b.PATH_FILESTAT_SET_TIMES|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_TIMES|b.FD_FILESTAT_SET_SIZE|b.PATH_SYMLINK|b.PATH_UNLINK_FILE|b.PATH_REMOVE_DIRECTORY|b.POLL_FD_READWRITE|b.SOCK_SHUTDOWN,T=A,w=A,N=A,B=A,S=b.FD_DATASYNC|b.FD_READ|b.FD_SEEK|b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_TELL|b.FD_WRITE|b.FD_ADVISE|b.FD_ALLOCATE|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_SIZE|b.FD_FILESTAT_SET_TIMES|b.POLL_FD_READWRITE,D=BigInt(0),P=b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_ADVISE|b.PATH_CREATE_DIRECTORY|b.PATH_CREATE_FILE|b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET|b.PATH_OPEN|b.FD_READDIR|b.PATH_READLINK|b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET|b.PATH_FILESTAT_GET|b.PATH_FILESTAT_SET_SIZE|b.PATH_FILESTAT_SET_TIMES|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_TIMES|b.PATH_SYMLINK|b.PATH_UNLINK_FILE|b.PATH_REMOVE_DIRECTORY|b.POLL_FD_READWRITE,F=P|S,R=b.FD_READ|b.FD_FDSTAT_SET_FLAGS|b.FD_WRITE|b.FD_FILESTAT_GET|b.POLL_FD_READWRITE|b.SOCK_SHUTDOWN,U=A,v=b.FD_READ|b.FD_FDSTAT_SET_FLAGS|b.FD_WRITE|b.FD_FILESTAT_GET|b.POLL_FD_READWRITE,L=BigInt(0);function H(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new m("Unknown file type",28);switch(r){case 4:i.base=S,i.inheriting=D;break;case 3:i.base=P,i.inheriting=F;break;case 6:case 5:i.base=R,i.inheriting=U;break;case 2:-1!==t.indexOf(e)?(i.base=v,i.inheriting=L):(i.base=N,i.inheriting=B);break;case 1:i.base=T,i.inheriting=w;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~b.FD_WRITE:1===s&&(i.base&=~b.FD_READ),i}function O(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class k{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new m("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class C extends k{constructor(t,e,n,r,i,s,o,a,u){super(e,n,r,i,s,o,a,u),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=O([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function x(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function M(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(x(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class K{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=H(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new m(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,u;let c,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return c="<stdout>"===e?new C(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new C(null!==(u=this.printErr)&&void 0!==u?u:console.error,f,t,e,n,r,i,s,o):new k(f,t,e,n,r,i,s,o),this.fds[f]=c,this.used++,c}get(t,e,n){if(t>=this.size)throw new m("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new m("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new m("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new m("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new m("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class z extends K{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return x(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new m(`Preopen not dir: ["${e}", "${n}"]`,54);const i=H(this.stdio,t,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new m("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new m("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class W extends K{constructor(t){super(t)}async getFileTypeByFd(t){return x(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new m(`Preopen not dir: ["${e}", "${n}"]`,54);const i=H(this.stdio,t.fd,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new m("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new m("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const G=function(){return t.Memory}();class Y extends G{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function j(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,Y.prototype),e}function $(){const e=t.Function;if("function"!=typeof e)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flag="--wasm-staging --experimental-wasm-stack-switching"');return e}function V(t,e,n){const r=$();if("function"!=typeof t)throw new TypeError("Function required");const i=e.slice(0);return i.unshift("externref"),new r({parameters:i,results:n},t,{suspending:"first"})}function Z(t){const e=$();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function q(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:Z(t)}))}function X(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const Q=new WeakMap,J=new WeakMap,tt=new WeakMap;function et(t){return Q.get(t)}function nt(t){const e=tt.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function rt(t){if(t instanceof m)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function it(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return rt(t)}return s(e)?e.then((t=>t),rt):e}))}function st(t,e,n,r){let i=I(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function ot(t,e,n,r){let i=I(e.realPath,n);if(1==(1&r))try{i=await t.promises.readlink(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}const at=new TextEncoder,ut=new TextDecoder;function ct(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ft{constructor(e,n,r,i,s,o){this.args_get=it(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=et(this),i=J.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=at.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=it(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=et(this),r=J.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,at.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=it(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=et(this),i=J.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=at.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=it(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=et(this),r=J.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,at.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=it(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=et(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=it(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=et(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=it(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=it(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=et(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=it(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=it(this,"fd_fdstat_set_rights",(function(t,e,n){const r=J.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=it(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof m)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=et(this);return i.setUint32(e,0,!0),i.setUint32(e+4,at.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=it(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=J.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=at.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=et(this);return s.set(i,e),0})),this.fd_seek=it(this,"fd_seek",(function(t,e,n,r){if(0===(r=Number(r)))return 28;if(0===t||1===t||2===t)return 0;const i=J.get(this).fds.get(t,b.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=et(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=it(this,"fd_tell",(function(t,e){const n=J.get(this).fds.get(t,b.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=et(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=it(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=et(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),u=BigInt(0),c=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),u=i.getBigUint64(s+32,!0),c=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:u,flags:c},fd_readwrite:{fd:r}}}}const g=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);u=s.u.clock.timeout-t}else u=s.u.clock.timeout;(0===c||u<f)&&(f=u,a=s.userdata,c=1);break;case 1:case 2:g.push(s);break;default:return 28}if(g.length>0){for(o=0;o<g.length;o++){const t=g[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,g.length,!0),0}if(c){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=it(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=it(this,"proc_raise",(function(t){return 52})),this.sched_yield=it(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?it(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=et(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):it(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=et(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=it(this,"sock_recv",(function(){return 58})),this.sock_send=it(this,"sock_send",(function(){return 58})),this.sock_shutdown=it(this,"sock_shutdown",(function(){return 58})),J.set(this,{fds:r,args:e,env:n}),s&&tt.set(this,s);const a=this;function u(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(it(a,t,n)):V(it(a,t,n),r,s):it(a,t,e)}function c(t,e,n,r){const i=J.get(this).fds.get(t,b.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(b.FD_READ|b.FD_READDIR))!==BigInt(0),s=(e&(b.FD_DATASYNC|b.FD_WRITE|b.FD_ALLOCATE|b.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=b.PATH_OPEN,u=e|n;return 0!=(1&t)&&(o|=64,a|=b.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=b.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(u|=b.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,u|=b.FD_SYNC),0!=(16&r)&&(o|=1052672,u|=b.FD_SYNC),s&&0==(1536&o)&&(u|=b.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:u}}u("fd_allocate",(function(t,e,n){const r=J.get(this),i=nt(this),s=r.fds.get(t,b.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=J.get(this).fds.get(t,b.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),u("fd_close",(function(t){const e=J.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return nt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=J.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),u("fd_datasync",(function(t){const e=J.get(this).fds.get(t,b.FD_DATASYNC,BigInt(0));return nt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=J.get(this).fds.get(t,b.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),u("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,b.FD_FILESTAT_GET,BigInt(0)),r=nt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=et(this);return M(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,b.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=et(this);return M(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=J.get(this).fds.get(t,b.FD_FILESTAT_SET_SIZE,BigInt(0));return nt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=J.get(this).fds.get(t,b.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),u("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r);return nt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),u("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_READ|b.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const g=nt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?X(c,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_READ|b.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const{bytesRead:g}=await a.fd.read(h,0,h.length,Number(r));return f=h?X(c,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_pwrite",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_WRITE|b.FD_SEEK,BigInt(0)),u=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),c=nt(this).writeSync(a.fd,u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_WRITE|b.FD_SEEK,BigInt(0)),u=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:c}=await a.fd.write(u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=ct(),f=c?X(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const t=nt(this).readSync(o.fd,c,0,c.length,Number(o.pos));f=c?X(u,c.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=ct(),f=c?X(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const{bytesRead:t}=await o.fd.read(c,0,c.length,Number(o.pos));f=c?X(u,c.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),u("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=J.get(this).fds.get(t,b.FD_READDIR,BigInt(0)),o=nt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=et(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=at.encode(a[t].name),i=o.statSync(I(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),c.set(r,24);const d=c.slice(0,Math.min(c.length,n-f));u.set(d,e+f),f+=d.byteLength}return c.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=J.get(this).fds.get(t,b.FD_READDIR,BigInt(0)),o=nt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=et(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=at.encode(a[t].name),i=await o.promises.stat(I(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),c.set(r,24);const d=c.slice(0,Math.min(c.length,n-f));u.set(d,e+f),f+=d.byteLength}return c.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return J.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=J.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=J.get(this).fds.get(t,b.FD_SYNC,BigInt(0));return nt(this).fsyncSync(e.fd),0}),(async function(t){const e=J.get(this).fds.get(t,b.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),u("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_WRITE,BigInt(0)),a=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let u;if(1===t||2===t)u=o.write(a);else{u=nt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(u)}return s.setUint32(r,u,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_WRITE,BigInt(0)),a=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let u;return 1===t||2===t?u=o.write(a):(u=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(u)),s.setUint32(r,u,!0),0}),["i32","i32","i32","i32"],["i32"]),u("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_CREATE_DIRECTORY,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_CREATE_DIRECTORY,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),u("path_filestat_get",(function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.PATH_FILESTAT_GET,BigInt(0));let u=ut.decode(s.subarray(n,n+r));const c=nt(this);let f;return u=I(a.realPath,u),f=1==(1&e)?c.statSync(u,{bigint:!0}):c.lstatSync(u,{bigint:!0}),M(o,i,f),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.PATH_FILESTAT_GET,BigInt(0));let u=ut.decode(s.subarray(n,n+r));const c=nt(this);let f;return u=I(a.realPath,u),f=1==(1&e)?await c.promises.stat(u,{bigint:!0}):await c.promises.lstat(u,{bigint:!0}),M(o,i,f),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=et(this),u=J.get(this).fds.get(t,b.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=nt(this),f=st(c,u,ut.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),c.utimesSync(f,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=et(this),u=J.get(this).fds.get(t,b.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=nt(this),f=await ot(c,u,ut.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await c.promises.utimes(f,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),u("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=J.get(this);let u,c;t===i?u=c=a.fds.get(t,b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,b.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,b.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=et(this),h=nt(this),g=st(h,u,ut.decode(f.subarray(n,n+r)),e),d=I(c.realPath,ut.decode(f.subarray(s,s+o)));return h.linkSync(g,d),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=J.get(this);let u,c;t===i?u=c=a.fds.get(t,b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,b.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,b.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=et(this),h=nt(this),g=await ot(h,u,ut.decode(f.subarray(n,n+r)),e),d=I(c.realPath,ut.decode(f.subarray(s,s+o)));return await h.promises.link(g,d),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,a,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:c,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=J.get(this),l=d.fds.get(t,h,g),_=et(this),E=_.HEAPU8,y=ut.decode(E.subarray(n,n+r)),p=nt(this),I=st(p,l,y,e),b=p.openSync(I,c,438),m=d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=H(d.fds.stdio,b,c,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:c,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=J.get(this),l=d.fds.get(t,h,g),_=et(this),E=_.HEAPU8,y=ut.decode(E.subarray(n,n+r)),p=nt(this),I=await ot(p,l,y,e),b=await p.promises.open(I,c,438),m=await d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=H(d.fds.stdio,b.fd,c,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),u("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=et(this),u=J.get(this).fds.get(t,b.PATH_READLINK,BigInt(0));let c=ut.decode(o.subarray(e,e+n));c=I(u.realPath,c);const f=nt(this).readlinkSync(c),h=at.encode(f),g=Math.min(h.length,i);return g>=i?42:(o.set(h.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=et(this),u=J.get(this).fds.get(t,b.PATH_READLINK,BigInt(0));let c=ut.decode(o.subarray(e,e+n));c=I(u.realPath,c);const f=nt(this),h=await f.promises.readlink(c),g=at.encode(h),d=Math.min(g.length,i);return d>=i?42:(o.set(g.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),u("path_rename",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=J.get(this);let a,u;t===r?a=u=o.fds.get(t,b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,b.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,b.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=et(this),f=I(a.realPath,ut.decode(c.subarray(e,e+n))),h=I(u.realPath,ut.decode(c.subarray(i,i+s)));return nt(this).renameSync(f,h),0}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=J.get(this);let a,u;t===r?a=u=o.fds.get(t,b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,b.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,b.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=et(this),f=I(a.realPath,ut.decode(c.subarray(e,e+n))),h=I(u.realPath,ut.decode(c.subarray(i,i+s))),g=nt(this);return await g.promises.rename(f,h),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_symlink",(function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=et(this),o=J.get(this).fds.get(n,b.PATH_SYMLINK,BigInt(0)),a=ut.decode(s.subarray(t,t+e));let u=ut.decode(s.subarray(r,r+i));u=I(o.realPath,u);return nt(this).symlinkSync(a,u),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=et(this),o=J.get(this).fds.get(n,b.PATH_SYMLINK,BigInt(0)),a=ut.decode(s.subarray(t,t+e));let u=ut.decode(s.subarray(r,r+i));u=I(o.realPath,u);const c=nt(this);return await c.promises.symlink(a,u),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_UNLINK_FILE,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_UNLINK_FILE,BigInt(0));let s=ut.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(e){if(!(e instanceof t.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');Q.set(a,j(e))}}static createSync(t,e,n,r,i,s,o){const a=new z({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),u=new ft(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return u}static async createAsync(t,e,n,r,i,s,o,a){const u=new W({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),c=new ft(t,e,u,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await u.insertPreopen(s,e.mappedPath,r)}return c}}const ht=Object.freeze(Object.create(null)),gt=Symbol("kExitCode"),dt=Symbol("kSetMemory"),lt=Symbol("kStarted"),_t=Symbol("kInstance");function Et(t,n){e(n,"instance"),e(n.exports,"instance.exports"),t[_t]=n,t[dt](n.exports.memory)}function yt(t){var n;e(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const i=(null!==(n=t.args)&&void 0!==n?n:[]).map(String),s=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{e(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&r(t.print,"options.print"),void 0!==t.printErr&&r(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:i,env:s,preopens:o,stdio:[0,1,2]}}class pt{constructor(t,e){this[dt]=t,this.wasiImport=e,this[lt]=!1,this[gt]=0,this[_t]=void 0}static createSync(t=ht){const{args:e,env:n,preopens:r,stdio:i}=yt(t),s=ft.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new pt(o,s);return t.returnOnExit&&(s.proc_exit=It.bind(a)),a}static async createAsync(t=ht){const{args:n,env:i,preopens:s,stdio:o}=yt(t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ft.createAsync(n,i,s,o,t.fs,t.print,t.printErr,t.asyncify),u=a._setMemory;delete a._setMemory;const c=new pt(u,a);return t.returnOnExit&&(a.proc_exit=It.bind(c)),c}start(t){if(this[lt])throw new Error("WASI instance has already started");this[lt]=!0,Et(this,t);const{_start:e,_initialize:n}=this[_t].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==gt)throw t}return s instanceof Promise?s.then((()=>this[gt]),(t=>{if(t!==gt)throw t;return this[gt]})):this[gt]}initialize(t){if(this[lt])throw new Error("WASI instance has already started");this[lt]=!0,Et(this,t);const{_start:e,_initialize:n}=this[_t].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}}function It(t){throw this[gt]=t,gt}export{c as Asyncify,Y as Memory,pt as WASI,G as WebAssemblyMemory,d as asyncifyLoad,_ as asyncifyLoadSync,j as extendMemory,g as load,l as loadSync,Z as wrapAsyncExport,V as wrapAsyncImport,q as wrapExports};
1
+ 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}const a=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function c(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 u{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<a.length;++t)if("function"!=typeof o[a[t]])throw new TypeError("Invalid asyncify wasm");let u;const f=Boolean(r.wasm64);u=r.tryAllocate?!0===r.tryAllocate?c(n,f,4096,"malloc"):c(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=u.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(u.start),BigInt(u.end)]):new Int32Array(e.buffer,this.dataPtr).set([u.start,u.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!==a.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function f(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function h(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 g(e,n){let r;if(f(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typeof t.instantiateStreaming){let i;try{i=fetch(e),r=t.instantiateStreaming(i,n).catch((()=>h(e,n)))}catch(t){r=h(e,n)}}else r=h(e,n);return r}function d(t,e,n){f(n),n=null!=n?n:{};const r=new u;return g(e,n=r.wrapImports(n)).then((e=>{var i;const s=e.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:e.module,instance:r.init(s,e.instance,t)}}))}function l(e,n){if(e instanceof ArrayBuffer&&!ArrayBuffer.isView(e))throw new TypeError("Invalid source");f(n),n=null!=n?n:{};const r=new t.Module(e);return{instance:new t.Instance(r,n),module:r}}function _(t,e,n){var r;f(n),n=null!=n?n:{};const i=new u,s=l(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}}const E=46,y=47;function p(t){return t===y}function I(...t){let e="",r=!1;for(let i=t.length-1;i>=-1&&!r;i--){const s=i>=0?t[i]:"/";n(s,"path"),0!==s.length&&(e=`${s}/${e}`,r=s.charCodeAt(0)===y)}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u<t.length)c=t.charCodeAt(u);else{if(r(c))break;c=y}if(r(c)){if(o===u-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==E||i.charCodeAt(i.length-2)!==E){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=u,a=0;continue}if(0!==i.length){i="",s=0,o=u,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,u)}`:i=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===E&&-1!==a?++a:a=-1}return i}(e,!r,"/",p),r?`/${e}`:e.length>0?e:"."}const b={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class m extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(m.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const A=b.FD_DATASYNC|b.FD_READ|b.FD_SEEK|b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_TELL|b.FD_WRITE|b.FD_ADVISE|b.FD_ALLOCATE|b.PATH_CREATE_DIRECTORY|b.PATH_CREATE_FILE|b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET|b.PATH_OPEN|b.FD_READDIR|b.PATH_READLINK|b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET|b.PATH_FILESTAT_GET|b.PATH_FILESTAT_SET_SIZE|b.PATH_FILESTAT_SET_TIMES|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_TIMES|b.FD_FILESTAT_SET_SIZE|b.PATH_SYMLINK|b.PATH_UNLINK_FILE|b.PATH_REMOVE_DIRECTORY|b.POLL_FD_READWRITE|b.SOCK_SHUTDOWN,T=A,w=A,N=A,B=A,S=b.FD_DATASYNC|b.FD_READ|b.FD_SEEK|b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_TELL|b.FD_WRITE|b.FD_ADVISE|b.FD_ALLOCATE|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_SIZE|b.FD_FILESTAT_SET_TIMES|b.POLL_FD_READWRITE,D=BigInt(0),P=b.FD_FDSTAT_SET_FLAGS|b.FD_SYNC|b.FD_ADVISE|b.PATH_CREATE_DIRECTORY|b.PATH_CREATE_FILE|b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET|b.PATH_OPEN|b.FD_READDIR|b.PATH_READLINK|b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET|b.PATH_FILESTAT_GET|b.PATH_FILESTAT_SET_SIZE|b.PATH_FILESTAT_SET_TIMES|b.FD_FILESTAT_GET|b.FD_FILESTAT_SET_TIMES|b.PATH_SYMLINK|b.PATH_UNLINK_FILE|b.PATH_REMOVE_DIRECTORY|b.POLL_FD_READWRITE,F=P|S,R=b.FD_READ|b.FD_FDSTAT_SET_FLAGS|b.FD_WRITE|b.FD_FILESTAT_GET|b.POLL_FD_READWRITE|b.SOCK_SHUTDOWN,U=A,v=b.FD_READ|b.FD_FDSTAT_SET_FLAGS|b.FD_WRITE|b.FD_FILESTAT_GET|b.POLL_FD_READWRITE,L=BigInt(0);function H(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new m("Unknown file type",28);switch(r){case 4:i.base=S,i.inheriting=D;break;case 3:i.base=P,i.inheriting=F;break;case 6:case 5:i.base=R,i.inheriting=U;break;case 2:-1!==t.indexOf(e)?(i.base=v,i.inheriting=L):(i.base=N,i.inheriting=B);break;case 1:i.base=T,i.inheriting=w;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~b.FD_WRITE:1===s&&(i.base&=~b.FD_READ),i}function O(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class k{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new m("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class C extends k{constructor(t,e,n,r,i,s,o,a,c){super(e,n,r,i,s,o,a,c),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=O([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function x(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function M(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(x(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class K{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=H(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new m(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return u="<stdout>"===e?new C(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new C(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,r,i,s,o):new k(f,t,e,n,r,i,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new m("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new m("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new m("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new m("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new m("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class z extends K{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return x(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new m(`Preopen not dir: ["${e}", "${n}"]`,54);const i=H(this.stdio,t,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new m("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new m("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class W extends K{constructor(t){super(t)}async getFileTypeByFd(t){return x(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new m(`Preopen not dir: ["${e}", "${n}"]`,54);const i=H(this.stdio,t.fd,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new m("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new m("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const G=function(){return t.Memory}();class Y extends G{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function j(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,Y.prototype),e}function $(){const e=t.Function;if("function"!=typeof e)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flags="--wasm-staging --experimental-wasm-stack-switching"');return e}function V(t,e,n){const r=$();if("function"!=typeof t)throw new TypeError("Function required");const i=e.slice(0);return i.unshift("externref"),new r({parameters:i,results:n},t,{suspending:"first"})}function Z(t){const e=$();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function q(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:Z(t)}))}function X(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const Q=new WeakMap,J=new WeakMap,tt=new WeakMap;function et(t){return Q.get(t)}function nt(t){const e=tt.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function rt(t){if(t instanceof m)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function it(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return rt(t)}return s(e)?e.then((t=>t),rt):e}))}function st(t,e,n,r){let i=I(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function ot(t,e,n,r){let i=I(e.realPath,n);if(1==(1&r))try{i=await t.promises.readlink(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}const at=new TextEncoder,ct=new TextDecoder;function ut(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ft{constructor(e,n,r,i,s,o){this.args_get=it(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=et(this),i=J.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=at.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=it(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=et(this),r=J.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,at.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=it(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=et(this),i=J.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=at.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=it(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=et(this),r=J.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,at.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=it(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=et(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=it(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=et(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=it(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=it(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=et(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=it(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=it(this,"fd_fdstat_set_rights",(function(t,e,n){const r=J.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=it(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof m)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=et(this);return i.setUint32(e,0,!0),i.setUint32(e+4,at.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=it(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=J.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=at.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=et(this);return s.set(i,e),0})),this.fd_seek=it(this,"fd_seek",(function(t,e,n,r){if(0===(r=Number(r)))return 28;if(0===t||1===t||2===t)return 0;const i=J.get(this).fds.get(t,b.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=et(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=it(this,"fd_tell",(function(t,e){const n=J.get(this).fds.get(t,b.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=et(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=it(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=et(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),c=i.getBigUint64(s+32,!0),u=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:c,flags:u},fd_readwrite:{fd:r}}}}const g=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);c=s.u.clock.timeout-t}else c=s.u.clock.timeout;(0===u||c<f)&&(f=c,a=s.userdata,u=1);break;case 1:case 2:g.push(s);break;default:return 28}if(g.length>0){for(o=0;o<g.length;o++){const t=g[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,g.length,!0),0}if(u){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=it(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=it(this,"proc_raise",(function(t){return 52})),this.sched_yield=it(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?it(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=et(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):it(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=et(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=it(this,"sock_recv",(function(){return 58})),this.sock_send=it(this,"sock_send",(function(){return 58})),this.sock_shutdown=it(this,"sock_shutdown",(function(){return 58})),J.set(this,{fds:r,args:e,env:n}),s&&tt.set(this,s);const a=this;function c(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(it(a,t,n)):V(it(a,t,n),r,s):it(a,t,e)}function u(t,e,n,r){const i=J.get(this).fds.get(t,b.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(b.FD_READ|b.FD_READDIR))!==BigInt(0),s=(e&(b.FD_DATASYNC|b.FD_WRITE|b.FD_ALLOCATE|b.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=b.PATH_OPEN,c=e|n;return 0!=(1&t)&&(o|=64,a|=b.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=b.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(c|=b.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,c|=b.FD_SYNC),0!=(16&r)&&(o|=1052672,c|=b.FD_SYNC),s&&0==(1536&o)&&(c|=b.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:c}}c("fd_allocate",(function(t,e,n){const r=J.get(this),i=nt(this),s=r.fds.get(t,b.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=J.get(this).fds.get(t,b.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),c("fd_close",(function(t){const e=J.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return nt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=J.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),c("fd_datasync",(function(t){const e=J.get(this).fds.get(t,b.FD_DATASYNC,BigInt(0));return nt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=J.get(this).fds.get(t,b.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),c("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,b.FD_FILESTAT_GET,BigInt(0)),r=nt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=et(this);return M(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=J.get(this).fds.get(t,b.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=et(this);return M(i,e,r),0}),["i32","i32"],["i32"]),c("fd_filestat_set_size",(function(t,e){const n=J.get(this).fds.get(t,b.FD_FILESTAT_SET_SIZE,BigInt(0));return nt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=J.get(this).fds.get(t,b.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),c("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r);return nt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),c("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_READ|b.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const g=nt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?X(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_READ|b.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:g}=await a.fd.read(h,0,h.length,Number(r));return f=h?X(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_pwrite",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_WRITE|b.FD_SEEK,BigInt(0)),c=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),u=nt(this).writeSync(a.fd,c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.FD_WRITE|b.FD_SEEK,BigInt(0)),c=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=ut(),f=u?X(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const t=nt(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?X(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=ut(),f=u?X(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?X(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),c("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=J.get(this).fds.get(t,b.FD_READDIR,BigInt(0)),o=nt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=et(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=at.encode(a[t].name),i=o.statSync(I(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=J.get(this).fds.get(t,b.FD_READDIR,BigInt(0)),o=nt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=et(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=at.encode(a[t].name),i=await o.promises.stat(I(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_renumber",(function(t,e){return J.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=J.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),c("fd_sync",(function(t){const e=J.get(this).fds.get(t,b.FD_SYNC,BigInt(0));return nt(this).fsyncSync(e.fd),0}),(async function(t){const e=J.get(this).fds.get(t,b.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),c("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_WRITE,BigInt(0)),a=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=nt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(r,c,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=et(this),o=J.get(this).fds.get(t,b.FD_WRITE,BigInt(0)),a=O(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(r,c,!0),0}),["i32","i32","i32","i32"],["i32"]),c("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_CREATE_DIRECTORY,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_CREATE_DIRECTORY,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),c("path_filestat_get",(function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.PATH_FILESTAT_GET,BigInt(0));let c=ct.decode(s.subarray(n,n+r));const u=nt(this);let f;return c=I(a.realPath,c),f=1==(1&e)?u.statSync(c,{bigint:!0}):u.lstatSync(c,{bigint:!0}),M(o,i,f),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=et(this),a=J.get(this).fds.get(t,b.PATH_FILESTAT_GET,BigInt(0));let c=ct.decode(s.subarray(n,n+r));const u=nt(this);let f;return c=I(a.realPath,c),f=1==(1&e)?await u.promises.stat(c,{bigint:!0}):await u.promises.lstat(c,{bigint:!0}),M(o,i,f),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=et(this),c=J.get(this).fds.get(t,b.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=nt(this),f=st(u,c,ct.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),u.utimesSync(f,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=et(this),c=J.get(this).fds.get(t,b.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=nt(this),f=await ot(u,c,ct.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await u.promises.utimes(f,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),c("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=J.get(this);let c,u;t===i?c=u=a.fds.get(t,b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,b.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,b.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=et(this),h=nt(this),g=st(h,c,ct.decode(f.subarray(n,n+r)),e),d=I(u.realPath,ct.decode(f.subarray(s,s+o)));return h.linkSync(g,d),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=J.get(this);let c,u;t===i?c=u=a.fds.get(t,b.PATH_LINK_SOURCE|b.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,b.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,b.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=et(this),h=nt(this),g=await ot(h,c,ct.decode(f.subarray(n,n+r)),e),d=I(u.realPath,ct.decode(f.subarray(s,s+o)));return await h.promises.link(g,d),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),c("path_open",(function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=J.get(this),l=d.fds.get(t,h,g),_=et(this),E=_.HEAPU8,y=ct.decode(E.subarray(n,n+r)),p=nt(this),I=st(p,l,y,e),b=p.openSync(I,u,438),m=d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=H(d.fds.stdio,b,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=J.get(this),l=d.fds.get(t,h,g),_=et(this),E=_.HEAPU8,y=ct.decode(E.subarray(n,n+r)),p=nt(this),I=await ot(p,l,y,e),b=await p.promises.open(I,u,438),m=await d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=H(d.fds.stdio,b.fd,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),c("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=et(this),c=J.get(this).fds.get(t,b.PATH_READLINK,BigInt(0));let u=ct.decode(o.subarray(e,e+n));u=I(c.realPath,u);const f=nt(this).readlinkSync(u),h=at.encode(f),g=Math.min(h.length,i);return g>=i?42:(o.set(h.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=et(this),c=J.get(this).fds.get(t,b.PATH_READLINK,BigInt(0));let u=ct.decode(o.subarray(e,e+n));u=I(c.realPath,u);const f=nt(this),h=await f.promises.readlink(u),g=at.encode(h),d=Math.min(g.length,i);return d>=i?42:(o.set(g.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),c("path_rename",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=J.get(this);let a,c;t===r?a=c=o.fds.get(t,b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,b.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,b.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=et(this),f=I(a.realPath,ct.decode(u.subarray(e,e+n))),h=I(c.realPath,ct.decode(u.subarray(i,i+s)));return nt(this).renameSync(f,h),0}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=J.get(this);let a,c;t===r?a=c=o.fds.get(t,b.PATH_RENAME_SOURCE|b.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,b.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,b.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=et(this),f=I(a.realPath,ct.decode(u.subarray(e,e+n))),h=I(c.realPath,ct.decode(u.subarray(i,i+s))),g=nt(this);return await g.promises.rename(f,h),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_symlink",(function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=et(this),o=J.get(this).fds.get(n,b.PATH_SYMLINK,BigInt(0)),a=ct.decode(s.subarray(t,t+e));let c=ct.decode(s.subarray(r,r+i));c=I(o.realPath,c);return nt(this).symlinkSync(a,c),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=et(this),o=J.get(this).fds.get(n,b.PATH_SYMLINK,BigInt(0)),a=ct.decode(s.subarray(t,t+e));let c=ct.decode(s.subarray(r,r+i));c=I(o.realPath,c);const u=nt(this);return await u.promises.symlink(a,c),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_UNLINK_FILE,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);return nt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=et(this),i=J.get(this).fds.get(t,b.PATH_UNLINK_FILE,BigInt(0));let s=ct.decode(r.subarray(e,e+n));s=I(i.realPath,s);const o=nt(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(e){if(!(e instanceof t.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');Q.set(a,j(e))}}static createSync(t,e,n,r,i,s,o){const a=new z({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),c=new ft(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return c}static async createAsync(t,e,n,r,i,s,o,a){const c=new W({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),u=new ft(t,e,c,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await c.insertPreopen(s,e.mappedPath,r)}return u}}const ht=Object.freeze(Object.create(null)),gt=Symbol("kExitCode"),dt=Symbol("kSetMemory"),lt=Symbol("kStarted"),_t=Symbol("kInstance");function Et(t,n){e(n,"instance"),e(n.exports,"instance.exports"),t[_t]=n,t[dt](n.exports.memory)}function yt(t){var n;e(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const i=(null!==(n=t.args)&&void 0!==n?n:[]).map(String),s=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{e(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&r(t.print,"options.print"),void 0!==t.printErr&&r(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:i,env:s,preopens:o,stdio:[0,1,2]}}function pt(t,e){this[dt]=t,this.wasiImport=e,this[lt]=!1,this[gt]=0,this[_t]=void 0}class It{constructor(t=ht){const{args:e,env:n,preopens:r,stdio:i}=yt(t),s=ft.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory,pt.call(this,o,s),t.returnOnExit&&(s.proc_exit=bt.bind(this))}static createSync(t=ht){return new It(t)}static async createAsync(t=ht){const{args:n,env:i,preopens:s,stdio:o}=yt(t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ft.createAsync(n,i,s,o,t.fs,t.print,t.printErr,t.asyncify),c=a._setMemory;delete a._setMemory;const u=Object.create(It.prototype);return pt.call(u,c,a),t.returnOnExit&&(a.proc_exit=bt.bind(u)),u}start(t){if(this[lt])throw new Error("WASI instance has already started");this[lt]=!0,Et(this,t);const{_start:e,_initialize:n}=this[_t].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==gt)throw t}return s instanceof Promise?s.then((()=>this[gt]),(t=>{if(t!==gt)throw t;return this[gt]})):this[gt]}initialize(t){if(this[lt])throw new Error("WASI instance has already started");this[lt]=!0,Et(this,t);const{_start:e,_initialize:n}=this[_t].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}}function bt(t){throw this[gt]=t,gt}export{u as Asyncify,Y as Memory,It as WASI,G as WebAssemblyMemory,d as asyncifyLoad,_ as asyncifyLoadSync,j as extendMemory,g as load,l as loadSync,Z as wrapAsyncExport,V as wrapAsyncImport,q as wrapExports};
package/dist/wasm-util.js CHANGED
@@ -973,7 +973,7 @@
973
973
  if (typeof WebAssemblyFunction !== 'function') {
974
974
  throw new Error('WebAssembly.Function is not supported in this environment.' +
975
975
  ' If you are using V8 based browser like Chrome, try to specify' +
976
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
976
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
977
977
  }
978
978
  return WebAssemblyFunction;
979
979
  }
@@ -2550,25 +2550,27 @@
2550
2550
  stdio
2551
2551
  };
2552
2552
  }
2553
+ function initWASI(setMemory, wrap) {
2554
+ this[kSetMemory] = setMemory;
2555
+ this.wasiImport = wrap;
2556
+ this[kStarted] = false;
2557
+ this[kExitCode] = 0;
2558
+ this[kInstance] = undefined;
2559
+ }
2553
2560
  /** @public */
2554
2561
  class WASI {
2555
- constructor(setMemory, wrap) {
2556
- this[kSetMemory] = setMemory;
2557
- this.wasiImport = wrap;
2558
- this[kStarted] = false;
2559
- this[kExitCode] = 0;
2560
- this[kInstance] = undefined;
2561
- }
2562
- static createSync(options = kEmptyObject) {
2562
+ constructor(options = kEmptyObject) {
2563
2563
  const { args, env, preopens, stdio } = validateOptions(options);
2564
2564
  const wrap = WASI$1.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
2565
2565
  const setMemory = wrap._setMemory;
2566
2566
  delete wrap._setMemory;
2567
- const _this = new WASI(setMemory, wrap);
2567
+ initWASI.call(this, setMemory, wrap);
2568
2568
  if (options.returnOnExit) {
2569
- wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2569
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
2570
2570
  }
2571
- return _this;
2571
+ }
2572
+ static createSync(options = kEmptyObject) {
2573
+ return new WASI(options);
2572
2574
  }
2573
2575
  static async createAsync(options = kEmptyObject) {
2574
2576
  const { args, env, preopens, stdio } = validateOptions(options);
@@ -2579,7 +2581,8 @@
2579
2581
  const wrap = await WASI$1.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
2580
2582
  const setMemory = wrap._setMemory;
2581
2583
  delete wrap._setMemory;
2582
- const _this = new WASI(setMemory, wrap);
2584
+ const _this = Object.create(WASI.prototype);
2585
+ initWASI.call(_this, setMemory, wrap);
2583
2586
  if (options.returnOnExit) {
2584
2587
  wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
2585
2588
  }
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wasmUtil={})}(this,(function(t){"use strict";const e="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0;if(!e)throw new Error("WebAssembly is not supported in this environment");function n(t,e){if(null===t||"object"!=typeof t)throw new TypeError(`${e} must be an object. Received ${null===t?"null":typeof t}`)}function r(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function i(t,e){if("function"!=typeof t)throw new TypeError(`${e} must be a function. Received ${null===t?"null":typeof t}`)}function s(t,e){if(void 0!==t)throw new TypeError(`${e} must be undefined. Received ${null===t?"null":typeof t}`)}function o(t){return!(!t||"object"!=typeof t&&"function"!=typeof t||"function"!=typeof t.then)}function a(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}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(t,n,r){var i,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(t instanceof e.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(t.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(t.buffer,this.dataPtr).set([a.start,a.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(e.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(!o(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 a(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(t,n){return"undefined"!=typeof wx&&"undefined"!=typeof __wxConfig?e.instantiate(t,n):fetch(t).then((t=>t.arrayBuffer())).then((t=>e.instantiate(t,n)))}function d(t,n){let r;if(h(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))return e.instantiate(t,n);if("string"!=typeof t&&!(t instanceof URL))throw new TypeError("Invalid source");if("function"==typeof e.instantiateStreaming){let i;try{i=fetch(t),r=e.instantiateStreaming(i,n).catch((()=>g(t,n)))}catch(e){r=g(t,n)}}else r=g(t,n);return r}function l(t,n){if(t instanceof ArrayBuffer&&!ArrayBuffer.isView(t))throw new TypeError("Invalid source");h(n),n=null!=n?n:{};const r=new e.Module(t);return{instance:new e.Instance(r,n),module:r}}const _=46,y=47;function E(t){return t===y}function p(...t){let e="",n=!1;for(let i=t.length-1;i>=-1&&!n;i--){const s=i>=0?t[i]:"/";r(s,"path"),0!==s.length&&(e=`${s}/${e}`,n=s.charCodeAt(0)===y)}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u<t.length)c=t.charCodeAt(u);else{if(r(c))break;c=y}if(r(c)){if(o===u-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==_||i.charCodeAt(i.length-2)!==_){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=u,a=0;continue}if(0!==i.length){i="",s=0,o=u,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,u)}`:i=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===_&&-1!==a?++a:a=-1}return i}(e,!n,"/",E),n?`/${e}`:e.length>0?e:"."}const I={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class b extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(b.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const m=I.FD_DATASYNC|I.FD_READ|I.FD_SEEK|I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_TELL|I.FD_WRITE|I.FD_ADVISE|I.FD_ALLOCATE|I.PATH_CREATE_DIRECTORY|I.PATH_CREATE_FILE|I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET|I.PATH_OPEN|I.FD_READDIR|I.PATH_READLINK|I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET|I.PATH_FILESTAT_GET|I.PATH_FILESTAT_SET_SIZE|I.PATH_FILESTAT_SET_TIMES|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_TIMES|I.FD_FILESTAT_SET_SIZE|I.PATH_SYMLINK|I.PATH_UNLINK_FILE|I.PATH_REMOVE_DIRECTORY|I.POLL_FD_READWRITE|I.SOCK_SHUTDOWN,A=m,T=m,w=m,N=m,B=I.FD_DATASYNC|I.FD_READ|I.FD_SEEK|I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_TELL|I.FD_WRITE|I.FD_ADVISE|I.FD_ALLOCATE|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_SIZE|I.FD_FILESTAT_SET_TIMES|I.POLL_FD_READWRITE,S=BigInt(0),P=I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_ADVISE|I.PATH_CREATE_DIRECTORY|I.PATH_CREATE_FILE|I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET|I.PATH_OPEN|I.FD_READDIR|I.PATH_READLINK|I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET|I.PATH_FILESTAT_GET|I.PATH_FILESTAT_SET_SIZE|I.PATH_FILESTAT_SET_TIMES|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_TIMES|I.PATH_SYMLINK|I.PATH_UNLINK_FILE|I.PATH_REMOVE_DIRECTORY|I.POLL_FD_READWRITE,D=P|B,F=I.FD_READ|I.FD_FDSTAT_SET_FLAGS|I.FD_WRITE|I.FD_FILESTAT_GET|I.POLL_FD_READWRITE|I.SOCK_SHUTDOWN,R=m,U=I.FD_READ|I.FD_FDSTAT_SET_FLAGS|I.FD_WRITE|I.FD_FILESTAT_GET|I.POLL_FD_READWRITE,v=BigInt(0);function L(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new b("Unknown file type",28);switch(r){case 4:i.base=B,i.inheriting=S;break;case 3:i.base=P,i.inheriting=D;break;case 6:case 5:i.base=F,i.inheriting=R;break;case 2:-1!==t.indexOf(e)?(i.base=U,i.inheriting=v):(i.base=w,i.inheriting=N);break;case 1:i.base=A,i.inheriting=T;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~I.FD_WRITE:1===s&&(i.base&=~I.FD_READ),i}function H(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class O{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new b("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class k extends O{constructor(t,e,n,r,i,s,o,a,c){super(e,n,r,i,s,o,a,c),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=H([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function C(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function x(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(C(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class M{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=L(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new b(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return u="<stdout>"===e?new k(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new k(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,r,i,s,o):new O(f,t,e,n,r,i,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new b("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new b("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new b("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new b("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new b("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class K extends M{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return C(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=L(this.stdio,t,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class z extends M{constructor(t){super(t)}async getFileTypeByFd(t){return C(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=L(this.stdio,t.fd,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const W=function(){return e.Memory}();class G extends W{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function Y(t){return Object.getPrototypeOf(t)===e.Memory.prototype&&Object.setPrototypeOf(t,G.prototype),t}function j(){const t=e.Function;if("function"!=typeof t)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flag="--wasm-staging --experimental-wasm-stack-switching"');return t}function $(t,e,n){const r=j();if("function"!=typeof t)throw new TypeError("Function required");const i=e.slice(0);return i.unshift("externref"),new r({parameters:i,results:n},t,{suspending:"first"})}function V(t){const e=j();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function Z(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const q=new WeakMap,X=new WeakMap,Q=new WeakMap;function J(t){return q.get(t)}function tt(t){const e=Q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function et(t){if(t instanceof b)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function nt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return et(t)}return o(e)?e.then((t=>t),et):e}))}function rt(t,e,n,r){let i=p(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function it(t,e,n,r){let i=p(e.realPath,n);if(1==(1&r))try{i=await t.promises.readlink(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}const st=new TextEncoder,ot=new TextDecoder;function at(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ct{constructor(t,n,r,i,s,o){this.args_get=nt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=nt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,st.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=nt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=nt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,st.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=nt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=J(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=nt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=J(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=nt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=nt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=J(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=nt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=nt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=nt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof b)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=J(this);return i.setUint32(e,0,!0),i.setUint32(e+4,st.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=nt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=st.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=J(this);return s.set(i,e),0})),this.fd_seek=nt(this,"fd_seek",(function(t,e,n,r){if(0===(r=Number(r)))return 28;if(0===t||1===t||2===t)return 0;const i=X.get(this).fds.get(t,I.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=J(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=nt(this,"fd_tell",(function(t,e){const n=X.get(this).fds.get(t,I.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=J(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=nt(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=J(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),c=i.getBigUint64(s+32,!0),u=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:c,flags:u},fd_readwrite:{fd:r}}}}const g=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);c=s.u.clock.timeout-t}else c=s.u.clock.timeout;(0===u||c<f)&&(f=c,a=s.userdata,u=1);break;case 1:case 2:g.push(s);break;default:return 28}if(g.length>0){for(o=0;o<g.length;o++){const t=g[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,g.length,!0),0}if(u){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=nt(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=nt(this,"proc_raise",(function(t){return 52})),this.sched_yield=nt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=J(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=J(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=nt(this,"sock_recv",(function(){return 58})),this.sock_send=nt(this,"sock_send",(function(){return 58})),this.sock_shutdown=nt(this,"sock_shutdown",(function(){return 58})),X.set(this,{fds:r,args:t,env:n}),s&&Q.set(this,s);const a=this;function c(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(nt(a,t,n)):$(nt(a,t,n),r,s):nt(a,t,e)}function u(t,e,n,r){const i=X.get(this).fds.get(t,I.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(I.FD_READ|I.FD_READDIR))!==BigInt(0),s=(e&(I.FD_DATASYNC|I.FD_WRITE|I.FD_ALLOCATE|I.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=I.PATH_OPEN,c=e|n;return 0!=(1&t)&&(o|=64,a|=I.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=I.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(c|=I.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,c|=I.FD_SYNC),0!=(16&r)&&(o|=1052672,c|=I.FD_SYNC),s&&0==(1536&o)&&(c|=I.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:c}}c("fd_allocate",(function(t,e,n){const r=X.get(this),i=tt(this),s=r.fds.get(t,I.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=X.get(this).fds.get(t,I.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),c("fd_close",(function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return tt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),c("fd_datasync",(function(t){const e=X.get(this).fds.get(t,I.FD_DATASYNC,BigInt(0));return tt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,I.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),c("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,I.FD_FILESTAT_GET,BigInt(0)),r=tt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=J(this);return x(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,I.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=J(this);return x(i,e,r),0}),["i32","i32"],["i32"]),c("fd_filestat_set_size",(function(t,e){const n=X.get(this).fds.get(t,I.FD_FILESTAT_SET_SIZE,BigInt(0));return tt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=X.get(this).fds.get(t,I.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),c("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r);return tt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),c("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_READ|I.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const g=tt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?Z(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_READ|I.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:g}=await a.fd.read(h,0,h.length,Number(r));return f=h?Z(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_pwrite",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_WRITE|I.FD_SEEK,BigInt(0)),c=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),u=tt(this).writeSync(a.fd,c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_WRITE|I.FD_SEEK,BigInt(0)),c=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=at(),f=u?Z(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const t=tt(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?Z(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=at(),f=u?Z(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?Z(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),c("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,I.FD_READDIR,BigInt(0)),o=tt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=o.statSync(p(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,I.FD_READDIR,BigInt(0)),o=tt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=await o.promises.stat(p(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_renumber",(function(t,e){return X.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=X.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),c("fd_sync",(function(t){const e=X.get(this).fds.get(t,I.FD_SYNC,BigInt(0));return tt(this).fsyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,I.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),c("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_WRITE,BigInt(0)),a=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=tt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(r,c,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_WRITE,BigInt(0)),a=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(r,c,!0),0}),["i32","i32","i32","i32"],["i32"]),c("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),c("path_filestat_get",(function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.PATH_FILESTAT_GET,BigInt(0));let c=ot.decode(s.subarray(n,n+r));const u=tt(this);let f;return c=p(a.realPath,c),f=1==(1&e)?u.statSync(c,{bigint:!0}):u.lstatSync(c,{bigint:!0}),x(o,i,f),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.PATH_FILESTAT_GET,BigInt(0));let c=ot.decode(s.subarray(n,n+r));const u=tt(this);let f;return c=p(a.realPath,c),f=1==(1&e)?await u.promises.stat(c,{bigint:!0}):await u.promises.lstat(c,{bigint:!0}),x(o,i,f),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=J(this),c=X.get(this).fds.get(t,I.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=tt(this),f=rt(u,c,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),u.utimesSync(f,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=J(this),c=X.get(this).fds.get(t,I.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=tt(this),f=await it(u,c,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await u.promises.utimes(f,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),c("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=X.get(this);let c,u;t===i?c=u=a.fds.get(t,I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,I.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,I.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),g=rt(h,c,ot.decode(f.subarray(n,n+r)),e),d=p(u.realPath,ot.decode(f.subarray(s,s+o)));return h.linkSync(g,d),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=X.get(this);let c,u;t===i?c=u=a.fds.get(t,I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,I.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,I.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),g=await it(h,c,ot.decode(f.subarray(n,n+r)),e),d=p(u.realPath,ot.decode(f.subarray(s,s+o)));return await h.promises.link(g,d),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),c("path_open",(function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=X.get(this),l=d.fds.get(t,h,g),_=J(this),y=_.HEAPU8,E=ot.decode(y.subarray(n,n+r)),p=tt(this),I=rt(p,l,E,e),b=p.openSync(I,u,438),m=d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=L(d.fds.stdio,b,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=X.get(this),l=d.fds.get(t,h,g),_=J(this),y=_.HEAPU8,E=ot.decode(y.subarray(n,n+r)),p=tt(this),I=await it(p,l,E,e),b=await p.promises.open(I,u,438),m=await d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=L(d.fds.stdio,b.fd,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),c("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=J(this),c=X.get(this).fds.get(t,I.PATH_READLINK,BigInt(0));let u=ot.decode(o.subarray(e,e+n));u=p(c.realPath,u);const f=tt(this).readlinkSync(u),h=st.encode(f),g=Math.min(h.length,i);return g>=i?42:(o.set(h.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=J(this),c=X.get(this).fds.get(t,I.PATH_READLINK,BigInt(0));let u=ot.decode(o.subarray(e,e+n));u=p(c.realPath,u);const f=tt(this),h=await f.promises.readlink(u),g=st.encode(h),d=Math.min(g.length,i);return d>=i?42:(o.set(g.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),c("path_rename",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=X.get(this);let a,c;t===r?a=c=o.fds.get(t,I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,I.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,I.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=J(this),f=p(a.realPath,ot.decode(u.subarray(e,e+n))),h=p(c.realPath,ot.decode(u.subarray(i,i+s)));return tt(this).renameSync(f,h),0}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=X.get(this);let a,c;t===r?a=c=o.fds.get(t,I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,I.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,I.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=J(this),f=p(a.realPath,ot.decode(u.subarray(e,e+n))),h=p(c.realPath,ot.decode(u.subarray(i,i+s))),g=tt(this);return await g.promises.rename(f,h),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_symlink",(function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=J(this),o=X.get(this).fds.get(n,I.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let c=ot.decode(s.subarray(r,r+i));c=p(o.realPath,c);return tt(this).symlinkSync(a,c),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=J(this),o=X.get(this).fds.get(n,I.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let c=ot.decode(s.subarray(r,r+i));c=p(o.realPath,c);const u=tt(this);return await u.promises.symlink(a,c),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(t){if(!(t instanceof e.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');q.set(a,Y(t))}}static createSync(t,e,n,r,i,s,o){const a=new K({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),c=new ct(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return c}static async createAsync(t,e,n,r,i,s,o,a){const c=new z({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),u=new ct(t,e,c,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await c.insertPreopen(s,e.mappedPath,r)}return u}}const ut=Object.freeze(Object.create(null)),ft=Symbol("kExitCode"),ht=Symbol("kSetMemory"),gt=Symbol("kStarted"),dt=Symbol("kInstance");function lt(t,e){n(e,"instance"),n(e.exports,"instance.exports"),t[dt]=e,t[ht](e.exports.memory)}function _t(t){var e;n(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const r=(null!==(e=t.args)&&void 0!==e?e:[]).map(String),s=[];void 0!==t.env&&(n(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(n(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{n(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&i(t.print,"options.print"),void 0!==t.printErr&&i(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:r,env:s,preopens:o,stdio:[0,1,2]}}class yt{constructor(t,e){this[ht]=t,this.wasiImport=e,this[gt]=!1,this[ft]=0,this[dt]=void 0}static createSync(t=ut){const{args:e,env:n,preopens:r,stdio:i}=_t(t),s=ct.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new yt(o,s);return t.returnOnExit&&(s.proc_exit=Et.bind(a)),a}static async createAsync(t=ut){const{args:e,env:r,preopens:s,stdio:o}=_t(t);void 0!==t.asyncify&&(n(t.asyncify,"options.asyncify"),i(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ct.createAsync(e,r,s,o,t.fs,t.print,t.printErr,t.asyncify),c=a._setMemory;delete a._setMemory;const u=new yt(c,a);return t.returnOnExit&&(a.proc_exit=Et.bind(u)),u}start(t){if(this[gt])throw new Error("WASI instance has already started");this[gt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[dt].exports;let r;i(e,"instance.exports._start"),s(n,"instance.exports._initialize");try{r=e()}catch(t){if(t!==ft)throw t}return r instanceof Promise?r.then((()=>this[ft]),(t=>{if(t!==ft)throw t;return this[ft]})):this[ft]}initialize(t){if(this[gt])throw new Error("WASI instance has already started");this[gt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[dt].exports;if(s(e,"instance.exports._start"),void 0!==n)return i(n,"instance.exports._initialize"),n()}}function Et(t){throw this[ft]=t,ft}t.Asyncify=f,t.Memory=G,t.WASI=yt,t.WebAssemblyMemory=W,t.asyncifyLoad=function(t,e,n){h(n),n=null!=n?n:{};const r=new f;return d(e,n=r.wrapImports(n)).then((e=>{var i;const s=e.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:e.module,instance:r.init(s,e.instance,t)}}))},t.asyncifyLoadSync=function(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=l(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}},t.extendMemory=Y,t.load=d,t.loadSync=l,t.wrapAsyncExport=V,t.wrapAsyncImport=$,t.wrapExports=function(t,e){return a(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:V(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wasmUtil={})}(this,(function(t){"use strict";const e="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0;if(!e)throw new Error("WebAssembly is not supported in this environment");function n(t,e){if(null===t||"object"!=typeof t)throw new TypeError(`${e} must be an object. Received ${null===t?"null":typeof t}`)}function r(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function i(t,e){if("function"!=typeof t)throw new TypeError(`${e} must be a function. Received ${null===t?"null":typeof t}`)}function s(t,e){if(void 0!==t)throw new TypeError(`${e} must be undefined. Received ${null===t?"null":typeof t}`)}function o(t){return!(!t||"object"!=typeof t&&"function"!=typeof t||"function"!=typeof t.then)}function a(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}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(t,n,r){var i,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(t instanceof e.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(t.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(t.buffer,this.dataPtr).set([a.start,a.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(e.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(!o(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 a(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(t,n){return"undefined"!=typeof wx&&"undefined"!=typeof __wxConfig?e.instantiate(t,n):fetch(t).then((t=>t.arrayBuffer())).then((t=>e.instantiate(t,n)))}function d(t,n){let r;if(h(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))return e.instantiate(t,n);if("string"!=typeof t&&!(t instanceof URL))throw new TypeError("Invalid source");if("function"==typeof e.instantiateStreaming){let i;try{i=fetch(t),r=e.instantiateStreaming(i,n).catch((()=>g(t,n)))}catch(e){r=g(t,n)}}else r=g(t,n);return r}function l(t,n){if(t instanceof ArrayBuffer&&!ArrayBuffer.isView(t))throw new TypeError("Invalid source");h(n),n=null!=n?n:{};const r=new e.Module(t);return{instance:new e.Instance(r,n),module:r}}const _=46,y=47;function E(t){return t===y}function p(...t){let e="",n=!1;for(let i=t.length-1;i>=-1&&!n;i--){const s=i>=0?t[i]:"/";r(s,"path"),0!==s.length&&(e=`${s}/${e}`,n=s.charCodeAt(0)===y)}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u<t.length)c=t.charCodeAt(u);else{if(r(c))break;c=y}if(r(c)){if(o===u-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==_||i.charCodeAt(i.length-2)!==_){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=u,a=0;continue}if(0!==i.length){i="",s=0,o=u,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,u)}`:i=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===_&&-1!==a?++a:a=-1}return i}(e,!n,"/",E),n?`/${e}`:e.length>0?e:"."}const I={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class b extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(b.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const m=I.FD_DATASYNC|I.FD_READ|I.FD_SEEK|I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_TELL|I.FD_WRITE|I.FD_ADVISE|I.FD_ALLOCATE|I.PATH_CREATE_DIRECTORY|I.PATH_CREATE_FILE|I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET|I.PATH_OPEN|I.FD_READDIR|I.PATH_READLINK|I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET|I.PATH_FILESTAT_GET|I.PATH_FILESTAT_SET_SIZE|I.PATH_FILESTAT_SET_TIMES|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_TIMES|I.FD_FILESTAT_SET_SIZE|I.PATH_SYMLINK|I.PATH_UNLINK_FILE|I.PATH_REMOVE_DIRECTORY|I.POLL_FD_READWRITE|I.SOCK_SHUTDOWN,A=m,T=m,w=m,N=m,B=I.FD_DATASYNC|I.FD_READ|I.FD_SEEK|I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_TELL|I.FD_WRITE|I.FD_ADVISE|I.FD_ALLOCATE|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_SIZE|I.FD_FILESTAT_SET_TIMES|I.POLL_FD_READWRITE,S=BigInt(0),P=I.FD_FDSTAT_SET_FLAGS|I.FD_SYNC|I.FD_ADVISE|I.PATH_CREATE_DIRECTORY|I.PATH_CREATE_FILE|I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET|I.PATH_OPEN|I.FD_READDIR|I.PATH_READLINK|I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET|I.PATH_FILESTAT_GET|I.PATH_FILESTAT_SET_SIZE|I.PATH_FILESTAT_SET_TIMES|I.FD_FILESTAT_GET|I.FD_FILESTAT_SET_TIMES|I.PATH_SYMLINK|I.PATH_UNLINK_FILE|I.PATH_REMOVE_DIRECTORY|I.POLL_FD_READWRITE,D=P|B,F=I.FD_READ|I.FD_FDSTAT_SET_FLAGS|I.FD_WRITE|I.FD_FILESTAT_GET|I.POLL_FD_READWRITE|I.SOCK_SHUTDOWN,R=m,U=I.FD_READ|I.FD_FDSTAT_SET_FLAGS|I.FD_WRITE|I.FD_FILESTAT_GET|I.POLL_FD_READWRITE,v=BigInt(0);function L(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new b("Unknown file type",28);switch(r){case 4:i.base=B,i.inheriting=S;break;case 3:i.base=P,i.inheriting=D;break;case 6:case 5:i.base=F,i.inheriting=R;break;case 2:-1!==t.indexOf(e)?(i.base=U,i.inheriting=v):(i.base=w,i.inheriting=N);break;case 1:i.base=A,i.inheriting=T;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~I.FD_WRITE:1===s&&(i.base&=~I.FD_READ),i}function H(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class O{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new b("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class k extends O{constructor(t,e,n,r,i,s,o,a,c){super(e,n,r,i,s,o,a,c),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=H([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function C(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function x(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(C(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class M{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=L(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new b(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return u="<stdout>"===e?new k(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new k(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,r,i,s,o):new O(f,t,e,n,r,i,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new b("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new b("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new b("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new b("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new b("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class K extends M{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return C(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=L(this.stdio,t,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class z extends M{constructor(t){super(t)}async getFileTypeByFd(t){return C(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=L(this.stdio,t.fd,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const W=function(){return e.Memory}();class G extends W{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function Y(t){return Object.getPrototypeOf(t)===e.Memory.prototype&&Object.setPrototypeOf(t,G.prototype),t}function j(){const t=e.Function;if("function"!=typeof t)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flags="--wasm-staging --experimental-wasm-stack-switching"');return t}function $(t,e,n){const r=j();if("function"!=typeof t)throw new TypeError("Function required");const i=e.slice(0);return i.unshift("externref"),new r({parameters:i,results:n},t,{suspending:"first"})}function V(t){const e=j();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function Z(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const q=new WeakMap,X=new WeakMap,Q=new WeakMap;function J(t){return q.get(t)}function tt(t){const e=Q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function et(t){if(t instanceof b)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function nt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return et(t)}return o(e)?e.then((t=>t),et):e}))}function rt(t,e,n,r){let i=p(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function it(t,e,n,r){let i=p(e.realPath,n);if(1==(1&r))try{i=await t.promises.readlink(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}const st=new TextEncoder,ot=new TextDecoder;function at(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ct{constructor(t,n,r,i,s,o){this.args_get=nt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=nt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,st.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=nt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=nt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,st.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=nt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=J(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=nt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=J(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=nt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=nt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=J(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=nt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=nt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=nt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof b)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=J(this);return i.setUint32(e,0,!0),i.setUint32(e+4,st.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=nt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=st.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=J(this);return s.set(i,e),0})),this.fd_seek=nt(this,"fd_seek",(function(t,e,n,r){if(0===(r=Number(r)))return 28;if(0===t||1===t||2===t)return 0;const i=X.get(this).fds.get(t,I.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=J(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=nt(this,"fd_tell",(function(t,e){const n=X.get(this).fds.get(t,I.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=J(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=nt(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=J(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),c=i.getBigUint64(s+32,!0),u=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:c,flags:u},fd_readwrite:{fd:r}}}}const g=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);c=s.u.clock.timeout-t}else c=s.u.clock.timeout;(0===u||c<f)&&(f=c,a=s.userdata,u=1);break;case 1:case 2:g.push(s);break;default:return 28}if(g.length>0){for(o=0;o<g.length;o++){const t=g[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,g.length,!0),0}if(u){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=nt(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=nt(this,"proc_raise",(function(t){return 52})),this.sched_yield=nt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=J(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=J(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=nt(this,"sock_recv",(function(){return 58})),this.sock_send=nt(this,"sock_send",(function(){return 58})),this.sock_shutdown=nt(this,"sock_shutdown",(function(){return 58})),X.set(this,{fds:r,args:t,env:n}),s&&Q.set(this,s);const a=this;function c(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(nt(a,t,n)):$(nt(a,t,n),r,s):nt(a,t,e)}function u(t,e,n,r){const i=X.get(this).fds.get(t,I.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(I.FD_READ|I.FD_READDIR))!==BigInt(0),s=(e&(I.FD_DATASYNC|I.FD_WRITE|I.FD_ALLOCATE|I.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=I.PATH_OPEN,c=e|n;return 0!=(1&t)&&(o|=64,a|=I.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=I.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(c|=I.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,c|=I.FD_SYNC),0!=(16&r)&&(o|=1052672,c|=I.FD_SYNC),s&&0==(1536&o)&&(c|=I.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:c}}c("fd_allocate",(function(t,e,n){const r=X.get(this),i=tt(this),s=r.fds.get(t,I.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=X.get(this).fds.get(t,I.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),c("fd_close",(function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return tt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),c("fd_datasync",(function(t){const e=X.get(this).fds.get(t,I.FD_DATASYNC,BigInt(0));return tt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,I.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),c("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,I.FD_FILESTAT_GET,BigInt(0)),r=tt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=J(this);return x(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,I.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=J(this);return x(i,e,r),0}),["i32","i32"],["i32"]),c("fd_filestat_set_size",(function(t,e){const n=X.get(this).fds.get(t,I.FD_FILESTAT_SET_SIZE,BigInt(0));return tt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=X.get(this).fds.get(t,I.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),c("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r);return tt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=u.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),c("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_READ|I.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const g=tt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?Z(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_READ|I.FD_SEEK,BigInt(0));let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:g}=await a.fd.read(h,0,h.length,Number(r));return f=h?Z(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_pwrite",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_WRITE|I.FD_SEEK,BigInt(0)),c=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),u=tt(this).writeSync(a.fd,c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.FD_WRITE|I.FD_SEEK,BigInt(0)),c=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=at(),f=u?Z(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const t=tt(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?Z(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_READ,BigInt(0));let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=at(),f=u?Z(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?Z(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),c("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,I.FD_READDIR,BigInt(0)),o=tt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=o.statSync(p(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,I.FD_READDIR,BigInt(0)),o=tt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=await o.promises.stat(p(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),c("fd_renumber",(function(t,e){return X.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=X.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),c("fd_sync",(function(t){const e=X.get(this).fds.get(t,I.FD_SYNC,BigInt(0));return tt(this).fsyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,I.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),c("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_WRITE,BigInt(0)),a=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=tt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(r,c,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,I.FD_WRITE,BigInt(0)),a=H(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(r,c,!0),0}),["i32","i32","i32","i32"],["i32"]),c("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),c("path_filestat_get",(function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.PATH_FILESTAT_GET,BigInt(0));let c=ot.decode(s.subarray(n,n+r));const u=tt(this);let f;return c=p(a.realPath,c),f=1==(1&e)?u.statSync(c,{bigint:!0}):u.lstatSync(c,{bigint:!0}),x(o,i,f),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,I.PATH_FILESTAT_GET,BigInt(0));let c=ot.decode(s.subarray(n,n+r));const u=tt(this);let f;return c=p(a.realPath,c),f=1==(1&e)?await u.promises.stat(c,{bigint:!0}):await u.promises.lstat(c,{bigint:!0}),x(o,i,f),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=J(this),c=X.get(this).fds.get(t,I.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=tt(this),f=rt(u,c,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),u.utimesSync(f,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;if(-16&o)return 28;const{HEAPU8:a}=J(this),c=X.get(this).fds.get(t,I.PATH_FILESTAT_SET_TIMES,BigInt(0)),u=tt(this),f=await it(u,c,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await u.promises.utimes(f,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),c("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=X.get(this);let c,u;t===i?c=u=a.fds.get(t,I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,I.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,I.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),g=rt(h,c,ot.decode(f.subarray(n,n+r)),e),d=p(u.realPath,ot.decode(f.subarray(s,s+o)));return h.linkSync(g,d),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=X.get(this);let c,u;t===i?c=u=a.fds.get(t,I.PATH_LINK_SOURCE|I.PATH_LINK_TARGET,BigInt(0)):(c=a.fds.get(t,I.PATH_LINK_SOURCE,BigInt(0)),u=a.fds.get(i,I.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),g=await it(h,c,ot.decode(f.subarray(n,n+r)),e),d=p(u.realPath,ot.decode(f.subarray(s,s+o)));return await h.promises.link(g,d),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),c("path_open",(function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=X.get(this),l=d.fds.get(t,h,g),_=J(this),y=_.HEAPU8,E=ot.decode(y.subarray(n,n+r)),p=tt(this),I=rt(p,l,E,e),b=p.openSync(I,u,438),m=d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=L(d.fds.stdio,b,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,c){if(n=Number(n),c=Number(c),0===n||0===c)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:u,needed_base:h,needed_inheriting:g}=f(i,s,o,a),d=X.get(this),l=d.fds.get(t,h,g),_=J(this),y=_.HEAPU8,E=ot.decode(y.subarray(n,n+r)),p=tt(this),I=await it(p,l,E,e),b=await p.promises.open(I,u,438),m=await d.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=L(d.fds.stdio,b.fd,u,m),w=d.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&u)&&(w.pos=N.size));return _.view.setInt32(c,w.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),c("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=J(this),c=X.get(this).fds.get(t,I.PATH_READLINK,BigInt(0));let u=ot.decode(o.subarray(e,e+n));u=p(c.realPath,u);const f=tt(this).readlinkSync(u),h=st.encode(f),g=Math.min(h.length,i);return g>=i?42:(o.set(h.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:a}=J(this),c=X.get(this).fds.get(t,I.PATH_READLINK,BigInt(0));let u=ot.decode(o.subarray(e,e+n));u=p(c.realPath,u);const f=tt(this),h=await f.promises.readlink(u),g=st.encode(h),d=Math.min(g.length,i);return d>=i?42:(o.set(g.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),c("path_rename",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=X.get(this);let a,c;t===r?a=c=o.fds.get(t,I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,I.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,I.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=J(this),f=p(a.realPath,ot.decode(u.subarray(e,e+n))),h=p(c.realPath,ot.decode(u.subarray(i,i+s)));return tt(this).renameSync(f,h),0}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=X.get(this);let a,c;t===r?a=c=o.fds.get(t,I.PATH_RENAME_SOURCE|I.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,I.PATH_RENAME_SOURCE,BigInt(0)),c=o.fds.get(r,I.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:u}=J(this),f=p(a.realPath,ot.decode(u.subarray(e,e+n))),h=p(c.realPath,ot.decode(u.subarray(i,i+s))),g=tt(this);return await g.promises.rename(f,h),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),c("path_symlink",(function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=J(this),o=X.get(this).fds.get(n,I.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let c=ot.decode(s.subarray(r,r+i));c=p(o.realPath,c);return tt(this).symlinkSync(a,c),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=J(this),o=X.get(this).fds.get(n,I.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let c=ot.decode(s.subarray(r,r+i));c=p(o.realPath,c);const u=tt(this);return await u.promises.symlink(a,c),0}),["i32","i32","i32","i32","i32"],["i32"]),c("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);return tt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,I.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=p(i.realPath,s);const o=tt(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(t){if(!(t instanceof e.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');q.set(a,Y(t))}}static createSync(t,e,n,r,i,s,o){const a=new K({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),c=new ct(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return c}static async createAsync(t,e,n,r,i,s,o,a){const c=new z({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),u=new ct(t,e,c,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await c.insertPreopen(s,e.mappedPath,r)}return u}}const ut=Object.freeze(Object.create(null)),ft=Symbol("kExitCode"),ht=Symbol("kSetMemory"),gt=Symbol("kStarted"),dt=Symbol("kInstance");function lt(t,e){n(e,"instance"),n(e.exports,"instance.exports"),t[dt]=e,t[ht](e.exports.memory)}function _t(t){var e;n(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const r=(null!==(e=t.args)&&void 0!==e?e:[]).map(String),s=[];void 0!==t.env&&(n(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(n(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{n(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&i(t.print,"options.print"),void 0!==t.printErr&&i(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:r,env:s,preopens:o,stdio:[0,1,2]}}function yt(t,e){this[ht]=t,this.wasiImport=e,this[gt]=!1,this[ft]=0,this[dt]=void 0}class Et{constructor(t=ut){const{args:e,env:n,preopens:r,stdio:i}=_t(t),s=ct.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory,yt.call(this,o,s),t.returnOnExit&&(s.proc_exit=pt.bind(this))}static createSync(t=ut){return new Et(t)}static async createAsync(t=ut){const{args:e,env:r,preopens:s,stdio:o}=_t(t);void 0!==t.asyncify&&(n(t.asyncify,"options.asyncify"),i(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ct.createAsync(e,r,s,o,t.fs,t.print,t.printErr,t.asyncify),c=a._setMemory;delete a._setMemory;const u=Object.create(Et.prototype);return yt.call(u,c,a),t.returnOnExit&&(a.proc_exit=pt.bind(u)),u}start(t){if(this[gt])throw new Error("WASI instance has already started");this[gt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[dt].exports;let r;i(e,"instance.exports._start"),s(n,"instance.exports._initialize");try{r=e()}catch(t){if(t!==ft)throw t}return r instanceof Promise?r.then((()=>this[ft]),(t=>{if(t!==ft)throw t;return this[ft]})):this[ft]}initialize(t){if(this[gt])throw new Error("WASI instance has already started");this[gt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[dt].exports;if(s(e,"instance.exports._start"),void 0!==n)return i(n,"instance.exports._initialize"),n()}}function pt(t){throw this[ft]=t,ft}t.Asyncify=f,t.Memory=G,t.WASI=Et,t.WebAssemblyMemory=W,t.asyncifyLoad=function(t,e,n){h(n),n=null!=n?n:{};const r=new f;return d(e,n=r.wrapImports(n)).then((e=>{var i;const s=e.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:e.module,instance:r.init(s,e.instance,t)}}))},t.asyncifyLoadSync=function(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=l(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}},t.extendMemory=Y,t.load=d,t.loadSync=l,t.wrapAsyncExport=V,t.wrapAsyncImport=$,t.wrapExports=function(t,e){return a(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:V(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
package/lib/cjs/jspi.js CHANGED
@@ -8,7 +8,7 @@ function checkWebAssemblyFunction() {
8
8
  if (typeof WebAssemblyFunction !== 'function') {
9
9
  throw new Error('WebAssembly.Function is not supported in this environment.' +
10
10
  ' If you are using V8 based browser like Chrome, try to specify' +
11
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
11
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
12
12
  }
13
13
  return WebAssemblyFunction;
14
14
  }
@@ -81,25 +81,27 @@ function validateOptions(options) {
81
81
  stdio
82
82
  };
83
83
  }
84
+ function initWASI(setMemory, wrap) {
85
+ this[kSetMemory] = setMemory;
86
+ this.wasiImport = wrap;
87
+ this[kStarted] = false;
88
+ this[kExitCode] = 0;
89
+ this[kInstance] = undefined;
90
+ }
84
91
  /** @public */
85
92
  class WASI {
86
- constructor(setMemory, wrap) {
87
- this[kSetMemory] = setMemory;
88
- this.wasiImport = wrap;
89
- this[kStarted] = false;
90
- this[kExitCode] = 0;
91
- this[kInstance] = undefined;
92
- }
93
- static createSync(options = kEmptyObject) {
93
+ constructor(options = kEmptyObject) {
94
94
  const { args, env, preopens, stdio } = validateOptions(options);
95
95
  const wrap = preview1_1.WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
96
96
  const setMemory = wrap._setMemory;
97
97
  delete wrap._setMemory;
98
- const _this = new WASI(setMemory, wrap);
98
+ initWASI.call(this, setMemory, wrap);
99
99
  if (options.returnOnExit) {
100
- wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
100
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
101
101
  }
102
- return _this;
102
+ }
103
+ static createSync(options = kEmptyObject) {
104
+ return new WASI(options);
103
105
  }
104
106
  static async createAsync(options = kEmptyObject) {
105
107
  const { args, env, preopens, stdio } = validateOptions(options);
@@ -110,7 +112,8 @@ class WASI {
110
112
  const wrap = await preview1_1.WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
111
113
  const setMemory = wrap._setMemory;
112
114
  delete wrap._setMemory;
113
- const _this = new WASI(setMemory, wrap);
115
+ const _this = Object.create(WASI.prototype);
116
+ initWASI.call(_this, setMemory, wrap);
114
117
  if (options.returnOnExit) {
115
118
  wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
116
119
  }
package/lib/mjs/jspi.mjs CHANGED
@@ -5,7 +5,7 @@ function checkWebAssemblyFunction() {
5
5
  if (typeof WebAssemblyFunction !== 'function') {
6
6
  throw new Error('WebAssembly.Function is not supported in this environment.' +
7
7
  ' If you are using V8 based browser like Chrome, try to specify' +
8
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
8
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
9
9
  }
10
10
  return WebAssemblyFunction;
11
11
  }
@@ -78,25 +78,27 @@ function validateOptions(options) {
78
78
  stdio
79
79
  };
80
80
  }
81
+ function initWASI(setMemory, wrap) {
82
+ this[kSetMemory] = setMemory;
83
+ this.wasiImport = wrap;
84
+ this[kStarted] = false;
85
+ this[kExitCode] = 0;
86
+ this[kInstance] = undefined;
87
+ }
81
88
  /** @public */
82
89
  export class WASI {
83
- constructor(setMemory, wrap) {
84
- this[kSetMemory] = setMemory;
85
- this.wasiImport = wrap;
86
- this[kStarted] = false;
87
- this[kExitCode] = 0;
88
- this[kInstance] = undefined;
89
- }
90
- static createSync(options = kEmptyObject) {
90
+ constructor(options = kEmptyObject) {
91
91
  const { args, env, preopens, stdio } = validateOptions(options);
92
92
  const wrap = _WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
93
93
  const setMemory = wrap._setMemory;
94
94
  delete wrap._setMemory;
95
- const _this = new WASI(setMemory, wrap);
95
+ initWASI.call(this, setMemory, wrap);
96
96
  if (options.returnOnExit) {
97
- wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
97
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
98
98
  }
99
- return _this;
99
+ }
100
+ static createSync(options = kEmptyObject) {
101
+ return new WASI(options);
100
102
  }
101
103
  static async createAsync(options = kEmptyObject) {
102
104
  const { args, env, preopens, stdio } = validateOptions(options);
@@ -107,7 +109,8 @@ export class WASI {
107
109
  const wrap = await _WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
108
110
  const setMemory = wrap._setMemory;
109
111
  delete wrap._setMemory;
110
- const _this = new WASI(setMemory, wrap);
112
+ const _this = Object.create(WASI.prototype);
113
+ initWASI.call(_this, setMemory, wrap);
111
114
  if (options.returnOnExit) {
112
115
  wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
113
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tybys/wasm-util",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "WASI polyfill for browser and some wasm util",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./dist/wasm-util.esm-bundler.js",