@wasmer/wasi
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -111,2 +111,3 @@ export declare const WASI_ESUCCESS = 0; | ||
export declare const WASI_FILETYPE_SYMBOLIC_LINK = 7; | ||
export declare type WASI_FILETYPE = typeof WASI_FILETYPE_UNKNOWN | typeof WASI_FILETYPE_BLOCK_DEVICE | typeof WASI_FILETYPE_CHARACTER_DEVICE | typeof WASI_FILETYPE_DIRECTORY | typeof WASI_FILETYPE_REGULAR_FILE | typeof WASI_FILETYPE_SOCKET_DGRAM | typeof WASI_FILETYPE_SOCKET_STREAM | typeof WASI_FILETYPE_SYMBOLIC_LINK; | ||
export declare const WASI_FDFLAG_APPEND = 1; | ||
@@ -113,0 +114,0 @@ export declare const WASI_FDFLAG_DSYNC = 2; |
@@ -39,36 +39,37 @@ /* | ||
_a[WASI_SIGXFSZ]="SIGXFSZ",_a[WASI_SIGVTALRM]="SIGVTALRM",_a),defaultBindings;defaultBindings=bindings; | ||
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,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; | ||
var STDIN_DEFAULT_RIGHTS=WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SYNC|WASI_RIGHT_FD_ADVISE|WASI_RIGHT_FD_FILESTAT_GET|WASI_RIGHT_POLL_FD_READWRITE,STDOUT_DEFAULT_RIGHTS=WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SYNC|WASI_RIGHT_FD_ADVISE|WASI_RIGHT_FD_FILESTAT_GET|WASI_RIGHT_POLL_FD_READWRITE,STDERR_DEFAULT_RIGHTS=STDOUT_DEFAULT_RIGHTS,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,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:WASI_FILETYPE_CHARACTER_DEVICE,rights:{base:STDIN_DEFAULT_RIGHTS,inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDOUT_FILENO,{real:1,filetype:WASI_FILETYPE_CHARACTER_DEVICE,rights:{base:STDOUT_DEFAULT_RIGHTS,inheriting:BigIntPolyfill(0)},path:void 0}],[WASI_STDERR_FILENO,{real:2,filetype:WASI_FILETYPE_CHARACTER_DEVICE,rights:{base:STDERR_DEFAULT_RIGHTS,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; |
import { BigIntPolyfillType } from "./polyfills/bigint"; | ||
import { DataViewPolyfillType } from "./polyfills/dataview"; | ||
import { WASI_FILETYPE } from "./constants"; | ||
interface Rights { | ||
@@ -10,3 +11,3 @@ base: BigIntPolyfillType; | ||
offset?: bigint; | ||
filetype?: any; | ||
filetype?: WASI_FILETYPE; | ||
rights: Rights; | ||
@@ -13,0 +14,0 @@ path?: any; |
@@ -50,2 +50,15 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const STDIN_DEFAULT_RIGHTS = constants_1.WASI_RIGHT_FD_DATASYNC | ||
| constants_1.WASI_RIGHT_FD_READ | ||
| constants_1.WASI_RIGHT_FD_SYNC | ||
| constants_1.WASI_RIGHT_FD_ADVISE | ||
| constants_1.WASI_RIGHT_FD_FILESTAT_GET | ||
| constants_1.WASI_RIGHT_POLL_FD_READWRITE; | ||
const STDOUT_DEFAULT_RIGHTS = constants_1.WASI_RIGHT_FD_DATASYNC | ||
| constants_1.WASI_RIGHT_FD_WRITE | ||
| constants_1.WASI_RIGHT_FD_SYNC | ||
| constants_1.WASI_RIGHT_FD_ADVISE | ||
| constants_1.WASI_RIGHT_FD_FILESTAT_GET | ||
| constants_1.WASI_RIGHT_POLL_FD_READWRITE; | ||
const STDERR_DEFAULT_RIGHTS = STDOUT_DEFAULT_RIGHTS; | ||
const msToNs = (ms) => { | ||
@@ -210,6 +223,6 @@ const msInt = Math.trunc(ms); | ||
real: 0, | ||
filetype: undefined, | ||
filetype: constants_1.WASI_FILETYPE_CHARACTER_DEVICE, | ||
// offset: BigInt(0), | ||
rights: { | ||
base: constants_1.RIGHTS_REGULAR_FILE_BASE, | ||
base: STDIN_DEFAULT_RIGHTS, | ||
inheriting: bigint_1.BigIntPolyfill(0) | ||
@@ -224,6 +237,6 @@ }, | ||
real: 1, | ||
filetype: undefined, | ||
filetype: constants_1.WASI_FILETYPE_CHARACTER_DEVICE, | ||
// offset: BigInt(0), | ||
rights: { | ||
base: constants_1.RIGHTS_REGULAR_FILE_BASE, | ||
base: STDOUT_DEFAULT_RIGHTS, | ||
inheriting: bigint_1.BigIntPolyfill(0) | ||
@@ -238,6 +251,6 @@ }, | ||
real: 2, | ||
filetype: undefined, | ||
filetype: constants_1.WASI_FILETYPE_CHARACTER_DEVICE, | ||
// offset: BigInt(0), | ||
rights: { | ||
base: constants_1.RIGHTS_REGULAR_FILE_BASE, | ||
base: STDERR_DEFAULT_RIGHTS, | ||
inheriting: bigint_1.BigIntPolyfill(0) | ||
@@ -244,0 +257,0 @@ }, |
@@ -111,2 +111,3 @@ export declare const WASI_ESUCCESS = 0; | ||
export declare const WASI_FILETYPE_SYMBOLIC_LINK = 7; | ||
export declare type WASI_FILETYPE = typeof WASI_FILETYPE_UNKNOWN | typeof WASI_FILETYPE_BLOCK_DEVICE | typeof WASI_FILETYPE_CHARACTER_DEVICE | typeof WASI_FILETYPE_DIRECTORY | typeof WASI_FILETYPE_REGULAR_FILE | typeof WASI_FILETYPE_SOCKET_DGRAM | typeof WASI_FILETYPE_SOCKET_STREAM | typeof WASI_FILETYPE_SYMBOLIC_LINK; | ||
export declare const WASI_FDFLAG_APPEND = 1; | ||
@@ -113,0 +114,0 @@ export declare const WASI_FDFLAG_DSYNC = 2; |
import { BigIntPolyfillType } from "./polyfills/bigint"; | ||
import { DataViewPolyfillType } from "./polyfills/dataview"; | ||
import { WASI_FILETYPE } from "./constants"; | ||
interface Rights { | ||
@@ -10,3 +11,3 @@ base: BigIntPolyfillType; | ||
offset?: bigint; | ||
filetype?: any; | ||
filetype?: WASI_FILETYPE; | ||
rights: Rights; | ||
@@ -13,0 +14,0 @@ path?: any; |
{ | ||
"name": "@wasmer/wasi", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚", | ||
@@ -53,3 +53,3 @@ "main": "lib/index.cjs.js", | ||
}, | ||
"gitHead": "d8b174aaeb62b0d293a30479322fe493ce872551" | ||
"gitHead": "e726cd61fc4b59c9dd5c7609b80b7235c454d7b3" | ||
} |
@@ -5,2 +5,4 @@ # `@wasmer/wasi` | ||
Documentation for Wasmer-JS Stack can be found on the [Wasmer Docs](https://docs.wasmer.io/wasmer-js/wasmer-js). | ||
## Table of Contents | ||
@@ -75,78 +77,6 @@ | ||
For a larger end-to-end example, please see the [wasm-terminal package](https://github.com/wasmerio/wasmer-js/tree/master/packages/wasm-terminal). | ||
## Reference API | ||
`new WASI(wasiConfigObject)` | ||
The Reference API Documentation can be found on the [`@wasmer/wasi` Reference API Wasmer Docs](https://docs.wasmer.io/wasmer-js/reference-api/wasmer-js-reference-api-wasi). | ||
Constructs a new WASI instance. | ||
The Config object is is as follows: | ||
```js | ||
let myWASIInstance = new WASI({ | ||
// OPTIONAL: The pre-opened dirctories | ||
preopens: {}, | ||
// OPTIONAL: The environment vars | ||
env: {}, | ||
// OPTIONAL: The arguments provided | ||
args: [], | ||
// OPTIONAL: The environment bindings (fs, path), | ||
// useful for using WASI in diferent environments | ||
// such as Node.js, Browsers, ... | ||
bindings: { | ||
// hrtime: WASI.defaultConfig.bindings.hrtime, | ||
// exit: WASI.defaultConfig.bindings.exit, | ||
// kill: WASI.defaultConfig.bindings.kill, | ||
// randomFillSync: WASI.defaultConfig.bindings.randomFillSync, | ||
// isTTY: WASI.defaultConfig.bindings.isTTY, | ||
// fs: WASI.defaultConfig.bindings.fs, | ||
// path: WASI.defaultConfig.bindings.path, | ||
...WASI.defaultConfig.bindings | ||
} | ||
}); | ||
``` | ||
And returns a WASI Instance: | ||
```js | ||
console.log(myWASIInstance); | ||
/* | ||
Would Output: | ||
{ | ||
memory: WebAssembly.Memory; | ||
view: DataView; | ||
FD_MAP: Map<number, File>; | ||
exports: Exports; // WASI API to be imported in the importObject on instantiation. | ||
bindings: WASIBindings; | ||
start: (wasmInstance: WebAssembly.Instance) => void; // Function that takes in a WASI WebAssembly Instance and starts it. | ||
} | ||
*/ | ||
``` | ||
--- | ||
`WASI.defaultBindings` | ||
The [default bindings](./lib/bindings) for the environment that are set on the `bindings` property of the constructor config object. This is useful for use cases like, you want to plugin in your own file system. For example: | ||
```js | ||
const myFs = require("fs"); | ||
let wasi = new WASI({ | ||
preopens: {}, | ||
env: {}, | ||
args: [], | ||
bindings: { | ||
fs: myFs, | ||
...WASI.defaultBindings | ||
} | ||
}); | ||
``` | ||
## Contributing | ||
@@ -153,0 +83,0 @@ |
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
278675
43
3200
85