Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wasmer/wasi

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wasmer/wasi - npm Package Compare versions

Comparing version 0.4.7 to 0.5.0

82

lib/index.cjs.js

@@ -16,8 +16,8 @@ /*

*****************************************************************************/
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(e,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(b,d){b.__proto__=d}||function(b,d){for(var e in d)d.hasOwnProperty(e)&&(b[e]=d[e])};return extendStatics(e,b)};function __extends(e,b){function f(){this.constructor=e}extendStatics(e,b);e.prototype=null===b?Object.create(b):(f.prototype=b.prototype,new f)}
function __values(e){var b="function"===typeof Symbol&&e[Symbol.iterator],f=0;return b?b.call(e):{next:function(){e&&f>=e.length&&(e=void 0);return{value:e&&e[f++],done:!e}}}}function __read(e,b){var f="function"===typeof Symbol&&e[Symbol.iterator];if(!f)return e;e=f.call(e);var d,u=[];try{for(;(void 0===b||0<b--)&&!(d=e.next()).done;)u.push(d.value)}catch(w){var x={error:w}}finally{try{d&&!d.done&&(f=e["return"])&&f.call(e)}finally{if(x)throw x.error;}}return u}
function __spread(){for(var e=[],b=0;b<arguments.length;b++)e=e.concat(__read(arguments[b]));return e}var globalObj="undefined"!==typeof globalThis?globalThis:"undefined"!==typeof global?global:{},BigIntPolyfill="undefined"!==typeof BigInt?BigInt:globalObj.BigInt||Number,exportedDataView=DataView;
exportedDataView.prototype.setBigUint64||(exportedDataView.prototype.setBigUint64=function(e,b,f){if(b<Math.pow(2,32)){var d=b;b=0}else{d=b.toString(2);b="";for(var u=0;u<64-d.length;u++)b+="0";b+=d;d=parseInt(b.substring(0,32),2);b=parseInt(b.substring(32),2)}this.setUint32(e+(f?0:4),d,f);this.setUint32(e+(f?4:0),b,f)},exportedDataView.prototype.getBigUint64=function(e,b){var f=this.getUint32(e+(b?0:4),b);this.setUint32(e+(b?4:0),b);e=f.toString(2);f=f.toString(2);for(b=0;b<32-e.length;b++);return parseInt(f+
e)});var DataViewPolyfill=exportedDataView,isomorphicBuffer=Buffer,NS_PER_SEC=1E9,getBigIntHrtime=function(e){var b=e();return function(f){f=e(f||b);return f[0]*NS_PER_SEC+f[1]}},crypto=require("crypto"),fs=require("fs"),isTTY=require("tty").isatty,path=require("path"),bigIntHrtime=getBigIntHrtime(process.hrtime);process.hrtime&&process.hrtime.bigint&&(bigIntHrtime=process.hrtime.bigint);
var bindings={hrtime:bigIntHrtime,exit:process.exit,kill:function(e){process.kill(process.pid,e)},randomFillSync:crypto.randomFillSync,isTTY,fs,path},_a,WASI_ESUCCESS=0,WASI_E2BIG=1,WASI_EACCES=2,WASI_EADDRINUSE=3,WASI_EADDRNOTAVAIL=4,WASI_EAFNOSUPPORT=5,WASI_EAGAIN=6,WASI_EALREADY=7,WASI_EBADF=8,WASI_EBADMSG=9,WASI_EBUSY=10,WASI_ECANCELED=11,WASI_ECHILD=12,WASI_ECONNABORTED=13,WASI_ECONNREFUSED=14,WASI_ECONNRESET=15,WASI_EDEADLK=16,WASI_EDESTADDRREQ=17,WASI_EDOM=18,WASI_EDQUOT=19,WASI_EEXIST=20,
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(b,c){b.__proto__=c}||function(b,c){for(var d in c)c.hasOwnProperty(d)&&(b[d]=c[d])};return extendStatics(d,b)};function __extends(d,b){function f(){this.constructor=d}extendStatics(d,b);d.prototype=null===b?Object.create(b):(f.prototype=b.prototype,new f)}
function __values(d){var b="function"===typeof Symbol&&d[Symbol.iterator],f=0;return b?b.call(d):{next:function(){d&&f>=d.length&&(d=void 0);return{value:d&&d[f++],done:!d}}}}function __read(d,b){var f="function"===typeof Symbol&&d[Symbol.iterator];if(!f)return d;d=f.call(d);var c,u=[];try{for(;(void 0===b||0<b--)&&!(c=d.next()).done;)u.push(c.value)}catch(w){var x={error:w}}finally{try{c&&!c.done&&(f=d["return"])&&f.call(d)}finally{if(x)throw x.error;}}return u}
function __spread(){for(var d=[],b=0;b<arguments.length;b++)d=d.concat(__read(arguments[b]));return d}var globalObj="undefined"!==typeof globalThis?globalThis:"undefined"!==typeof global?global:{},BigIntPolyfill="undefined"!==typeof BigInt?BigInt:globalObj.BigInt||Number,exportedDataView=DataView;
exportedDataView.prototype.setBigUint64||(exportedDataView.prototype.setBigUint64=function(d,b,f){if(b<Math.pow(2,32))var c=0;else{c=b.toString(2);b="";for(var u=0;u<64-c.length;u++)b+="0";b+=c;c=parseInt(b.substring(0,32),2);b=parseInt(b.substring(32),2)}this.setUint32(d+(f?0:4),b,f);this.setUint32(d+(f?4:0),c,f)},exportedDataView.prototype.getBigUint64=function(d,b){var f=this.getUint32(d+(b?0:4),b);d=this.getUint32(d+(b?4:0),b);f=f.toString(2);d=d.toString(2);b="";for(var c=0;c<32-f.length;c++)b+=
"0";return BigIntPolyfill("0b"+d+(b+f))});var DataViewPolyfill=exportedDataView,isomorphicBuffer=Buffer,NS_PER_SEC=1E9,getBigIntHrtime=function(d){return function(b){b=d(b);return b[0]*NS_PER_SEC+b[1]}},crypto=require("crypto"),fs=require("fs"),isTTY=require("tty").isatty,path=require("path"),bigIntHrtime=getBigIntHrtime(process.hrtime);process.hrtime&&process.hrtime.bigint&&(bigIntHrtime=process.hrtime.bigint);
var bindings={hrtime:bigIntHrtime,exit:process.exit,kill:function(d){process.kill(process.pid,d)},randomFillSync:crypto.randomFillSync,isTTY,fs,path},_a,WASI_ESUCCESS=0,WASI_E2BIG=1,WASI_EACCES=2,WASI_EADDRINUSE=3,WASI_EADDRNOTAVAIL=4,WASI_EAFNOSUPPORT=5,WASI_EAGAIN=6,WASI_EALREADY=7,WASI_EBADF=8,WASI_EBADMSG=9,WASI_EBUSY=10,WASI_ECANCELED=11,WASI_ECHILD=12,WASI_ECONNABORTED=13,WASI_ECONNREFUSED=14,WASI_ECONNRESET=15,WASI_EDEADLK=16,WASI_EDESTADDRREQ=17,WASI_EDOM=18,WASI_EDQUOT=19,WASI_EEXIST=20,
WASI_EFAULT=21,WASI_EFBIG=22,WASI_EHOSTUNREACH=23,WASI_EIDRM=24,WASI_EILSEQ=25,WASI_EINPROGRESS=26,WASI_EINTR=27,WASI_EINVAL=28,WASI_EIO=29,WASI_EISCONN=30,WASI_EISDIR=31,WASI_ELOOP=32,WASI_EMFILE=33,WASI_EMLINK=34,WASI_EMSGSIZE=35,WASI_EMULTIHOP=36,WASI_ENAMETOOLONG=37,WASI_ENETDOWN=38,WASI_ENETRESET=39,WASI_ENETUNREACH=40,WASI_ENFILE=41,WASI_ENOBUFS=42,WASI_ENODEV=43,WASI_ENOENT=44,WASI_ENOEXEC=45,WASI_ENOLCK=46,WASI_ENOLINK=47,WASI_ENOMEM=48,WASI_ENOMSG=49,WASI_ENOPROTOOPT=50,WASI_ENOSPC=51,WASI_ENOSYS=

