@wasmer/wasi
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -17,5 +17,5 @@ /* | ||
'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,t=[];try{for(;(void 0===b||0<b--)&&!(c=d.next()).done;)t.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 t} | ||
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,p=[];try{for(;(void 0===b||0<b--)&&!(c=d.next()).done;)p.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 p} | ||
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 t=0;t<64-c.length;t++)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+= | ||
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 p=0;p<64-c.length;p++)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); | ||
@@ -44,32 +44,32 @@ 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, | ||
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,t={};b&&b.preopenDirectories&& | ||
(t=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(t)),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)})},l=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){l(a,WASI_RIGHT_FD_ADVISE);return WASI_ENOSYS}),fd_allocate:wrap(function(a,c,b){l(a,WASI_RIGHT_FD_ALLOCATE);return WASI_ENOSYS}),fd_close:wrap(function(a){var e=l(a,BigIntPolyfill(0));g.closeSync(e.real);c.FD_MAP.delete(a);return WASI_ESUCCESS}),fd_datasync:function(a){a=l(a,WASI_RIGHT_FD_DATASYNC);g.fdatasyncSync(a.real); | ||
return WASI_ESUCCESS},fd_fdstat_get:wrap(function(a,e){a=l(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){l(a,WASI_RIGHT_FD_FDSTAT_SET_FLAGS);return WASI_ENOSYS}),fd_fdstat_set_rights:wrap(function(a,c,b){a=l(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=l(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=l(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=l(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=l(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=l(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 k=l(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(k.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 k=l(a,WASI_RIGHT_FD_WRITE),f=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(k.real,a,c,a.byteLength-c,k.offset?Number(k.offset):null);f+=c});c.view.setUint32(d,f,!0);return WASI_ESUCCESS}), | ||
fd_pread:wrap(function(a,e,b,d,f){var k=l(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(k.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=l(a,WASI_RIGHT_FD_READ);var k=0===a.real,r=0;try{var u=__values(A(e,b)),v=u.next();a:for(;!v.done;v=u.next()){var n=v.value;for(e=0;e<n.byteLength;){var F=n.byteLength-e,m=g.readSync(a.real,n,e,F,k||void 0===a.offset?null: | ||
Number(a.offset));k||(a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(m));e+=m;r+=m;if(0===m||m<F)break a}}}catch(L){var q={error:L}}finally{try{v&&!v.done&&(f=u.return)&&f.call(u)}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=l(a,WASI_RIGHT_FD_READDIR);c.refreshMemory();var k=g.readdirSync(a.path,{withFileTypes:!0}),h=e;for(d=Number(d);d<k.length;d+=1){var r=k[d],v=isomorphicBuffer.byteLength(r.name);c.view.setBigUint64(e, | ||
BigIntPolyfill(d+1),!0);e+=8;var n=g.statSync(m.resolve(a.path,r.name));c.view.setBigUint64(e,BigIntPolyfill(n.ino),!0);e+=8;c.view.setUint32(e,v,!0);e+=4;switch(!0){case n.isBlockDevice():n=WASI_FILETYPE_BLOCK_DEVICE;break;case n.isCharacterDevice():n=WASI_FILETYPE_CHARACTER_DEVICE;break;case n.isDirectory():n=WASI_FILETYPE_DIRECTORY;break;case n.isFIFO():n=WASI_FILETYPE_SOCKET_STREAM;break;case n.isFile():n=WASI_FILETYPE_REGULAR_FILE;break;case n.isSocket():n=WASI_FILETYPE_SOCKET_STREAM;break;case n.isSymbolicLink():n= | ||
WASI_FILETYPE_SYMBOLIC_LINK;break;default:n=WASI_FILETYPE_UNKNOWN}c.view.setUint8(e,n);e+=1;e+=3;if(e+v>=h+b)break;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){l(a,BigIntPolyfill(0));l(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=l(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){l(a,WASI_RIGHT_FD_TELL);c.refreshMemory();throw Error("fd_tell to be implemented (without binding)");}),fd_sync:wrap(function(a){a=l(a,WASI_RIGHT_FD_SYNC); | ||
g.fsyncSync(a.real);return WASI_ESUCCESS}),path_create_directory:wrap(function(a,e,b){a=l(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(m.resolve(a.path,e));return WASI_ESUCCESS}),path_filestat_get:wrap(function(a,b,d,f,h){a=l(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(m.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=l(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES); | ||
if(!a.path)return WASI_EINVAL;c.refreshMemory();var e=B(WASI_CLOCK_REALTIME),k=(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(m.resolve(a.path,d),k?e:h,b?e:p);return WASI_ESUCCESS}),path_link:wrap(function(a,b,d,f,h,p,q){a=l(a,WASI_RIGHT_PATH_LINK_SOURCE);h=l(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(m.resolve(a.path,d),m.resolve(h.path,p));return WASI_ESUCCESS}),path_open:wrap(function(a,b,d,f,h,p,q,u,v){b=l(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 k=g.constants.O_RDWR;else a?k=g.constants.O_RDONLY: | ||
e&&(k=g.constants.O_WRONLY);a=p|WASI_RIGHT_PATH_OPEN;p|=q;0!==(h&WASI_O_CREAT)&&(k|=g.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(h&WASI_O_DIRECTORY)&&(k|=g.constants.O_DIRECTORY);0!==(h&WASI_O_EXCL)&&(k|=g.constants.O_EXCL);0!==(h&WASI_O_TRUNC)&&(k|=g.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE);0!==(u&WASI_FDFLAG_APPEND)&&(k|=g.constants.O_APPEND);0!==(u&WASI_FDFLAG_DSYNC)&&(k=g.constants.O_DSYNC?k|g.constants.O_DSYNC:k|g.constants.O_SYNC,p|=WASI_RIGHT_FD_DATASYNC);0!==(u& | ||
WASI_FDFLAG_NONBLOCK)&&(k|=g.constants.O_NONBLOCK);0!==(u&WASI_FDFLAG_RSYNC)&&(k=g.constants.O_RSYNC?k|g.constants.O_RSYNC:k|g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);0!==(u&WASI_FDFLAG_SYNC)&&(k|=g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);e&&0===(k&(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=m.resolve(b.path,d);if(m.relative(b.path,d).startsWith(".."))return WASI_ENOTCAPABLE;try{var r=g.realpathSync(d); | ||
if(m.relative(b.path,r).startsWith(".."))return WASI_ENOTCAPABLE}catch(G){if("ENOENT"===G.code)r=d;else throw G;}k=g.openSync(r,k);d=__spread(c.FD_MAP.keys()).reverse()[0]+1;c.FD_MAP.set(d,{real:k,filetype:void 0,rights:{base:a,inheriting:p},path:r});stat(c,d);c.view.setUint32(v,d,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,b,d,f,h,p){a=l(a,WASI_RIGHT_PATH_READLINK);if(!a.path)return WASI_EINVAL;c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();b=m.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=l(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(m.resolve(a.path,b));return WASI_ESUCCESS}),path_rename:wrap(function(a,b,d,f,h,p){a=l(a,WASI_RIGHT_PATH_RENAME_SOURCE);f=l(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(m.resolve(a.path,b),m.resolve(f.path,h));return WASI_ESUCCESS}),path_symlink:wrap(function(a,b,d,f,h){d=l(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,m.resolve(d.path,f));return WASI_ESUCCESS}),path_unlink_file:wrap(function(a, | ||
b,d){a=l(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(m.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 t=1===r;r=WASI_ESUCCESS;n=BigIntPolyfill(B(n));null===n?r=WASI_EINVAL:(m=t?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_ESUCCESS},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; | ||
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,p={};b&&b.preopens?p=b.preopens: | ||
b&&b.preopenDirectories&&(p=b.preopenDirectories);var x={};b&&b.env&&(x=b.env);var w=[];b&&b.args&&(w=b.args);var v=defaultBindings;b&&b.bindings&&(v=b.bindings);this.view=this.memory=void 0;this.bindings=v;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,l=this.bindings.path;try{for(var z=__values(Object.entries(p)),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=v.hrtime(),B=function(a){switch(a){case WASI_CLOCK_MONOTONIC:case WASI_CLOCK_REALTIME:return v.hrtime(); | ||
case WASI_CLOCK_PROCESS_CPUTIME_ID:case WASI_CLOCK_THREAD_CPUTIME_ID:return v.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 h=k(a,WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SEEK),m=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.writeSync(h.real,a,c,a.byteLength-c,d+m+c);m+=c});c.view.setUint32(f,m,!0);return WASI_ESUCCESS}),fd_write:wrap(function(a,e,b,d){var h=k(a,WASI_RIGHT_FD_WRITE),f=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;){var e=g.writeSync(h.real, | ||
a,c,a.byteLength-c,h.offset?Number(h.offset):null);h.offset&&(h.offset+=BigIntPolyfill(e));c+=e}f+=c});c.view.setUint32(d,f,!0);return WASI_ESUCCESS}),fd_pread:wrap(function(a,e,b,d,f){var h=k(a,WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SEEK),m=0;A(e,b).forEach(function(a){for(var c=0;c<a.byteLength;)c+=g.readSync(h.real,a,c,a.byteLength-c,d+m+c);m+=c});c.view.setUint32(f,m,!0);return WASI_ESUCCESS}),fd_read:wrap(function(a,e,b,d){var h;a=k(a,WASI_RIGHT_FD_READ);var f=0===a.real,r=0;try{var t=__values(A(e, | ||
b)),u=t.next();a:for(;!u.done;u=t.next()){var n=u.value;for(e=0;e<n.byteLength;){var F=n.byteLength-e,l=g.readSync(a.real,n,e,F,f||void 0===a.offset?null:Number(a.offset));f||(a.offset=(a.offset?a.offset:BigIntPolyfill(0))+BigIntPolyfill(l));e+=l;r+=l;if(0===l||l<F)break a}}}catch(L){var p={error:L}}finally{try{u&&!u.done&&(h=t.return)&&h.call(t)}finally{if(p)throw p.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 h=g.readdirSync(a.path,{withFileTypes:!0}),m=e;for(d=Number(d);d<h.length;d+=1){var r=h[d],u=isomorphicBuffer.byteLength(r.name);c.view.setBigUint64(e,BigIntPolyfill(d+1),!0);e+=8;var n=g.statSync(l.resolve(a.path,r.name));c.view.setBigUint64(e,BigIntPolyfill(n.ino),!0);e+=8;c.view.setUint32(e,u,!0);e+=4;switch(!0){case n.isBlockDevice():n=WASI_FILETYPE_BLOCK_DEVICE;break;case n.isCharacterDevice():n=WASI_FILETYPE_CHARACTER_DEVICE;break;case n.isDirectory():n=WASI_FILETYPE_DIRECTORY;break;case n.isFIFO():n= | ||
WASI_FILETYPE_SOCKET_STREAM;break;case n.isFile():n=WASI_FILETYPE_REGULAR_FILE;break;case n.isSocket():n=WASI_FILETYPE_SOCKET_STREAM;break;case n.isSymbolicLink():n=WASI_FILETYPE_SYMBOLIC_LINK;break;default:n=WASI_FILETYPE_UNKNOWN}c.view.setUint8(e,n);e+=1;e+=3;if(e+u>=m+b)break;isomorphicBuffer.from(c.memory.buffer).write(r.name,e);e+=isomorphicBuffer.byteLength(r.name)}c.view.setUint32(f,e-m,!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){a=k(a,WASI_RIGHT_FD_TELL);c.refreshMemory();a.offset||(a.offset=BigIntPolyfill(0));c.view.setBigUint64(e,a.offset,!0);return WASI_ESUCCESS}),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(l.resolve(a.path,e));return WASI_ESUCCESS}),path_filestat_get:wrap(function(a, | ||
e,b,d,f){a=k(a,WASI_RIGHT_PATH_FILESTAT_GET);if(!a.path)return WASI_EINVAL;c.refreshMemory();b=isomorphicBuffer.from(c.memory.buffer,b,d).toString();b=g.statSync(l.resolve(a.path,b));c.view.setBigUint64(f,BigIntPolyfill(b.dev),!0);f+=8;c.view.setBigUint64(f,BigIntPolyfill(b.ino),!0);f+=8;c.view.setUint8(f,translateFileAttributes(c,void 0,b).filetype);f+=4;c.view.setUint32(f,Number(b.nlink),!0);f+=4;c.view.setBigUint64(f,BigIntPolyfill(b.size),!0);f+=8;c.view.setBigUint64(f,msToNs(b.atimeMs),!0);f+= | ||
8;c.view.setBigUint64(f,msToNs(b.mtimeMs),!0);c.view.setBigUint64(f+8,msToNs(b.ctimeMs),!0);return WASI_ESUCCESS}),path_filestat_set_times:wrap(function(a,b,d,f,m,q){a=k(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES);if(!a.path)return WASI_EINVAL;c.refreshMemory();var e=B(WASI_CLOCK_REALTIME),h=(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(l.resolve(a.path,d),h?e: | ||
m,b?e:q);return WASI_ESUCCESS}),path_link:wrap(function(a,b,d,f,m,q,p){a=k(a,WASI_RIGHT_PATH_LINK_SOURCE);m=k(m,WASI_RIGHT_PATH_LINK_TARGET);if(!a.path||!m.path)return WASI_EINVAL;c.refreshMemory();d=isomorphicBuffer.from(c.memory.buffer,d,f).toString();q=isomorphicBuffer.from(c.memory.buffer,q,p).toString();g.linkSync(l.resolve(a.path,d),l.resolve(m.path,q));return WASI_ESUCCESS}),path_open:wrap(function(a,b,d,f,m,q,p,t,u){b=k(a,WASI_RIGHT_PATH_OPEN);q=BigIntPolyfill(q);p=BigIntPolyfill(p);a=(q& | ||
(WASI_RIGHT_FD_READ|WASI_RIGHT_FD_READDIR))!==BigIntPolyfill(0);var e=(q&(WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_ALLOCATE|WASI_RIGHT_FD_FILESTAT_SET_SIZE))!==BigIntPolyfill(0);if(e&&a)var h=g.constants.O_RDWR;else a?h=g.constants.O_RDONLY:e&&(h=g.constants.O_WRONLY);a=q|WASI_RIGHT_PATH_OPEN;q|=p;0!==(m&WASI_O_CREAT)&&(h|=g.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(m&WASI_O_DIRECTORY)&&(h|=g.constants.O_DIRECTORY);0!==(m&WASI_O_EXCL)&&(h|=g.constants.O_EXCL);0!==(m&WASI_O_TRUNC)&& | ||
(h|=g.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE);0!==(t&WASI_FDFLAG_APPEND)&&(h|=g.constants.O_APPEND);0!==(t&WASI_FDFLAG_DSYNC)&&(h=g.constants.O_DSYNC?h|g.constants.O_DSYNC:h|g.constants.O_SYNC,q|=WASI_RIGHT_FD_DATASYNC);0!==(t&WASI_FDFLAG_NONBLOCK)&&(h|=g.constants.O_NONBLOCK);0!==(t&WASI_FDFLAG_RSYNC)&&(h=g.constants.O_RSYNC?h|g.constants.O_RSYNC:h|g.constants.O_SYNC,q|=WASI_RIGHT_FD_SYNC);0!==(t&WASI_FDFLAG_SYNC)&&(h|=g.constants.O_SYNC,q|=WASI_RIGHT_FD_SYNC);e&&0===(h&(g.constants.O_APPEND| | ||
g.constants.O_TRUNC))&&(q|=WASI_RIGHT_FD_SEEK);c.refreshMemory();d=isomorphicBuffer.from(c.memory.buffer,d,f).toString();d=l.resolve(b.path,d);if(l.relative(b.path,d).startsWith(".."))return WASI_ENOTCAPABLE;try{var r=g.realpathSync(d);if(l.relative(b.path,r).startsWith(".."))return WASI_ENOTCAPABLE}catch(G){if("ENOENT"===G.code)r=d;else throw G;}h=g.openSync(r,h);d=__spread(c.FD_MAP.keys()).reverse()[0]+1;c.FD_MAP.set(d,{real:h,filetype:void 0,rights:{base:a,inheriting:q},path:r});stat(c,d);c.view.setUint32(u, | ||
d,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,b,d,f,m,q){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=l.resolve(a.path,b);b=g.readlinkSync(b);f=isomorphicBuffer.from(c.memory.buffer).write(b,f,m);c.view.setUint32(q,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(l.resolve(a.path,b));return WASI_ESUCCESS}),path_rename:wrap(function(a,b,d,f,m,q){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();m=isomorphicBuffer.from(c.memory.buffer,m,q).toString();g.renameSync(l.resolve(a.path,b),l.resolve(f.path,m));return WASI_ESUCCESS}),path_symlink:wrap(function(a,b,d,f,m){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,m).toString();g.symlinkSync(a,l.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(l.resolve(a.path,b));return WASI_ESUCCESS}),poll_oneoff:function(a,b,d,f){var e=0,g=0;c.refreshMemory();for(var h=0;h<d;h+= | ||
1){var k=c.view.getBigUint64(a,!0);a+=8;var l=c.view.getUint8(a);a+=1;switch(l){case WASI_EVENTTYPE_CLOCK:a+=7;c.view.getBigUint64(a,!0);a+=8;var n=c.view.getUint32(a,!0);a+=4;a+=4;l=c.view.getBigUint64(a,!0);a+=8;c.view.getBigUint64(a,!0);a+=8;var p=c.view.getUint16(a,!0);a+=2;a+=6;var r=1===p;p=WASI_ESUCCESS;n=BigIntPolyfill(B(n));null===n?p=WASI_EINVAL:(l=r?l:n+l,g=l>g?l:g);c.view.setBigUint64(b,k,!0);b+=8;c.view.setUint16(b,p,!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,k,!0);b+=8;c.view.setUint16(b,WASI_ENOSYS,!0);b+=2;c.view.setUint8(b,l);b+=1;b+=5;e+=1;break;default:return WASI_EINVAL}}for(c.view.setUint32(f,e,!0);v.hrtime()<g;);return WASI_ESUCCESS},proc_exit:function(a){v.exit(a);return WASI_ESUCCESS},proc_raise:function(a){if(!(a in SIGNAL_MAP))return WASI_EINVAL;v.kill(SIGNAL_MAP[a]);return WASI_ESUCCESS},random_get:function(a,b){c.refreshMemory(); | ||
v.randomFillSync(new Uint8Array(c.memory.buffer),a,b);return WASI_ESUCCESS},sched_yield:function(){return WASI_ESUCCESS},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; |
@@ -34,3 +34,3 @@ import { BigIntPolyfillType } from "./polyfills/bigint"; | ||
}; | ||
export declare type WASIConfig = { | ||
export declare type WASIConfigOld = { | ||
preopenDirectories?: WASIPreopenedDirs; | ||
@@ -41,2 +41,8 @@ env?: WASIEnv; | ||
}; | ||
export declare type WASIConfig = { | ||
preopens?: WASIPreopenedDirs; | ||
env?: WASIEnv; | ||
args?: WASIArgs; | ||
bindings?: WASIBindings; | ||
}; | ||
export declare class WASIError extends Error { | ||
@@ -61,3 +67,3 @@ errno: number; | ||
static defaultBindings: WASIBindings; | ||
constructor(wasiConfig?: WASIConfig); | ||
constructor(wasiConfig?: WASIConfigOld | WASIConfig); | ||
refreshMemory(): void; | ||
@@ -64,0 +70,0 @@ setMemory(memory: WebAssembly.Memory): void; |
@@ -178,7 +178,11 @@ "use strict"; | ||
constructor(wasiConfig) { | ||
// Destructur our wasiConfig | ||
let preopenDirectories = {}; | ||
if (wasiConfig && wasiConfig.preopenDirectories) { | ||
preopenDirectories = wasiConfig.preopenDirectories; | ||
// Destructure our wasiConfig | ||
let preopens = {}; | ||
if (wasiConfig && wasiConfig.preopens) { | ||
preopens = wasiConfig.preopens; | ||
} | ||
else if (wasiConfig && wasiConfig.preopenDirectories) { | ||
preopens = wasiConfig | ||
.preopenDirectories; | ||
} | ||
let env = {}; | ||
@@ -244,3 +248,3 @@ if (wasiConfig && wasiConfig.env) { | ||
let path = this.bindings.path; | ||
for (const [k, v] of Object.entries(preopenDirectories)) { | ||
for (const [k, v] of Object.entries(preopens)) { | ||
const real = fs.openSync(v, fs.constants.O_RDONLY); | ||
@@ -470,4 +474,6 @@ const newfd = [...this.FD_MAP.keys()].reverse()[0] + 1; | ||
while (w < iov.byteLength) { | ||
// console.log("FD WRITE", stats.real, iov, w, iov.byteLength - w, stats.offset); | ||
w += fs.writeSync(stats.real, iov, w, iov.byteLength - w, stats.offset ? Number(stats.offset) : null); | ||
const i = fs.writeSync(stats.real, iov, w, iov.byteLength - w, stats.offset ? Number(stats.offset) : null); | ||
if (stats.offset) | ||
stats.offset += bigint_1.BigIntPolyfill(i); | ||
w += i; | ||
} | ||
@@ -611,14 +617,8 @@ written += w; | ||
const stats = CHECK_FD(fd, constants_1.WASI_RIGHT_FD_TELL); | ||
// TODO: Why? | ||
// Refreshing memory here either way | ||
this.refreshMemory(); | ||
throw new Error("fd_tell to be implemented (without binding)"); | ||
// const currentOffset = binding.seek(stats.real, BigInt(0), SEEK_CUR) | ||
// if (typeof currentOffset === 'number') { | ||
// // errno | ||
// throw currentOffset | ||
// } | ||
// this.refreshMemory() | ||
// this.view.setBigUint64(offsetPtr, currentOffset, true) | ||
// return WASI_ESUCCESS | ||
if (!stats.offset) { | ||
stats.offset = bigint_1.BigIntPolyfill(0); | ||
} | ||
this.view.setBigUint64(offsetPtr, stats.offset, true); | ||
return constants_1.WASI_ESUCCESS; | ||
}), | ||
@@ -625,0 +625,0 @@ fd_sync: wrap((fd) => { |
/// <reference types="node" /> | ||
declare const isomorphicBuffer: typeof Buffer; | ||
declare const isomorphicBuffer: { | ||
new (str: string, encoding?: string | undefined): Buffer; | ||
new (size: number): Buffer; | ||
new (array: Uint8Array): Buffer; | ||
new (arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer; | ||
new (array: any[]): Buffer; | ||
new (buffer: Buffer): Buffer; | ||
prototype: Buffer; | ||
from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number | undefined, length?: number | undefined): Buffer; | ||
from(data: any[]): Buffer; | ||
from(data: Uint8Array): Buffer; | ||
from(str: string, encoding?: string | undefined): Buffer; | ||
of(...items: number[]): Buffer; | ||
isBuffer(obj: any): obj is Buffer; | ||
isEncoding(encoding: string): boolean | undefined; | ||
byteLength(string: string | ArrayBuffer | SharedArrayBuffer | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | DataView, encoding?: string | undefined): number; | ||
concat(list: Uint8Array[], totalLength?: number | undefined): Buffer; | ||
compare(buf1: Uint8Array, buf2: Uint8Array): number; | ||
alloc(size: number, fill?: string | number | Buffer | undefined, encoding?: string | undefined): Buffer; | ||
allocUnsafe(size: number): Buffer; | ||
allocUnsafeSlow(size: number): Buffer; | ||
poolSize: number; | ||
}; | ||
export default isomorphicBuffer; |
{ | ||
"name": "@wasmer/wasi", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.cjs.js", | ||
"iife": "lib/index.iife.js", | ||
"typings": "lib/wasi/src/index.d.ts", | ||
"typings": "lib/packages/wasi/src/index.d.ts", | ||
"files": [ | ||
@@ -54,14 +54,3 @@ "lib" | ||
}, | ||
"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", | ||
"typedoc": "^0.15.2", | ||
"typescript": "^3.6.4", | ||
"watch": "^1.0.2" | ||
}, | ||
"gitHead": "4880face192985a055e89e145ba3a643d4a07087" | ||
"gitHead": "d8b174aaeb62b0d293a30479322fe493ce872551" | ||
} |
@@ -87,3 +87,3 @@ # `@wasmer/wasi` | ||
// OPTIONAL: The pre-opened dirctories | ||
preopenDirectories: {}, | ||
preopens: {}, | ||
@@ -141,3 +141,3 @@ // OPTIONAL: The environment vars | ||
let wasi = new WASI({ | ||
preopenDirectories: {}, | ||
preopens: {}, | ||
env: {}, | ||
@@ -144,0 +144,0 @@ args: [], |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
278075
0
41
3170