@@ -40,36 +40,36 @@ 52,WASI_ENOTCONN=53,WASI_ENOTDIR=54,WASI_ENOTEMPTY=55,WASI_ENOTRECOVERABLE=56,WASI_ENOTSOCK=57,WASI_ENOTTY=59,WASI_ENXIO=60,WASI_EOVERFLOW=61,WASI_EOWNERDEAD=62,WASI_EPERM=63,WASI_EPIPE=64,WASI_EPROTO=65,WASI_EPROTONOSUPPORT=66,WASI_EPROTOTYPE=67,WASI_ERANGE=68,WASI_EROFS=69,WASI_ESPIPE=70,WASI_ESRCH=71,WASI_ESTALE=72,WASI_ETIMEDOUT=73,WASI_ETXTBSY=74,WASI_EXDEV=75,WASI_ENOTCAPABLE=76,WASI_SIGABRT=0,WASI_SIGALRM=1,WASI_SIGBUS=2,WASI_SIGCHLD=3,WASI_SIGCONT=4,WASI_SIGFPE=5,WASI_SIGHUP=6,WASI_SIGILL=

_a[WASI_SIGXFSZ]="SIGXFSZ",_a[WASI_SIGVTALRM]="SIGVTALRM",_a),defaultBindings;defaultBindings=bindings;
var msToNs=function(e){var b=Math.trunc(e);e=BigIntPolyfill(Math.round(1E3*(e-b)));return BigIntPolyfill(b)*BigIntPolyfill(1E3)+e},wrap=function(e){return function(){for(var b=[],f=0;f<arguments.length;f++)b[f]=arguments[f];try{return e.apply(void 0,__spread(b))}catch(d){if("number"===typeof d)return d;if(d&&d.errno)return ERROR_MAP[d.code]||WASI_EINVAL;throw d;}}},stat=function(e,b){var f=e.FD_MAP.get(b);if(!f)throw WASI_EBADF;if(void 0===f.filetype){var d=e.bindings.fs.fstatSync(f.real);e=translateFileAttributes(e,
b,d);b=e.rightsBase;d=e.rightsInheriting;f.filetype=e.filetype;f.rights||(f.rights={base:b,inheriting:d})}return f},translateFileAttributes=function(e,b,f){switch(!0){case f.isBlockDevice():return{filetype:WASI_FILETYPE_BLOCK_DEVICE,rightsBase:RIGHTS_BLOCK_DEVICE_BASE,rightsInheriting:RIGHTS_BLOCK_DEVICE_INHERITING};case f.isCharacterDevice():return f=WASI_FILETYPE_CHARACTER_DEVICE,void 0!==b&&e.bindings.isTTY(b)?{filetype:f,rightsBase:RIGHTS_TTY_BASE,rightsInheriting:RIGHTS_TTY_INHERITING}:{filetype:f,
rightsBase:RIGHTS_CHARACTER_DEVICE_BASE,rightsInheriting:RIGHTS_CHARACTER_DEVICE_INHERITING};case f.isDirectory():return{filetype:WASI_FILETYPE_DIRECTORY,rightsBase:RIGHTS_DIRECTORY_BASE,rightsInheriting:RIGHTS_DIRECTORY_INHERITING};case f.isFIFO():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case f.isFile():return{filetype:WASI_FILETYPE_REGULAR_FILE,rightsBase:RIGHTS_REGULAR_FILE_BASE,rightsInheriting:RIGHTS_REGULAR_FILE_INHERITING};
case f.isSocket():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case f.isSymbolicLink():return{filetype:WASI_FILETYPE_SYMBOLIC_LINK,rightsBase:BigIntPolyfill(0),rightsInheriting:BigIntPolyfill(0)};default:return{filetype:WASI_FILETYPE_UNKNOWN,rightsBase:BigIntPolyfill(0),rightsInheriting:BigIntPolyfill(0)}}},WASIExitError=function(e){function b(b){var d=e.call(this,"WASI Exit error: "+b)||this;d.code=b;return d}__extends(b,e);
return b}(Error),WASIKillError=function(e){function b(b){var d=e.call(this,"WASI Kill signal: "+b)||this;d.signal=b;return d}__extends(b,e);return b}(Error),WASIDefault=function(){function e(b){var e,d=this,u={};b&&b.preopenDirectories&&(u=b.preopenDirectories);var x={};b&&b.env&&(x=b.env);var w=[];b&&b.args&&(w=b.args);var q=defaultBindings;b&&b.bindings&&(q=b.bindings);this.view=this.memory=void 0;this.bindings=q;this.FD_MAP=new Map([[WASI_STDIN_FILENO,{real:0,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,
inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDOUT_FILENO,{real:1,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDERR_FILENO,{real:2,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,inheriting:BigIntPolyfill(0)},path:void 0}]]);var g=this.bindings.fs,m=this.bindings.path;try{for(var z=__values(Object.entries(u)),y=z.next();!y.done;y=z.next()){var C=__read(y.value,2),H=C[0],D=C[1],I=g.openSync(D,g.constants.O_RDONLY),J=__spread(this.FD_MAP.keys()).reverse()[0]+
1;this.FD_MAP.set(J,{real:I,filetype:WASI_FILETYPE_DIRECTORY,rights:{base:RIGHTS_DIRECTORY_BASE,inheriting:RIGHTS_DIRECTORY_INHERITING},fakePath:H,path:D})}}catch(a){var E={error:a}}finally{try{y&&!y.done&&(e=z.return)&&e.call(z)}finally{if(E)throw E.error;}}var A=function(a,c){d.refreshMemory();return Array.from({length:c},function(c,b){b=a+8*b;c=d.view.getUint32(b,!0);b=d.view.getUint32(b+4,!0);return new Uint8Array(d.memory.buffer,c,b)})},h=function(a,c){a=stat(d,a);if(c!==BigIntPolyfill(0)&&(a.rights.base&
c)===BigIntPolyfill(0))throw WASI_EPERM;return a},K=q.hrtime(),B=function(a){switch(a){case WASI_CLOCK_MONOTONIC:case WASI_CLOCK_REALTIME:return q.hrtime();case WASI_CLOCK_PROCESS_CPUTIME_ID:case WASI_CLOCK_THREAD_CPUTIME_ID:return q.hrtime()-K;default:return null}};this.wasiImport={args_get:function(a,c){d.refreshMemory();var b=a,e=c;w.forEach(function(a){d.view.setUint32(b,e,!0);b+=4;e+=isomorphicBuffer.from(d.memory.buffer).write(a+"\x00",e)});return WASI_ESUCCESS},args_sizes_get:function(a,c){d.refreshMemory();
d.view.setUint32(a,w.length,!0);a=w.reduce(function(a,c){return a+isomorphicBuffer.byteLength(c)+1},0);d.view.setUint32(c,a,!0);return WASI_ESUCCESS},environ_get:function(a,c){d.refreshMemory();var b=a,e=c;Object.entries(x).forEach(function(a){var c=__read(a,2);a=c[0];c=c[1];d.view.setUint32(b,e,!0);b+=4;e+=isomorphicBuffer.from(d.memory.buffer).write(a+"="+c+"\x00",e)});return WASI_ESUCCESS},environ_sizes_get:function(a,c){d.refreshMemory();var b=Object.entries(x).map(function(a){a=__read(a,2);return a[0]+
"="+a[1]+"\x00"}),e=b.reduce(function(a,c){return a+isomorphicBuffer.byteLength(c)},0);d.view.setUint32(a,b.length,!0);d.view.setUint32(c,e,!0);return WASI_ESUCCESS},clock_res_get:function(a,c){d.view.setBigUint64(c,BigIntPolyfill(0));return WASI_ESUCCESS},clock_time_get:function(a,c,b){d.refreshMemory();a=B(a);if(null===a)return WASI_EINVAL;d.view.setBigUint64(b,BigIntPolyfill(a),!0);return WASI_ESUCCESS},fd_advise:wrap(function(a,c,d,b){h(a,WASI_RIGHT_FD_ADVISE);return WASI_ENOSYS}),fd_allocate:wrap(function(a,
c,d){h(a,WASI_RIGHT_FD_ALLOCATE);return WASI_ENOSYS}),fd_close:wrap(function(a){var c=h(a,BigIntPolyfill(0));g.closeSync(c.real);d.FD_MAP.delete(a);return WASI_ESUCCESS}),fd_datasync:function(a){a=h(a,WASI_RIGHT_FD_DATASYNC);g.fdatasyncSync(a.real);return WASI_ESUCCESS},fd_fdstat_get:wrap(function(a,c){a=h(a,BigIntPolyfill(0));d.refreshMemory();d.view.setUint8(c,a.filetype);d.view.setUint16(c+2,0,!0);d.view.setUint16(c+4,0,!0);d.view.setBigUint64(c+8,BigIntPolyfill(a.rights.base),!0);d.view.setBigUint64(c+
8+8,BigIntPolyfill(a.rights.inheriting),!0);return WASI_ESUCCESS}),fd_fdstat_set_flags:wrap(function(a,c){h(a,WASI_RIGHT_FD_FDSTAT_SET_FLAGS);return WASI_ENOSYS}),fd_fdstat_set_rights:wrap(function(a,c,d){a=h(a,BigIntPolyfill(0));c|=a.rights.base;if(c>a.rights.base)return WASI_EPERM;d|=a.rights.inheriting;if(d>a.rights.inheriting)return WASI_EPERM;a.rights.base=c;a.rights.inheriting=d;return WASI_ESUCCESS}),fd_filestat_get:wrap(function(a,c){a=h(a,WASI_RIGHT_FD_FILESTAT_GET);var b=g.fstatSync(a.real);
d.refreshMemory();d.view.setBigUint64(c,BigIntPolyfill(b.dev),!0);c+=8;d.view.setBigUint64(c,BigIntPolyfill(b.ino),!0);c+=8;d.view.setUint8(c,a.filetype);c+=4;d.view.setUint32(c,Number(b.nlink),!0);c+=4;d.view.setBigUint64(c,BigIntPolyfill(b.size),!0);c+=8;d.view.setBigUint64(c,msToNs(b.atimeMs),!0);c+=8;d.view.setBigUint64(c,msToNs(b.mtimeMs),!0);d.view.setBigUint64(c+8,msToNs(b.ctimeMs),!0);return WASI_ESUCCESS}),fd_filestat_set_size:wrap(function(a,c){a=h(a,WASI_RIGHT_FD_FILESTAT_SET_SIZE);g.ftruncate(a.real,
Number(c));return WASI_ESUCCESS}),fd_filestat_set_times:wrap(function(a,c,d,b){a=h(a,WASI_RIGHT_FD_FILESTAT_SET_TIMES);var e=B(WASI_CLOCK_REALTIME);g.futimesSync(a.real,(b&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW?e:c,(b&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW?e:d);return WASI_ESUCCESS}),fd_prestat_get:wrap(function(a,c){a=h(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();d.view.setUint8(c,WASI_PREOPENTYPE_DIR);d.view.setUint32(c+4,isomorphicBuffer.byteLength(a.fakePath),
!0);return WASI_ESUCCESS}),fd_prestat_dir_name:wrap(function(a,c,b){a=h(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();isomorphicBuffer.from(d.memory.buffer).write(a.fakePath,c,b,"utf8");return WASI_ESUCCESS}),fd_pwrite:wrap(function(a,c,b,e,f){var n=h(a,WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SEEK),k=0;A(c,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(n.real,a,c,a.byteLength-c,e+k+c);k+=c});d.view.setUint32(f,k,!0);return WASI_ESUCCESS}),fd_write:wrap(function(a,
c,b,e){var n=h(a,WASI_RIGHT_FD_WRITE),f=0;A(c,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(n.real,a,c,a.byteLength-c);f+=c});d.view.setUint32(e,f,!0);return WASI_ESUCCESS}),fd_pread:wrap(function(a,c,b,e,f){var n=h(a,WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SEEK),k=0;A(c,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.readSync(n.real,a,c,a.byteLength-c,e+k+c);k+=c});d.view.setUint32(f,k,!0);return WASI_ESUCCESS}),fd_read:wrap(function(a,c,b,e){var n;a=h(a,WASI_RIGHT_FD_READ);
var f=0===a.real,r=0;try{var v=__values(A(c,b)),l=v.next();a:for(;!l.done;l=v.next()){var t=l.value;for(c=0;c<t.byteLength;){var F=t.byteLength-c,m=g.readSync(a.real,t,c,F,f||void 0===a.offset?null:Number(a.offset));f||(a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(m));c+=m;r+=m;if(0===m||m<F)break a}}}catch(L){var q={error:L}}finally{try{l&&!l.done&&(n=v.return)&&n.call(v)}finally{if(q)throw q.error;}}d.view.setUint32(e,r,!0);return WASI_ESUCCESS}),fd_readdir:wrap(function(a,c,b,
e,f){a=h(a,WASI_RIGHT_FD_READDIR);d.refreshMemory();var n=g.readdirSync(a.path,{withFileTypes:!0}),k=c;for(e=Number(e);e<n.length;e+=1){var r=n[e],l=isomorphicBuffer.byteLength(r.name);if(c+24+l>=k+b)break;d.view.setBigUint64(c,BigIntPolyfill(e+1),!0);c+=8;var t=g.statSync(m.resolve(a.path,r.name));d.view.setBigUint64(c,BigIntPolyfill(t.ino),!0);c+=8;d.view.setUint32(c,l,!0);c+=4;switch(!0){case t.isBlockDevice():l=WASI_FILETYPE_BLOCK_DEVICE;break;case t.isCharacterDevice():l=WASI_FILETYPE_CHARACTER_DEVICE;
break;case t.isDirectory():l=WASI_FILETYPE_DIRECTORY;break;case t.isFIFO():l=WASI_FILETYPE_SOCKET_STREAM;break;case t.isFile():l=WASI_FILETYPE_REGULAR_FILE;break;case t.isSocket():l=WASI_FILETYPE_SOCKET_STREAM;break;case t.isSymbolicLink():l=WASI_FILETYPE_SYMBOLIC_LINK;break;default:l=WASI_FILETYPE_UNKNOWN}d.view.setUint8(c,l);c+=1;c+=3;isomorphicBuffer.from(d.memory.buffer).write(r.name,c);c+=isomorphicBuffer.byteLength(r.name)}d.view.setUint32(f,c-k,!0);return WASI_ESUCCESS}),fd_renumber:wrap(function(a,
c){h(a,BigIntPolyfill(0));h(c,BigIntPolyfill(0));g.closeSync(d.FD_MAP.get(a).real);d.FD_MAP.set(a,d.FD_MAP.get(c));d.FD_MAP.delete(c);return WASI_ESUCCESS}),fd_seek:wrap(function(a,c,b,e){a=h(a,WASI_RIGHT_FD_SEEK);d.refreshMemory();switch(b){case WASI_WHENCE_CUR:a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(c);break;case WASI_WHENCE_END:b=g.fstatSync(a.real).size;a.offset=BigIntPolyfill(b)+BigIntPolyfill(c);break;case WASI_WHENCE_SET:a.offset=BigIntPolyfill(c)}d.view.setBigUint64(e,
a.offset,!0);return WASI_ESUCCESS}),fd_tell:wrap(function(a,c){h(a,WASI_RIGHT_FD_TELL);d.refreshMemory();throw Error("fd_tell to be implemented (without binding)");}),fd_sync:wrap(function(a){a=h(a,WASI_RIGHT_FD_SYNC);g.fsyncSync(a.real);return WASI_ESUCCESS}),path_create_directory:wrap(function(a,c,b){a=h(a,WASI_RIGHT_PATH_CREATE_DIRECTORY);if(!a.path)return WASI_EINVAL;d.refreshMemory();c=isomorphicBuffer.from(d.memory.buffer,c,b).toString();g.mkdirSync(m.resolve(a.path,c));return WASI_ESUCCESS}),
path_filestat_get:wrap(function(a,c,b,e,f){a=h(a,WASI_RIGHT_PATH_FILESTAT_GET);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=isomorphicBuffer.from(d.memory.buffer,b,e).toString();b=g.statSync(m.resolve(a.path,b));d.view.setBigUint64(f,BigIntPolyfill(b.dev),!0);f+=8;d.view.setBigUint64(f,BigIntPolyfill(b.ino),!0);f+=8;d.view.setUint8(f,translateFileAttributes(d,void 0,b).filetype);f+=4;d.view.setUint32(f,Number(b.nlink),!0);f+=4;d.view.setBigUint64(f,BigIntPolyfill(b.size),!0);f+=8;d.view.setBigUint64(f,
msToNs(b.atimeMs),!0);f+=8;d.view.setBigUint64(f,msToNs(b.mtimeMs),!0);d.view.setBigUint64(f+8,msToNs(b.ctimeMs),!0);return WASI_ESUCCESS}),path_filestat_set_times:wrap(function(a,c,b,e,f,p){a=h(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES);if(!a.path)return WASI_EINVAL;d.refreshMemory();var n=B(WASI_CLOCK_REALTIME),k=(c&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW;c=(c&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW;b=isomorphicBuffer.from(d.memory.buffer,b,e).toString();g.utimesSync(m.resolve(a.path,
b),k?n:f,c?n:p);return WASI_ESUCCESS}),path_link:wrap(function(a,c,b,e,f,p,q){a=h(a,WASI_RIGHT_PATH_LINK_SOURCE);f=h(f,WASI_RIGHT_PATH_LINK_TARGET);if(!a.path||!f.path)return WASI_EINVAL;d.refreshMemory();b=isomorphicBuffer.from(d.memory.buffer,b,e).toString();p=isomorphicBuffer.from(d.memory.buffer,p,q).toString();g.linkSync(m.resolve(a.path,b),m.resolve(f.path,p));return WASI_ESUCCESS}),path_open:wrap(function(a,c,b,e,f,p,q,v,l){c=h(a,WASI_RIGHT_PATH_OPEN);p=BigIntPolyfill(p);q=BigIntPolyfill(q);
a=(p&(WASI_RIGHT_FD_READ|WASI_RIGHT_FD_READDIR))!==BigIntPolyfill(0);var n=(p&(WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_ALLOCATE|WASI_RIGHT_FD_FILESTAT_SET_SIZE))!==BigIntPolyfill(0);if(n&&a)var k=g.constants.O_RDWR;else a?k=g.constants.O_RDONLY:n&&(k=g.constants.O_WRONLY);a=p|WASI_RIGHT_PATH_OPEN;p|=q;0!==(f&WASI_O_CREAT)&&(k|=g.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(f&WASI_O_DIRECTORY)&&(k|=g.constants.O_DIRECTORY);0!==(f&WASI_O_EXCL)&&(k|=g.constants.O_EXCL);0!==
(f&WASI_O_TRUNC)&&(k|=g.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE);0!==(v&WASI_FDFLAG_APPEND)&&(k|=g.constants.O_APPEND);0!==(v&WASI_FDFLAG_DSYNC)&&(k=g.constants.O_DSYNC?k|g.constants.O_DSYNC:k|g.constants.O_SYNC,p|=WASI_RIGHT_FD_DATASYNC);0!==(v&WASI_FDFLAG_NONBLOCK)&&(k|=g.constants.O_NONBLOCK);0!==(v&WASI_FDFLAG_RSYNC)&&(k=g.constants.O_RSYNC?k|g.constants.O_RSYNC:k|g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);0!==(v&WASI_FDFLAG_SYNC)&&(k|=g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);n&&
0===(k&(g.constants.O_APPEND|g.constants.O_TRUNC))&&(p|=WASI_RIGHT_FD_SEEK);d.refreshMemory();b=isomorphicBuffer.from(d.memory.buffer,b,e).toString();b=m.resolve(c.path,b);if(m.relative(c.path,b).startsWith(".."))return WASI_ENOTCAPABLE;try{var r=g.realpathSync(b);if(m.relative(c.path,r).startsWith(".."))return WASI_ENOTCAPABLE}catch(G){if("ENOENT"===G.code)r=b;else throw G;}k=g.openSync(r,k);b=__spread(d.FD_MAP.keys()).reverse()[0]+1;d.FD_MAP.set(b,{real:k,filetype:void 0,rights:{base:a,inheriting:p},
path:r});stat(d,b);d.view.setUint32(l,b,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,c,b,e,f,p){a=h(a,WASI_RIGHT_PATH_READLINK);if(!a.path)return WASI_EINVAL;d.refreshMemory();c=isomorphicBuffer.from(d.memory.buffer,c,b).toString();c=m.resolve(a.path,c);c=g.readlinkSync(c);e=isomorphicBuffer.from(d.memory.buffer).write(c,e,f);d.view.setUint32(p,e,!0);return WASI_ESUCCESS}),path_remove_directory:wrap(function(a,c,b){a=h(a,WASI_RIGHT_PATH_REMOVE_DIRECTORY);if(!a.path)return WASI_EINVAL;
d.refreshMemory();c=isomorphicBuffer.from(d.memory.buffer,c,b).toString();g.rmdirSync(m.resolve(a.path,c));return WASI_ESUCCESS}),path_rename:wrap(function(a,c,b,e,f,p){a=h(a,WASI_RIGHT_PATH_RENAME_SOURCE);e=h(e,WASI_RIGHT_PATH_RENAME_TARGET);if(!a.path||!e.path)return WASI_EINVAL;d.refreshMemory();c=isomorphicBuffer.from(d.memory.buffer,c,b).toString();f=isomorphicBuffer.from(d.memory.buffer,f,p).toString();g.renameSync(m.resolve(a.path,c),m.resolve(e.path,f));return WASI_ESUCCESS}),path_symlink:wrap(function(a,
c,b,e,f){b=h(b,WASI_RIGHT_PATH_SYMLINK);if(!b.path)return WASI_EINVAL;d.refreshMemory();a=isomorphicBuffer.from(d.memory.buffer,a,c).toString();e=isomorphicBuffer.from(d.memory.buffer,e,f).toString();g.symlinkSync(a,m.resolve(b.path,e));return WASI_ESUCCESS}),path_unlink_file:wrap(function(a,b,e){a=h(a,WASI_RIGHT_PATH_UNLINK_FILE);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=isomorphicBuffer.from(d.memory.buffer,b,e).toString();g.unlinkSync(m.resolve(a.path,b));return WASI_ESUCCESS}),poll_oneoff:function(a,
b,e,f){var c=0,g=0;d.refreshMemory();for(var h=0;h<e;h+=1){var m=d.view.getBigUint64(a,!0);a+=8;var l=d.view.getUint8(a);a+=1;switch(l){case WASI_EVENTTYPE_CLOCK:a+=7;d.view.getBigUint64(a,!0);a+=8;var n=d.view.getUint32(a,!0);a+=4;a+=4;l=d.view.getBigUint64(a,!0);a+=8;d.view.getBigUint64(a,!0);a+=8;var r=d.view.getUint16(a,!0);a+=2;a+=6;var u=1===r;r=WASI_ESUCCESS;n=BigIntPolyfill(B(n));null===n?r=WASI_EINVAL:(l=u?l:n+l,g=l>g?l:g);d.view.setBigUint64(b,m,!0);b+=8;d.view.setUint16(b,r,!0);b+=2;d.view.setUint8(b,
WASI_EVENTTYPE_CLOCK);b+=1;b+=5;c+=1;break;case WASI_EVENTTYPE_FD_READ:case WASI_EVENTTYPE_FD_WRITE:a+=3;d.view.getUint32(a,!0);a+=4;d.view.setBigUint64(b,m,!0);b+=8;d.view.setUint16(b,WASI_ENOSYS,!0);b+=2;d.view.setUint8(b,l);b+=1;b+=5;c+=1;break;default:return WASI_EINVAL}}for(d.view.setUint32(f,c,!0);q.hrtime()<g;);return WASI_ESUCCESS},proc_exit:function(a){q.exit(a);return WASI_ESUCCESS},proc_raise:function(a){if(!(a in SIGNAL_MAP))return WASI_EINVAL;q.kill(SIGNAL_MAP[a]);return WASI_ESUCCESS},
random_get:function(a,b){d.refreshMemory();q.randomFillSync(new Uint8Array(d.memory.buffer),a,b);return WASI_ESUCCESS},sched_yield:function(){return WASI_ENOSYS},sock_recv:function(){return WASI_ENOSYS},sock_send:function(){return WASI_ENOSYS},sock_shutdown:function(){return WASI_ENOSYS}};Object.keys(this.wasiImport).forEach(function(a){var b=d.wasiImport[a];d.wasiImport[a]=function(){for(var a=[],c=0;c<arguments.length;c++)a[c]=arguments[c];try{return b.apply(void 0,__spread(a))}catch(k){switch(console.log("Catched error: "+
k),k.code){default:throw k;case "ENOENT":return WASI_ENOENT}}}})}e.prototype.refreshMemory=function(){this.view&&0!==this.view.buffer.byteLength||(this.view=new DataViewPolyfill(this.memory.buffer))};e.prototype.setMemory=function(b){this.memory=b};e.prototype.start=function(b){b=b.exports;if(null===b||"object"!==typeof b)throw Error("instance.exports must be an Object. Received "+b+".");var e=b.memory;if(!(e instanceof WebAssembly.Memory))throw Error("instance.exports.memory must be a WebAssembly.Memory. Recceived "+
e+".");this.setMemory(e);b._start&&b._start()};e.defaultBindings=defaultBindings;return e}(),WASI=WASIDefault;exports.WASI=WASI;exports.WASIExitError=WASIExitError;exports.WASIKillError=WASIKillError;exports.default=WASIDefault;
var msToNs=function(d){var b=Math.trunc(d);d=BigIntPolyfill(Math.round(1E3*(d-b)));return BigIntPolyfill(b)*BigIntPolyfill(1E3)+d},wrap=function(d){return function(){for(var b=[],f=0;f<arguments.length;f++)b[f]=arguments[f];try{return d.apply(void 0,__spread(b))}catch(c){if(c&&c.code&&"string"===typeof c.code)return ERROR_MAP[c.code]||WASI_EINVAL;if(c instanceof WASIError)return c.errno;throw c;}}},stat=function(d,b){var f=d.FD_MAP.get(b);if(!f)throw new WASIError(WASI_EBADF);if(void 0===f.filetype){var c=
d.bindings.fs.fstatSync(f.real);d=translateFileAttributes(d,b,c);b=d.rightsBase;c=d.rightsInheriting;f.filetype=d.filetype;f.rights||(f.rights={base:b,inheriting:c})}return f},translateFileAttributes=function(d,b,f){switch(!0){case f.isBlockDevice():return{filetype:WASI_FILETYPE_BLOCK_DEVICE,rightsBase:RIGHTS_BLOCK_DEVICE_BASE,rightsInheriting:RIGHTS_BLOCK_DEVICE_INHERITING};case f.isCharacterDevice():return f=WASI_FILETYPE_CHARACTER_DEVICE,void 0!==b&&d.bindings.isTTY(b)?{filetype:f,rightsBase:RIGHTS_TTY_BASE,
rightsInheriting:RIGHTS_TTY_INHERITING}:{filetype:f,rightsBase:RIGHTS_CHARACTER_DEVICE_BASE,rightsInheriting:RIGHTS_CHARACTER_DEVICE_INHERITING};case f.isDirectory():return{filetype:WASI_FILETYPE_DIRECTORY,rightsBase:RIGHTS_DIRECTORY_BASE,rightsInheriting:RIGHTS_DIRECTORY_INHERITING};case f.isFIFO():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case f.isFile():return{filetype:WASI_FILETYPE_REGULAR_FILE,rightsBase:RIGHTS_REGULAR_FILE_BASE,
rightsInheriting:RIGHTS_REGULAR_FILE_INHERITING};case f.isSocket():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case f.isSymbolicLink():return{filetype:WASI_FILETYPE_SYMBOLIC_LINK,rightsBase:BigIntPolyfill(0),rightsInheriting:BigIntPolyfill(0)};default:return{filetype:WASI_FILETYPE_UNKNOWN,rightsBase:BigIntPolyfill(0),rightsInheriting:BigIntPolyfill(0)}}},WASIError=function(d){function b(f){var c=d.call(this)||this;c.errno=f;
Object.setPrototypeOf(c,b.prototype);return c}__extends(b,d);return b}(Error),WASIExitError=function(d){function b(f){var c=d.call(this,"WASI Exit error: "+f)||this;c.code=f;Object.setPrototypeOf(c,b.prototype);return c}__extends(b,d);return b}(Error),WASIKillError=function(d){function b(f){var c=d.call(this,"WASI Kill signal: "+f)||this;c.signal=f;Object.setPrototypeOf(c,b.prototype);return c}__extends(b,d);return b}(Error),WASIDefault=function(){function d(b){var d,c=this,u={};b&&b.preopenDirectories&&
(u=b.preopenDirectories);var x={};b&&b.env&&(x=b.env);var w=[];b&&b.args&&(w=b.args);var q=defaultBindings;b&&b.bindings&&(q=b.bindings);this.view=this.memory=void 0;this.bindings=q;this.FD_MAP=new Map([[WASI_STDIN_FILENO,{real:0,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDOUT_FILENO,{real:1,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDERR_FILENO,{real:2,filetype:void 0,rights:{base:RIGHTS_REGULAR_FILE_BASE,
inheriting:BigIntPolyfill(0)},path:void 0}]]);var g=this.bindings.fs,n=this.bindings.path;try{for(var z=__values(Object.entries(u)),y=z.next();!y.done;y=z.next()){var C=__read(y.value,2),H=C[0],D=C[1],I=g.openSync(D,g.constants.O_RDONLY),J=__spread(this.FD_MAP.keys()).reverse()[0]+1;this.FD_MAP.set(J,{real:I,filetype:WASI_FILETYPE_DIRECTORY,rights:{base:RIGHTS_DIRECTORY_BASE,inheriting:RIGHTS_DIRECTORY_INHERITING},fakePath:H,path:D})}}catch(a){var E={error:a}}finally{try{y&&!y.done&&(d=z.return)&&
d.call(z)}finally{if(E)throw E.error;}}var A=function(a,e){c.refreshMemory();return Array.from({length:e},function(e,b){b=a+8*b;e=c.view.getUint32(b,!0);b=c.view.getUint32(b+4,!0);return new Uint8Array(c.memory.buffer,e,b)})},k=function(a,e){a=stat(c,a);if(e!==BigIntPolyfill(0)&&(a.rights.base&e)===BigIntPolyfill(0))throw new WASIError(WASI_EPERM);return a},K=q.hrtime(),B=function(a){switch(a){case WASI_CLOCK_MONOTONIC:case WASI_CLOCK_REALTIME:return q.hrtime();case WASI_CLOCK_PROCESS_CPUTIME_ID:case WASI_CLOCK_THREAD_CPUTIME_ID:return q.hrtime()-
K;default:return null}};this.wasiImport={args_get:function(a,e){c.refreshMemory();var b=a,d=e;w.forEach(function(a){c.view.setUint32(b,d,!0);b+=4;d+=isomorphicBuffer.from(c.memory.buffer).write(a+"\x00",d)});return WASI_ESUCCESS},args_sizes_get:function(a,e){c.refreshMemory();c.view.setUint32(a,w.length,!0);a=w.reduce(function(a,c){return a+isomorphicBuffer.byteLength(c)+1},0);c.view.setUint32(e,a,!0);return WASI_ESUCCESS},environ_get:function(a,e){c.refreshMemory();var b=a,d=e;Object.entries(x).forEach(function(a){var e=
__read(a,2);a=e[0];e=e[1];c.view.setUint32(b,d,!0);b+=4;d+=isomorphicBuffer.from(c.memory.buffer).write(a+"="+e+"\x00",d)});return WASI_ESUCCESS},environ_sizes_get:function(a,e){c.refreshMemory();var b=Object.entries(x).map(function(a){a=__read(a,2);return a[0]+"="+a[1]+"\x00"}),d=b.reduce(function(a,c){return a+isomorphicBuffer.byteLength(c)},0);c.view.setUint32(a,b.length,!0);c.view.setUint32(e,d,!0);return WASI_ESUCCESS},clock_res_get:function(a,e){c.view.setBigUint64(e,BigIntPolyfill(0));return WASI_ESUCCESS},
clock_time_get:function(a,e,b){c.refreshMemory();a=B(a);if(null===a)return WASI_EINVAL;c.view.setBigUint64(b,BigIntPolyfill(a),!0);return WASI_ESUCCESS},fd_advise:wrap(function(a,c,b,d){k(a,WASI_RIGHT_FD_ADVISE);return WASI_ENOSYS}),fd_allocate:wrap(function(a,c,b){k(a,WASI_RIGHT_FD_ALLOCATE);return WASI_ENOSYS}),fd_close:wrap(function(a){var e=k(a,BigIntPolyfill(0));g.closeSync(e.real);c.FD_MAP.delete(a);return WASI_ESUCCESS}),fd_datasync:function(a){a=k(a,WASI_RIGHT_FD_DATASYNC);g.fdatasyncSync(a.real);
return WASI_ESUCCESS},fd_fdstat_get:wrap(function(a,e){a=k(a,BigIntPolyfill(0));c.refreshMemory();c.view.setUint8(e,a.filetype);c.view.setUint16(e+2,0,!0);c.view.setUint16(e+4,0,!0);c.view.setBigUint64(e+8,BigIntPolyfill(a.rights.base),!0);c.view.setBigUint64(e+8+8,BigIntPolyfill(a.rights.inheriting),!0);return WASI_ESUCCESS}),fd_fdstat_set_flags:wrap(function(a,c){k(a,WASI_RIGHT_FD_FDSTAT_SET_FLAGS);return WASI_ENOSYS}),fd_fdstat_set_rights:wrap(function(a,c,b){a=k(a,BigIntPolyfill(0));c|=a.rights.base;
if(c>a.rights.base)return WASI_EPERM;b|=a.rights.inheriting;if(b>a.rights.inheriting)return WASI_EPERM;a.rights.base=c;a.rights.inheriting=b;return WASI_ESUCCESS}),fd_filestat_get:wrap(function(a,e){a=k(a,WASI_RIGHT_FD_FILESTAT_GET);var b=g.fstatSync(a.real);c.refreshMemory();c.view.setBigUint64(e,BigIntPolyfill(b.dev),!0);e+=8;c.view.setBigUint64(e,BigIntPolyfill(b.ino),!0);e+=8;c.view.setUint8(e,a.filetype);e+=4;c.view.setUint32(e,Number(b.nlink),!0);e+=4;c.view.setBigUint64(e,BigIntPolyfill(b.size),
!0);e+=8;c.view.setBigUint64(e,msToNs(b.atimeMs),!0);e+=8;c.view.setBigUint64(e,msToNs(b.mtimeMs),!0);c.view.setBigUint64(e+8,msToNs(b.ctimeMs),!0);return WASI_ESUCCESS}),fd_filestat_set_size:wrap(function(a,c){a=k(a,WASI_RIGHT_FD_FILESTAT_SET_SIZE);g.ftruncate(a.real,Number(c));return WASI_ESUCCESS}),fd_filestat_set_times:wrap(function(a,c,b,d){a=k(a,WASI_RIGHT_FD_FILESTAT_SET_TIMES);var e=B(WASI_CLOCK_REALTIME);g.futimesSync(a.real,(d&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW?e:c,
(d&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW?e:b);return WASI_ESUCCESS}),fd_prestat_get:wrap(function(a,e){a=k(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;c.refreshMemory();c.view.setUint8(e,WASI_PREOPENTYPE_DIR);c.view.setUint32(e+4,isomorphicBuffer.byteLength(a.fakePath),!0);return WASI_ESUCCESS}),fd_prestat_dir_name:wrap(function(a,e,b){a=k(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;c.refreshMemory();isomorphicBuffer.from(c.memory.buffer).write(a.fakePath,e,b,"utf8");
return WASI_ESUCCESS}),fd_pwrite:wrap(function(a,e,b,d,f){var l=k(a,WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SEEK),h=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(l.real,a,c,a.byteLength-c,d+h+c);h+=c});c.view.setUint32(f,h,!0);return WASI_ESUCCESS}),fd_write:wrap(function(a,e,b,d){var l=k(a,WASI_RIGHT_FD_WRITE),f=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(l.real,a,c,a.byteLength-c);f+=c});c.view.setUint32(d,f,!0);return WASI_ESUCCESS}),fd_pread:wrap(function(a,
e,b,d,f){var l=k(a,WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SEEK),h=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.readSync(l.real,a,c,a.byteLength-c,d+h+c);h+=c});c.view.setUint32(f,h,!0);return WASI_ESUCCESS}),fd_read:wrap(function(a,e,b,d){var f;a=k(a,WASI_RIGHT_FD_READ);var l=0===a.real,r=0;try{var v=__values(A(e,b)),m=v.next();a:for(;!m.done;m=v.next()){var t=m.value;for(e=0;e<t.byteLength;){var F=t.byteLength-e,n=g.readSync(a.real,t,e,F,l||void 0===a.offset?null:Number(a.offset));l||
(a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(n));e+=n;r+=n;if(0===n||n<F)break a}}}catch(L){var q={error:L}}finally{try{m&&!m.done&&(f=v.return)&&f.call(v)}finally{if(q)throw q.error;}}c.view.setUint32(d,r,!0);return WASI_ESUCCESS}),fd_readdir:wrap(function(a,e,b,d,f){a=k(a,WASI_RIGHT_FD_READDIR);c.refreshMemory();var l=g.readdirSync(a.path,{withFileTypes:!0}),h=e;for(d=Number(d);d<l.length;d+=1){var r=l[d],m=isomorphicBuffer.byteLength(r.name);if(e+24+m>=h+b)break;c.view.setBigUint64(e,
BigIntPolyfill(d+1),!0);e+=8;var t=g.statSync(n.resolve(a.path,r.name));c.view.setBigUint64(e,BigIntPolyfill(t.ino),!0);e+=8;c.view.setUint32(e,m,!0);e+=4;switch(!0){case t.isBlockDevice():m=WASI_FILETYPE_BLOCK_DEVICE;break;case t.isCharacterDevice():m=WASI_FILETYPE_CHARACTER_DEVICE;break;case t.isDirectory():m=WASI_FILETYPE_DIRECTORY;break;case t.isFIFO():m=WASI_FILETYPE_SOCKET_STREAM;break;case t.isFile():m=WASI_FILETYPE_REGULAR_FILE;break;case t.isSocket():m=WASI_FILETYPE_SOCKET_STREAM;break;case t.isSymbolicLink():m=
WASI_FILETYPE_SYMBOLIC_LINK;break;default:m=WASI_FILETYPE_UNKNOWN}c.view.setUint8(e,m);e+=1;e+=3;isomorphicBuffer.from(c.memory.buffer).write(r.name,e);e+=isomorphicBuffer.byteLength(r.name)}c.view.setUint32(f,e-h,!0);return WASI_ESUCCESS}),fd_renumber:wrap(function(a,e){k(a,BigIntPolyfill(0));k(e,BigIntPolyfill(0));g.closeSync(c.FD_MAP.get(a).real);c.FD_MAP.set(a,c.FD_MAP.get(e));c.FD_MAP.delete(e);return WASI_ESUCCESS}),fd_seek:wrap(function(a,e,b,d){a=k(a,WASI_RIGHT_FD_SEEK);c.refreshMemory();
switch(b){case WASI_WHENCE_CUR:a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(e);break;case WASI_WHENCE_END:b=g.fstatSync(a.real).size;a.offset=BigIntPolyfill(b)+BigIntPolyfill(e);break;case WASI_WHENCE_SET:a.offset=BigIntPolyfill(e)}c.view.setBigUint64(d,a.offset,!0);return WASI_ESUCCESS}),fd_tell:wrap(function(a,e){k(a,WASI_RIGHT_FD_TELL);c.refreshMemory();throw Error("fd_tell to be implemented (without binding)");}),fd_sync:wrap(function(a){a=k(a,WASI_RIGHT_FD_SYNC);g.fsyncSync(a.real);
return WASI_ESUCCESS}),path_create_directory:wrap(function(a,e,b){a=k(a,WASI_RIGHT_PATH_CREATE_DIRECTORY);if(!a.path)return WASI_EINVAL;c.refreshMemory();e=isomorphicBuffer.from(c.memory.buffer,e,b).toString();g.mkdirSync(n.resolve(a.path,e));return WASI_ESUCCESS}),path_filestat_get:wrap(function(a,b,d,f,h){a=k(a,WASI_RIGHT_PATH_FILESTAT_GET);if(!a.path)return WASI_EINVAL;c.refreshMemory();d=isomorphicBuffer.from(c.memory.buffer,d,f).toString();d=g.statSync(n.resolve(a.path,d));c.view.setBigUint64(h,
BigIntPolyfill(d.dev),!0);h+=8;c.view.setBigUint64(h,BigIntPolyfill(d.ino),!0);h+=8;c.view.setUint8(h,translateFileAttributes(c,void 0,d).filetype);h+=4;c.view.setUint32(h,Number(d.nlink),!0);h+=4;c.view.setBigUint64(h,BigIntPolyfill(d.size),!0);h+=8;c.view.setBigUint64(h,msToNs(d.atimeMs),!0);h+=8;c.view.setBigUint64(h,msToNs(d.mtimeMs),!0);c.view.setBigUint64(h+8,msToNs(d.ctimeMs),!0);return WASI_ESUCCESS}),path_filestat_set_times:wrap(function(a,b,d,f,h,p){a=k(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES);
if(!a.path)return WASI_EINVAL;c.refreshMemory();var e=B(WASI_CLOCK_REALTIME),l=(b&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW;b=(b&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW;d=isomorphicBuffer.from(c.memory.buffer,d,f).toString();g.utimesSync(n.resolve(a.path,d),l?e:h,b?e:p);return WASI_ESUCCESS}),path_link:wrap(function(a,b,d,f,h,p,q){a=k(a,WASI_RIGHT_PATH_LINK_SOURCE);h=k(h,WASI_RIGHT_PATH_LINK_TARGET);if(!a.path||!h.path)return WASI_EINVAL;c.refreshMemory();d=isomorphicBuffer.from(c.memory.buffer,
d,f).toString();p=isomorphicBuffer.from(c.memory.buffer,p,q).toString();g.linkSync(n.resolve(a.path,d),n.resolve(h.path,p));return WASI_ESUCCESS}),path_open:wrap(function(a,b,d,f,h,p,q,v,m){b=k(a,WASI_RIGHT_PATH_OPEN);p=BigIntPolyfill(p);q=BigIntPolyfill(q);a=(p&(WASI_RIGHT_FD_READ|WASI_RIGHT_FD_READDIR))!==BigIntPolyfill(0);var e=(p&(WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_ALLOCATE|WASI_RIGHT_FD_FILESTAT_SET_SIZE))!==BigIntPolyfill(0);if(e&&a)var l=g.constants.O_RDWR;else a?l=g.constants.O_RDONLY:
e&&(l=g.constants.O_WRONLY);a=p|WASI_RIGHT_PATH_OPEN;p|=q;0!==(h&WASI_O_CREAT)&&(l|=g.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(h&WASI_O_DIRECTORY)&&(l|=g.constants.O_DIRECTORY);0!==(h&WASI_O_EXCL)&&(l|=g.constants.O_EXCL);0!==(h&WASI_O_TRUNC)&&(l|=g.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE);0!==(v&WASI_FDFLAG_APPEND)&&(l|=g.constants.O_APPEND);0!==(v&WASI_FDFLAG_DSYNC)&&(l=g.constants.O_DSYNC?l|g.constants.O_DSYNC:l|g.constants.O_SYNC,p|=WASI_RIGHT_FD_DATASYNC);0!==(v&
WASI_FDFLAG_NONBLOCK)&&(l|=g.constants.O_NONBLOCK);0!==(v&WASI_FDFLAG_RSYNC)&&(l=g.constants.O_RSYNC?l|g.constants.O_RSYNC:l|g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);0!==(v&WASI_FDFLAG_SYNC)&&(l|=g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);e&&0===(l&(g.constants.O_APPEND|g.constants.O_TRUNC))&&(p|=WASI_RIGHT_FD_SEEK);c.refreshMemory();d=isomorphicBuffer.from(c.memory.buffer,d,f).toString();d=n.resolve(b.path,d);if(n.relative(b.path,d).startsWith(".."))return WASI_ENOTCAPABLE;try{var r=g.realpathSync(d);
if(n.relative(b.path,r).startsWith(".."))return WASI_ENOTCAPABLE}catch(G){if("ENOENT"===G.code)r=d;else throw G;}l=g.openSync(r,l);d=__spread(c.FD_MAP.keys()).reverse()[0]+1;c.FD_MAP.set(d,{real:l,filetype:void 0,rights:{base:a,inheriting:p},path:r});stat(c,d);c.view.setUint32(m,d,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,b,d,f,h,p){a=k(a,WASI_RIGHT_PATH_READLINK);if(!a.path)return WASI_EINVAL;c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();b=n.resolve(a.path,
b);b=g.readlinkSync(b);f=isomorphicBuffer.from(c.memory.buffer).write(b,f,h);c.view.setUint32(p,f,!0);return WASI_ESUCCESS}),path_remove_directory:wrap(function(a,b,d){a=k(a,WASI_RIGHT_PATH_REMOVE_DIRECTORY);if(!a.path)return WASI_EINVAL;c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();g.rmdirSync(n.resolve(a.path,b));return WASI_ESUCCESS}),path_rename:wrap(function(a,b,d,f,h,p){a=k(a,WASI_RIGHT_PATH_RENAME_SOURCE);f=k(f,WASI_RIGHT_PATH_RENAME_TARGET);if(!a.path||!f.path)return WASI_EINVAL;
c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();h=isomorphicBuffer.from(c.memory.buffer,h,p).toString();g.renameSync(n.resolve(a.path,b),n.resolve(f.path,h));return WASI_ESUCCESS}),path_symlink:wrap(function(a,b,d,f,h){d=k(d,WASI_RIGHT_PATH_SYMLINK);if(!d.path)return WASI_EINVAL;c.refreshMemory();a=isomorphicBuffer.from(c.memory.buffer,a,b).toString();f=isomorphicBuffer.from(c.memory.buffer,f,h).toString();g.symlinkSync(a,n.resolve(d.path,f));return WASI_ESUCCESS}),path_unlink_file:wrap(function(a,
b,d){a=k(a,WASI_RIGHT_PATH_UNLINK_FILE);if(!a.path)return WASI_EINVAL;c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();g.unlinkSync(n.resolve(a.path,b));return WASI_ESUCCESS}),poll_oneoff:function(a,b,d,f){var e=0,g=0;c.refreshMemory();for(var k=0;k<d;k+=1){var l=c.view.getBigUint64(a,!0);a+=8;var m=c.view.getUint8(a);a+=1;switch(m){case WASI_EVENTTYPE_CLOCK:a+=7;c.view.getBigUint64(a,!0);a+=8;var n=c.view.getUint32(a,!0);a+=4;a+=4;m=c.view.getBigUint64(a,!0);a+=8;c.view.getBigUint64(a,
!0);a+=8;var r=c.view.getUint16(a,!0);a+=2;a+=6;var u=1===r;r=WASI_ESUCCESS;n=BigIntPolyfill(B(n));null===n?r=WASI_EINVAL:(m=u?m:n+m,g=m>g?m:g);c.view.setBigUint64(b,l,!0);b+=8;c.view.setUint16(b,r,!0);b+=2;c.view.setUint8(b,WASI_EVENTTYPE_CLOCK);b+=1;b+=5;e+=1;break;case WASI_EVENTTYPE_FD_READ:case WASI_EVENTTYPE_FD_WRITE:a+=3;c.view.getUint32(a,!0);a+=4;c.view.setBigUint64(b,l,!0);b+=8;c.view.setUint16(b,WASI_ENOSYS,!0);b+=2;c.view.setUint8(b,m);b+=1;b+=5;e+=1;break;default:return WASI_EINVAL}}for(c.view.setUint32(f,
e,!0);q.hrtime()<g;);return WASI_ESUCCESS},proc_exit:function(a){q.exit(a);return WASI_ESUCCESS},proc_raise:function(a){if(!(a in SIGNAL_MAP))return WASI_EINVAL;q.kill(SIGNAL_MAP[a]);return WASI_ESUCCESS},random_get:function(a,b){c.refreshMemory();q.randomFillSync(new Uint8Array(c.memory.buffer),a,b);return WASI_ESUCCESS},sched_yield:function(){return WASI_ENOSYS},sock_recv:function(){return WASI_ENOSYS},sock_send:function(){return WASI_ENOSYS},sock_shutdown:function(){return WASI_ENOSYS}}}d.prototype.refreshMemory=
function(){this.view&&0!==this.view.buffer.byteLength||(this.view=new DataViewPolyfill(this.memory.buffer))};d.prototype.setMemory=function(b){this.memory=b};d.prototype.start=function(b){b=b.exports;if(null===b||"object"!==typeof b)throw Error("instance.exports must be an Object. Received "+b+".");var d=b.memory;if(!(d instanceof WebAssembly.Memory))throw Error("instance.exports.memory must be a WebAssembly.Memory. Recceived "+d+".");this.setMemory(d);b._start&&b._start()};d.defaultBindings=defaultBindings;
return d}(),WASI=WASIDefault;exports.WASI=WASI;exports.WASIError=WASIError;exports.WASIExitError=WASIExitError;exports.WASIKillError=WASIKillError;exports.default=WASIDefault;

@@ -40,2 +40,6 @@ import { BigIntPolyfillType } from "./polyfills/bigint";

};
export declare class WASIError extends Error {
errno: number;
constructor(errno: number);
}
export declare class WASIExitError extends Error {

@@ -42,0 +46,0 @@ code: number | null;

@@ -61,8 +61,11 @@ "use strict";

catch (e) {
if (typeof e === "number") {
return e;
}
if (e && e.errno) {
// If it's an error from the fs
if (e && e.code && typeof e.code === "string") {
return constants_1.ERROR_MAP[e.code] || constants_1.WASI_EINVAL;
}
// If it's a WASI error, we return it directly
if (e instanceof WASIError) {
return e.errno;
}
// Otherwise we let the error bubble up
throw e;

@@ -74,3 +77,3 @@ }

if (!entry) {
throw constants_1.WASI_EBADF;
throw new WASIError(constants_1.WASI_EBADF);
}

@@ -151,2 +154,10 @@ if (entry.filetype === undefined) {

};
class WASIError extends Error {
constructor(errno) {
super();
this.errno = errno;
Object.setPrototypeOf(this, WASIError.prototype);
}
}
exports.WASIError = WASIError;
class WASIExitError extends Error {

@@ -156,2 +167,3 @@ constructor(code) {

this.code = code;
Object.setPrototypeOf(this, WASIExitError.prototype);
}

@@ -164,2 +176,3 @@ }

this.signal = signal;
Object.setPrototypeOf(this, WASIKillError.prototype);
}

@@ -269,3 +282,3 @@ }

if (rights !== bigint_1.BigIntPolyfill(0) && (stats.rights.base & rights) === bigint_1.BigIntPolyfill(0)) {
throw constants_1.WASI_EPERM;
throw new WASIError(constants_1.WASI_EPERM);
}

@@ -947,23 +960,17 @@ return stats;

};
// Wrap each of the imports with a recoverable WASI error
Object.keys(this.wasiImport).forEach((key) => {
const prevImport = this.wasiImport[key];
this.wasiImport[key] = function (...args) {
// console.log(`WASI: wasiImport called: ${key} (${args})`);
try {
let result = prevImport(...args);
// console.log(`WASI: => ${result}`);
return result;
}
catch (e) {
console.log(`Catched error: ${e}`);
switch (e.code) {
default:
throw e;
case "ENOENT":
return constants_1.WASI_ENOENT;
}
}
};
});
// Wrap each of the imports to show the calls in the console
// Object.keys(this.wasiImport).forEach((key: string) => {
// const prevImport = this.wasiImport[key];
// this.wasiImport[key] = function(...args: any[]) {
// console.log(`WASI: wasiImport called: ${key} (${args})`);
// try {
// let result = prevImport(...args);
// console.log(`WASI: => ${result}`);
// return result;
// } catch (e) {
// console.log(`Catched error: ${e}`);
// throw e;
// }
// };
// });
}

@@ -970,0 +977,0 @@ refreshMemory() {

"use strict";
// hrtime polyfill for the browser
Object.defineProperty(exports, "__esModule", { value: true });
const baseNow = Math.floor((Date.now() - performance.now()) * 1e-3);
function hrtime(previousTimestamp) {
// initilaize our variables
let clocktime = performance.now() * 1e-3;
let seconds = Math.floor(clocktime);
let seconds = Math.floor(clocktime) + baseNow;
let nanoseconds = Math.floor((clocktime % 1) * 1e9);

@@ -9,0 +10,0 @@ // Compare to the prvious timestamp if we have one

@@ -5,2 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const bigint_1 = require("./bigint");
let exportedDataView = DataView;

@@ -24,4 +25,4 @@ if (!exportedDataView.prototype.setBigUint64) {

bigNumberAsBinaryStr2 += bigNumberAsBinaryStr;
lowWord = parseInt(bigNumberAsBinaryStr2.substring(0, 32), 2);
highWord = parseInt(bigNumberAsBinaryStr2.substring(32), 2);
highWord = parseInt(bigNumberAsBinaryStr2.substring(0, 32), 2);
lowWord = parseInt(bigNumberAsBinaryStr2.substring(32), 2);
}

@@ -33,5 +34,5 @@ this.setUint32(byteOffset + (littleEndian ? 0 : 4), lowWord, littleEndian);

let lowWord = this.getUint32(byteOffset + (littleEndian ? 0 : 4), littleEndian);
let highWord = this.setUint32(byteOffset + (littleEndian ? 4 : 0), littleEndian);
let highWord = this.getUint32(byteOffset + (littleEndian ? 4 : 0), littleEndian);
var lowWordAsBinaryStr = lowWord.toString(2);
var highWordAsBinaryStr = lowWord.toString(2);
var highWordAsBinaryStr = highWord.toString(2);
// Convert the above binary str to 64 bit (actually 52 bit will work) by padding zeros in the left

@@ -43,5 +44,5 @@ var lowWordAsBinaryStrPadded = "";

lowWordAsBinaryStrPadded += lowWordAsBinaryStr;
return parseInt(highWordAsBinaryStr + lowWordAsBinaryStr);
return bigint_1.BigIntPolyfill("0b" + highWordAsBinaryStr + lowWordAsBinaryStrPadded);
};
}
exports.DataViewPolyfill = exportedDataView;

@@ -7,5 +7,4 @@ "use strict";

const getBigIntHrtime = (nativeHrtime) => {
const baseTime = nativeHrtime();
return (time) => {
const diff = nativeHrtime(time || baseTime);
const diff = nativeHrtime(time);
// Return the time

@@ -12,0 +11,0 @@ return (diff[0] * NS_PER_SEC + diff[1]);

@@ -40,2 +40,6 @@ import { BigIntPolyfillType } from "./polyfills/bigint";

};
export declare class WASIError extends Error {
errno: number;
constructor(errno: number);
}
export declare class WASIExitError extends Error {

@@ -42,0 +46,0 @@ code: number | null;

{
"name": "@wasmer/wasi",
"version": "0.4.7",
"version": "0.5.0",
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚",

@@ -14,11 +14,11 @@ "main": "lib/index.cjs.js",

"precompile": "cd test/rs && make all",
"build": "npx run-s build:clean build:ts build:prod",
"build": "run-s build:clean build:ts build:prod",
"build:clean": "rm -rf lib",
"build:ts": "tsc -b",
"build:prod": "npx rollup -c --environment PROD",
"build:dev": "npx rollup -c --environment DEV",
"dev": "npx watch \"npm run build:dev\" src",
"test": "npx jest --config jest.config.js",
"test:watch": "npx jest --config jest.config.js --watch",
"docs": "npx typedoc src/ --out docs --target es6 --theme minimal --mode file"
"build:prod": "rollup -c --environment PROD",
"build:dev": "rollup -c --environment DEV",
"dev": "watch \"npm run build:dev\" src",
"test": "jest --config jest.config.js",
"test:watch": "jest --config jest.config.js --watch",
"docs": "typedoc src/ --out docs --target es6 --theme minimal --mode file"
},

@@ -55,9 +55,13 @@ "repository": {

"devDependencies": {
"jest": "^24.9.0",
"npm-run-all": "^4.1.5",
"rollup": "^1.27.3",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.6.4"
"typedoc": "^0.15.2",
"typescript": "^3.6.4",
"watch": "^1.0.2"
},
"gitHead": "891f6cb60cee502bdf7fc0a300244c841f88a88b"
"gitHead": "4cd68ac620d51cb220d7d59d58a2b5f964a24344"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc