@wasmer/wasi
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -16,7 +16,69 @@ /* | ||
*****************************************************************************/ | ||
'use strict';var extendStatics=function(e,c){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,d){c.__proto__=d}||function(c,d){for(var e in d)d.hasOwnProperty(e)&&(c[e]=d[e])};return extendStatics(e,c)};function __extends(e,c){function f(){this.constructor=e}extendStatics(e,c);e.prototype=null===c?Object.create(c):(f.prototype=c.prototype,new f)} | ||
function __values(e){var c="function"===typeof Symbol&&e[Symbol.iterator],f=0;return c?c.call(e):{next:function(){e&&f>=e.length&&(e=void 0);return{value:e&&e[f++],done:!e}}}}function __read(e,c){var f="function"===typeof Symbol&&e[Symbol.iterator];if(!f)return e;e=f.call(e);var d,x=[];try{for(;(void 0===c||0<c--)&&!(d=e.next()).done;)x.push(d.value)}catch(v){var w={error:v}}finally{try{d&&!d.done&&(f=e["return"])&&f.call(e)}finally{if(w)throw w.error;}}return x} | ||
function __spread(){for(var e=[],c=0;c<arguments.length;c++)e=e.concat(__read(arguments[c]));return e}var exportedBigInt=Number,globalThis={BigInt:{}};globalThis=global;globalThis.BigInt&&(exportedBigInt=globalThis.BigInt);var BigIntPolyfill=exportedBigInt,exportedDataView=DataView;exportedDataView.prototype.setBigUint64||(exportedDataView.prototype.setBigUint64=function(e,c,f){this.setUint32(f?0:4,c,f);this.setUint32(f?4:0,0,f)}); | ||
var DataViewPolyfill=exportedDataView,NS_PER_SEC=1E9,getBigIntHrtime=function(e){var c=e();return function(f){f=e(f||c);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';var extendStatics=function(a,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,b){a.__proto__=b}||function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])};return extendStatics(a,b)};function __extends(a,b){function c(){this.constructor=a}extendStatics(a,b);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)} | ||
function __values(a){var b="function"===typeof Symbol&&a[Symbol.iterator],c=0;return b?b.call(a):{next:function(){a&&c>=a.length&&(a=void 0);return{value:a&&a[c++],done:!a}}}}function __read(a,b){var c="function"===typeof Symbol&&a[Symbol.iterator];if(!c)return a;a=c.call(a);var d,e=[];try{for(;(void 0===b||0<b--)&&!(d=a.next()).done;)e.push(d.value)}catch(g){var f={error:g}}finally{try{d&&!d.done&&(c=a["return"])&&c.call(a)}finally{if(f)throw f.error;}}return e} | ||
function __spread(){for(var a=[],b=0;b<arguments.length;b++)a=a.concat(__read(arguments[b]));return a}var exportedBigInt=Number,globalThis={BigInt:{}};globalThis=global;globalThis.BigInt&&(exportedBigInt=globalThis.BigInt);var BigIntPolyfill=exportedBigInt,exportedDataView=DataView;exportedDataView.prototype.setBigUint64||(exportedDataView.prototype.setBigUint64=function(a,b,c){this.setUint32(c?0:4,b,c);this.setUint32(c?4:0,0,c)}); | ||
var DataViewPolyfill=exportedDataView,global$1="undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{},lookup=[],revLookup=[],Arr="undefined"!==typeof Uint8Array?Uint8Array:Array,inited=!1;function init(){inited=!0;for(var a=0;64>a;++a)lookup[a]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a],revLookup["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(a)]=a;revLookup[45]=62;revLookup[95]=63} | ||
function toByteArray(a){inited||init();var b=a.length;if(0<b%4)throw Error("Invalid string. Length must be a multiple of 4");var c="="===a[b-2]?2:"="===a[b-1]?1:0;var d=new Arr(3*b/4-c);var e=0<c?b-4:b;var f=0;for(b=0;b<e;b+=4){var g=revLookup[a.charCodeAt(b)]<<18|revLookup[a.charCodeAt(b+1)]<<12|revLookup[a.charCodeAt(b+2)]<<6|revLookup[a.charCodeAt(b+3)];d[f++]=g>>16&255;d[f++]=g>>8&255;d[f++]=g&255}2===c?(g=revLookup[a.charCodeAt(b)]<<2|revLookup[a.charCodeAt(b+1)]>>4,d[f++]=g&255):1===c&&(g=revLookup[a.charCodeAt(b)]<< | ||
10|revLookup[a.charCodeAt(b+1)]<<4|revLookup[a.charCodeAt(b+2)]>>2,d[f++]=g>>8&255,d[f++]=g&255);return d}function tripletToBase64(a){return lookup[a>>18&63]+lookup[a>>12&63]+lookup[a>>6&63]+lookup[a&63]}function encodeChunk(a,b,c){for(var d=[],e=b;e<c;e+=3)b=(a[e]<<16)+(a[e+1]<<8)+a[e+2],d.push(tripletToBase64(b));return d.join("")} | ||
function fromByteArray(a){inited||init();for(var b=a.length,c=b%3,d="",e=[],f=0,g=b-c;f<g;f+=16383)e.push(encodeChunk(a,f,f+16383>g?g:f+16383));1===c?(a=a[b-1],d+=lookup[a>>2],d+=lookup[a<<4&63],d+="=="):2===c&&(a=(a[b-2]<<8)+a[b-1],d+=lookup[a>>10],d+=lookup[a>>4&63],d+=lookup[a<<2&63],d+="=");e.push(d);return e.join("")} | ||
function read(a,b,c,d,e){var f=8*e-d-1;var g=(1<<f)-1,k=g>>1,h=-7;e=c?e-1:0;var n=c?-1:1,q=a[b+e];e+=n;c=q&(1<<-h)-1;q>>=-h;for(h+=f;0<h;c=256*c+a[b+e],e+=n,h-=8);f=c&(1<<-h)-1;c>>=-h;for(h+=d;0<h;f=256*f+a[b+e],e+=n,h-=8);if(0===c)c=1-k;else{if(c===g)return f?NaN:Infinity*(q?-1:1);f+=Math.pow(2,d);c-=k}return(q?-1:1)*f*Math.pow(2,c-d)} | ||
function write(a,b,c,d,e,f){var g,k=8*f-e-1,h=(1<<k)-1,n=h>>1,q=23===e?Math.pow(2,-24)-Math.pow(2,-77):0;f=d?0:f-1;var t=d?1:-1,u=0>b||0===b&&0>1/b?1:0;b=Math.abs(b);isNaN(b)||Infinity===b?(b=isNaN(b)?1:0,d=h):(d=Math.floor(Math.log(b)/Math.LN2),1>b*(g=Math.pow(2,-d))&&(d--,g*=2),b=1<=d+n?b+q/g:b+q*Math.pow(2,1-n),2<=b*g&&(d++,g/=2),d+n>=h?(b=0,d=h):1<=d+n?(b=(b*g-1)*Math.pow(2,e),d+=n):(b=b*Math.pow(2,n-1)*Math.pow(2,e),d=0));for(;8<=e;a[c+f]=b&255,f+=t,b/=256,e-=8);d=d<<e|b;for(k+=e;0<k;a[c+f]= | ||
d&255,f+=t,d/=256,k-=8);a[c+f-t]|=128*u}var toString={}.toString,isArray=Array.isArray||function(a){return"[object Array]"==toString.call(a)},INSPECT_MAX_BYTES=50;Buffer.TYPED_ARRAY_SUPPORT=void 0!==global$1.TYPED_ARRAY_SUPPORT?global$1.TYPED_ARRAY_SUPPORT:!0;function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823} | ||
function createBuffer(a,b){if(kMaxLength()<b)throw new RangeError("Invalid typed array length");Buffer.TYPED_ARRAY_SUPPORT?(a=new Uint8Array(b),a.__proto__=Buffer.prototype):(null===a&&(a=new Buffer(b)),a.length=b);return a} | ||
function Buffer(a,b,c){if(!(Buffer.TYPED_ARRAY_SUPPORT||this instanceof Buffer))return new Buffer(a,b,c);if("number"===typeof a){if("string"===typeof b)throw Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,a)}return from(this,a,b,c)}Buffer.poolSize=8192;Buffer._augment=function(a){a.__proto__=Buffer.prototype;return a}; | ||
function from(a,b,c,d){if("number"===typeof b)throw new TypeError('"value" argument must not be a number');return"undefined"!==typeof ArrayBuffer&&b instanceof ArrayBuffer?fromArrayBuffer(a,b,c,d):"string"===typeof b?fromString(a,b,c):fromObject(a,b)}Buffer.from=function(a,b,c){return from(null,a,b,c)};Buffer.TYPED_ARRAY_SUPPORT&&(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array); | ||
function assertSize(a){if("number"!==typeof a)throw new TypeError('"size" argument must be a number');if(0>a)throw new RangeError('"size" argument must not be negative');}function alloc(a,b,c,d){assertSize(b);return 0>=b?createBuffer(a,b):void 0!==c?"string"===typeof d?createBuffer(a,b).fill(c,d):createBuffer(a,b).fill(c):createBuffer(a,b)}Buffer.alloc=function(a,b,c){return alloc(null,a,b,c)}; | ||
function allocUnsafe(a,b){assertSize(b);a=createBuffer(a,0>b?0:checked(b)|0);if(!Buffer.TYPED_ARRAY_SUPPORT)for(var c=0;c<b;++c)a[c]=0;return a}Buffer.allocUnsafe=function(a){return allocUnsafe(null,a)};Buffer.allocUnsafeSlow=function(a){return allocUnsafe(null,a)}; | ||
function fromString(a,b,c){if("string"!==typeof c||""===c)c="utf8";if(!Buffer.isEncoding(c))throw new TypeError('"encoding" must be a valid string encoding');var d=byteLength(b,c)|0;a=createBuffer(a,d);b=a.write(b,c);b!==d&&(a=a.slice(0,b));return a}function fromArrayLike(a,b){var c=0>b.length?0:checked(b.length)|0;a=createBuffer(a,c);for(var d=0;d<c;d+=1)a[d]=b[d]&255;return a} | ||
function fromArrayBuffer(a,b,c,d){b.byteLength;if(0>c||b.byteLength<c)throw new RangeError("'offset' is out of bounds");if(b.byteLength<c+(d||0))throw new RangeError("'length' is out of bounds");b=void 0===c&&void 0===d?new Uint8Array(b):void 0===d?new Uint8Array(b,c):new Uint8Array(b,c,d);Buffer.TYPED_ARRAY_SUPPORT?(a=b,a.__proto__=Buffer.prototype):a=fromArrayLike(a,b);return a} | ||
function fromObject(a,b){if(internalIsBuffer(b)){var c=checked(b.length)|0;a=createBuffer(a,c);if(0===a.length)return a;b.copy(a,0,0,c);return a}if(b){if("undefined"!==typeof ArrayBuffer&&b.buffer instanceof ArrayBuffer||"length"in b)return"number"!==typeof b.length||isnan(b.length)?createBuffer(a,0):fromArrayLike(a,b);if("Buffer"===b.type&&isArray(b.data))return fromArrayLike(a,b.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");} | ||
function checked(a){if(a>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return a|0}Buffer.isBuffer=isBuffer;function internalIsBuffer(a){return!(null==a||!a._isBuffer)} | ||
Buffer.compare=function(a,b){if(!internalIsBuffer(a)||!internalIsBuffer(b))throw new TypeError("Arguments must be Buffers");if(a===b)return 0;for(var c=a.length,d=b.length,e=0,f=Math.min(c,d);e<f;++e)if(a[e]!==b[e]){c=a[e];d=b[e];break}return c<d?-1:d<c?1:0};Buffer.isEncoding=function(a){switch(String(a).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "latin1":case "binary":case "base64":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return!0;default:return!1}}; | ||
Buffer.concat=function(a,b){if(!isArray(a))throw new TypeError('"list" argument must be an Array of Buffers');if(0===a.length)return Buffer.alloc(0);var c;if(void 0===b)for(c=b=0;c<a.length;++c)b+=a[c].length;b=Buffer.allocUnsafe(b);var d=0;for(c=0;c<a.length;++c){var e=a[c];if(!internalIsBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(b,d);d+=e.length}return b}; | ||
function byteLength(a,b){if(internalIsBuffer(a))return a.length;if("undefined"!==typeof ArrayBuffer&&"function"===typeof ArrayBuffer.isView&&(ArrayBuffer.isView(a)||a instanceof ArrayBuffer))return a.byteLength;"string"!==typeof a&&(a=""+a);var c=a.length;if(0===c)return 0;for(var d=!1;;)switch(b){case "ascii":case "latin1":case "binary":return c;case "utf8":case "utf-8":case void 0:return utf8ToBytes(a).length;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return 2*c;case "hex":return c>>> | ||
1;case "base64":return base64ToBytes(a).length;default:if(d)return utf8ToBytes(a).length;b=(""+b).toLowerCase();d=!0}}Buffer.byteLength=byteLength; | ||
function slowToString(a,b,c){var d=!1;if(void 0===b||0>b)b=0;if(b>this.length)return"";if(void 0===c||c>this.length)c=this.length;if(0>=c)return"";c>>>=0;b>>>=0;if(c<=b)return"";for(a||(a="utf8");;)switch(a){case "hex":return hexSlice(this,b,c);case "utf8":case "utf-8":return utf8Slice(this,b,c);case "ascii":return asciiSlice(this,b,c);case "latin1":case "binary":return latin1Slice(this,b,c);case "base64":return base64Slice(this,b,c);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return utf16leSlice(this, | ||
b,c);default:if(d)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase();d=!0}}Buffer.prototype._isBuffer=!0;function swap(a,b,c){var d=a[b];a[b]=a[c];a[c]=d}Buffer.prototype.swap16=function(){var a=this.length;if(0!==a%2)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var b=0;b<a;b+=2)swap(this,b,b+1);return this}; | ||
Buffer.prototype.swap32=function(){var a=this.length;if(0!==a%4)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var b=0;b<a;b+=4)swap(this,b,b+3),swap(this,b+1,b+2);return this};Buffer.prototype.swap64=function(){var a=this.length;if(0!==a%8)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var b=0;b<a;b+=8)swap(this,b,b+7),swap(this,b+1,b+6),swap(this,b+2,b+5),swap(this,b+3,b+4);return this}; | ||
Buffer.prototype.toString=function(){var a=this.length|0;return 0===a?"":0===arguments.length?utf8Slice(this,0,a):slowToString.apply(this,arguments)};Buffer.prototype.equals=function(a){if(!internalIsBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?!0:0===Buffer.compare(this,a)};Buffer.prototype.inspect=function(){var a="",b=INSPECT_MAX_BYTES;0<this.length&&(a=this.toString("hex",0,b).match(/.{2}/g).join(" "),this.length>b&&(a+=" ... "));return"<Buffer "+a+">"}; | ||
Buffer.prototype.compare=function(a,b,c,d,e){if(!internalIsBuffer(a))throw new TypeError("Argument must be a Buffer");void 0===b&&(b=0);void 0===c&&(c=a?a.length:0);void 0===d&&(d=0);void 0===e&&(e=this.length);if(0>b||c>a.length||0>d||e>this.length)throw new RangeError("out of range index");if(d>=e&&b>=c)return 0;if(d>=e)return-1;if(b>=c)return 1;b>>>=0;c>>>=0;d>>>=0;e>>>=0;if(this===a)return 0;var f=e-d,g=c-b,k=Math.min(f,g);d=this.slice(d,e);a=a.slice(b,c);for(b=0;b<k;++b)if(d[b]!==a[b]){f=d[b]; | ||
g=a[b];break}return f<g?-1:g<f?1:0}; | ||
function bidirectionalIndexOf(a,b,c,d,e){if(0===a.length)return-1;"string"===typeof c?(d=c,c=0):2147483647<c?c=2147483647:-2147483648>c&&(c=-2147483648);c=+c;isNaN(c)&&(c=e?0:a.length-1);0>c&&(c=a.length+c);if(c>=a.length){if(e)return-1;c=a.length-1}else if(0>c)if(e)c=0;else return-1;"string"===typeof b&&(b=Buffer.from(b,d));if(internalIsBuffer(b))return 0===b.length?-1:arrayIndexOf(a,b,c,d,e);if("number"===typeof b)return b&=255,Buffer.TYPED_ARRAY_SUPPORT&&"function"===typeof Uint8Array.prototype.indexOf? | ||
e?Uint8Array.prototype.indexOf.call(a,b,c):Uint8Array.prototype.lastIndexOf.call(a,b,c):arrayIndexOf(a,[b],c,d,e);throw new TypeError("val must be string, number or Buffer");} | ||
function arrayIndexOf(a,b,c,d,e){function f(a,b){return 1===g?a[b]:a.readUInt16BE(b*g)}var g=1,k=a.length,h=b.length;if(void 0!==d&&(d=String(d).toLowerCase(),"ucs2"===d||"ucs-2"===d||"utf16le"===d||"utf-16le"===d)){if(2>a.length||2>b.length)return-1;g=2;k/=2;h/=2;c/=2}if(e)for(d=-1;c<k;c++)if(f(a,c)===f(b,-1===d?0:c-d)){if(-1===d&&(d=c),c-d+1===h)return d*g}else-1!==d&&(c-=c-d),d=-1;else for(c+h>k&&(c=k-h);0<=c;c--){k=!0;for(d=0;d<h;d++)if(f(a,c+d)!==f(b,d)){k=!1;break}if(k)return c}return-1} | ||
Buffer.prototype.includes=function(a,b,c){return-1!==this.indexOf(a,b,c)};Buffer.prototype.indexOf=function(a,b,c){return bidirectionalIndexOf(this,a,b,c,!0)};Buffer.prototype.lastIndexOf=function(a,b,c){return bidirectionalIndexOf(this,a,b,c,!1)}; | ||
function hexWrite(a,b,c,d){c=Number(c)||0;var e=a.length-c;d?(d=Number(d),d>e&&(d=e)):d=e;e=b.length;if(0!==e%2)throw new TypeError("Invalid hex string");d>e/2&&(d=e/2);for(e=0;e<d;++e){var f=parseInt(b.substr(2*e,2),16);if(isNaN(f))break;a[c+e]=f}return e}function utf8Write(a,b,c,d){return blitBuffer(utf8ToBytes(b,a.length-c),a,c,d)}function asciiWrite(a,b,c,d){return blitBuffer(asciiToBytes(b),a,c,d)}function latin1Write(a,b,c,d){return asciiWrite(a,b,c,d)} | ||
function base64Write(a,b,c,d){return blitBuffer(base64ToBytes(b),a,c,d)}function ucs2Write(a,b,c,d){return blitBuffer(utf16leToBytes(b,a.length-c),a,c,d)} | ||
Buffer.prototype.write=function(a,b,c,d){if(void 0===b)d="utf8",c=this.length,b=0;else if(void 0===c&&"string"===typeof b)d=b,c=this.length,b=0;else if(isFinite(b))b|=0,isFinite(c)?(c|=0,void 0===d&&(d="utf8")):(d=c,c=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var e=this.length-b;if(void 0===c||c>e)c=e;if(0<a.length&&(0>c||0>b)||b>this.length)throw new RangeError("Attempt to write outside buffer bounds");d||(d="utf8");for(e=!1;;)switch(d){case "hex":return hexWrite(this, | ||
a,b,c);case "utf8":case "utf-8":return utf8Write(this,a,b,c);case "ascii":return asciiWrite(this,a,b,c);case "latin1":case "binary":return latin1Write(this,a,b,c);case "base64":return base64Write(this,a,b,c);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return ucs2Write(this,a,b,c);default:if(e)throw new TypeError("Unknown encoding: "+d);d=(""+d).toLowerCase();e=!0}};Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}}; | ||
function base64Slice(a,b,c){return 0===b&&c===a.length?fromByteArray(a):fromByteArray(a.slice(b,c))} | ||
function utf8Slice(a,b,c){c=Math.min(a.length,c);for(var d=[];b<c;){var e=a[b],f=null,g=239<e?4:223<e?3:191<e?2:1;if(b+g<=c)switch(g){case 1:128>e&&(f=e);break;case 2:var k=a[b+1];128===(k&192)&&(e=(e&31)<<6|k&63,127<e&&(f=e));break;case 3:k=a[b+1];var h=a[b+2];128===(k&192)&&128===(h&192)&&(e=(e&15)<<12|(k&63)<<6|h&63,2047<e&&(55296>e||57343<e)&&(f=e));break;case 4:k=a[b+1];h=a[b+2];var n=a[b+3];128===(k&192)&&128===(h&192)&&128===(n&192)&&(e=(e&15)<<18|(k&63)<<12|(h&63)<<6|n&63,65535<e&&1114112> | ||
e&&(f=e))}null===f?(f=65533,g=1):65535<f&&(f-=65536,d.push(f>>>10&1023|55296),f=56320|f&1023);d.push(f);b+=g}return decodeCodePointsArray(d)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(a){var b=a.length;if(b<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,a);for(var c="",d=0;d<b;)c+=String.fromCharCode.apply(String,a.slice(d,d+=MAX_ARGUMENTS_LENGTH));return c} | ||
function asciiSlice(a,b,c){var d="";for(c=Math.min(a.length,c);b<c;++b)d+=String.fromCharCode(a[b]&127);return d}function latin1Slice(a,b,c){var d="";for(c=Math.min(a.length,c);b<c;++b)d+=String.fromCharCode(a[b]);return d}function hexSlice(a,b,c){var d=a.length;if(!b||0>b)b=0;if(!c||0>c||c>d)c=d;for(d="";b<c;++b)d+=toHex(a[b]);return d}function utf16leSlice(a,b,c){a=a.slice(b,c);b="";for(c=0;c<a.length;c+=2)b+=String.fromCharCode(a[c]+256*a[c+1]);return b} | ||
Buffer.prototype.slice=function(a,b){var c=this.length;a=~~a;b=void 0===b?c:~~b;0>a?(a+=c,0>a&&(a=0)):a>c&&(a=c);0>b?(b+=c,0>b&&(b=0)):b>c&&(b=c);b<a&&(b=a);if(Buffer.TYPED_ARRAY_SUPPORT)b=this.subarray(a,b),b.__proto__=Buffer.prototype;else{c=b-a;b=new Buffer(c,void 0);for(var d=0;d<c;++d)b[d]=this[d+a]}return b};function checkOffset(a,b,c){if(0!==a%1||0>a)throw new RangeError("offset is not uint");if(a+b>c)throw new RangeError("Trying to access beyond buffer length");} | ||
Buffer.prototype.readUIntLE=function(a,b,c){a|=0;b|=0;c||checkOffset(a,b,this.length);c=this[a];for(var d=1,e=0;++e<b&&(d*=256);)c+=this[a+e]*d;return c};Buffer.prototype.readUIntBE=function(a,b,c){a|=0;b|=0;c||checkOffset(a,b,this.length);c=this[a+--b];for(var d=1;0<b&&(d*=256);)c+=this[a+--b]*d;return c};Buffer.prototype.readUInt8=function(a,b){b||checkOffset(a,1,this.length);return this[a]};Buffer.prototype.readUInt16LE=function(a,b){b||checkOffset(a,2,this.length);return this[a]|this[a+1]<<8}; | ||
Buffer.prototype.readUInt16BE=function(a,b){b||checkOffset(a,2,this.length);return this[a]<<8|this[a+1]};Buffer.prototype.readUInt32LE=function(a,b){b||checkOffset(a,4,this.length);return(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]};Buffer.prototype.readUInt32BE=function(a,b){b||checkOffset(a,4,this.length);return 16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])}; | ||
Buffer.prototype.readIntLE=function(a,b,c){a|=0;b|=0;c||checkOffset(a,b,this.length);c=this[a];for(var d=1,e=0;++e<b&&(d*=256);)c+=this[a+e]*d;c>=128*d&&(c-=Math.pow(2,8*b));return c};Buffer.prototype.readIntBE=function(a,b,c){a|=0;b|=0;c||checkOffset(a,b,this.length);c=b;for(var d=1,e=this[a+--c];0<c&&(d*=256);)e+=this[a+--c]*d;e>=128*d&&(e-=Math.pow(2,8*b));return e};Buffer.prototype.readInt8=function(a,b){b||checkOffset(a,1,this.length);return this[a]&128?-1*(255-this[a]+1):this[a]}; | ||
Buffer.prototype.readInt16LE=function(a,b){b||checkOffset(a,2,this.length);a=this[a]|this[a+1]<<8;return a&32768?a|4294901760:a};Buffer.prototype.readInt16BE=function(a,b){b||checkOffset(a,2,this.length);a=this[a+1]|this[a]<<8;return a&32768?a|4294901760:a};Buffer.prototype.readInt32LE=function(a,b){b||checkOffset(a,4,this.length);return this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24}; | ||
Buffer.prototype.readInt32BE=function(a,b){b||checkOffset(a,4,this.length);return this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]};Buffer.prototype.readFloatLE=function(a,b){b||checkOffset(a,4,this.length);return read(this,a,!0,23,4)};Buffer.prototype.readFloatBE=function(a,b){b||checkOffset(a,4,this.length);return read(this,a,!1,23,4)};Buffer.prototype.readDoubleLE=function(a,b){b||checkOffset(a,8,this.length);return read(this,a,!0,52,8)}; | ||
Buffer.prototype.readDoubleBE=function(a,b){b||checkOffset(a,8,this.length);return read(this,a,!1,52,8)};function checkInt(a,b,c,d,e,f){if(!internalIsBuffer(a))throw new TypeError('"buffer" argument must be a Buffer instance');if(b>e||b<f)throw new RangeError('"value" argument is out of bounds');if(c+d>a.length)throw new RangeError("Index out of range");} | ||
Buffer.prototype.writeUIntLE=function(a,b,c,d){a=+a;b|=0;c|=0;d||checkInt(this,a,b,c,Math.pow(2,8*c)-1,0);d=1;var e=0;for(this[b]=a&255;++e<c&&(d*=256);)this[b+e]=a/d&255;return b+c};Buffer.prototype.writeUIntBE=function(a,b,c,d){a=+a;b|=0;c|=0;d||checkInt(this,a,b,c,Math.pow(2,8*c)-1,0);d=c-1;var e=1;for(this[b+d]=a&255;0<=--d&&(e*=256);)this[b+d]=a/e&255;return b+c}; | ||
Buffer.prototype.writeUInt8=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,1,255,0);Buffer.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));this[b]=a&255;return b+1};function objectWriteUInt16(a,b,c,d){0>b&&(b=65535+b+1);for(var e=0,f=Math.min(a.length-c,2);e<f;++e)a[c+e]=(b&255<<8*(d?e:1-e))>>>8*(d?e:1-e)}Buffer.prototype.writeUInt16LE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,2,65535,0);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a&255,this[b+1]=a>>>8):objectWriteUInt16(this,a,b,!0);return b+2}; | ||
Buffer.prototype.writeUInt16BE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,2,65535,0);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a&255):objectWriteUInt16(this,a,b,!1);return b+2};function objectWriteUInt32(a,b,c,d){0>b&&(b=4294967295+b+1);for(var e=0,f=Math.min(a.length-c,4);e<f;++e)a[c+e]=b>>>8*(d?e:3-e)&255} | ||
Buffer.prototype.writeUInt32LE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,4,4294967295,0);Buffer.TYPED_ARRAY_SUPPORT?(this[b+3]=a>>>24,this[b+2]=a>>>16,this[b+1]=a>>>8,this[b]=a&255):objectWriteUInt32(this,a,b,!0);return b+4};Buffer.prototype.writeUInt32BE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,4,4294967295,0);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a&255):objectWriteUInt32(this,a,b,!1);return b+4}; | ||
Buffer.prototype.writeIntLE=function(a,b,c,d){a=+a;b|=0;d||(d=Math.pow(2,8*c-1),checkInt(this,a,b,c,d-1,-d));d=0;var e=1,f=0;for(this[b]=a&255;++d<c&&(e*=256);)0>a&&0===f&&0!==this[b+d-1]&&(f=1),this[b+d]=(a/e>>0)-f&255;return b+c};Buffer.prototype.writeIntBE=function(a,b,c,d){a=+a;b|=0;d||(d=Math.pow(2,8*c-1),checkInt(this,a,b,c,d-1,-d));d=c-1;var e=1,f=0;for(this[b+d]=a&255;0<=--d&&(e*=256);)0>a&&0===f&&0!==this[b+d+1]&&(f=1),this[b+d]=(a/e>>0)-f&255;return b+c}; | ||
Buffer.prototype.writeInt8=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,1,127,-128);Buffer.TYPED_ARRAY_SUPPORT||(a=Math.floor(a));0>a&&(a=255+a+1);this[b]=a&255;return b+1};Buffer.prototype.writeInt16LE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,2,32767,-32768);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a&255,this[b+1]=a>>>8):objectWriteUInt16(this,a,b,!0);return b+2}; | ||
Buffer.prototype.writeInt16BE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,2,32767,-32768);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a>>>8,this[b+1]=a&255):objectWriteUInt16(this,a,b,!1);return b+2};Buffer.prototype.writeInt32LE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,4,2147483647,-2147483648);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a&255,this[b+1]=a>>>8,this[b+2]=a>>>16,this[b+3]=a>>>24):objectWriteUInt32(this,a,b,!0);return b+4}; | ||
Buffer.prototype.writeInt32BE=function(a,b,c){a=+a;b|=0;c||checkInt(this,a,b,4,2147483647,-2147483648);0>a&&(a=4294967295+a+1);Buffer.TYPED_ARRAY_SUPPORT?(this[b]=a>>>24,this[b+1]=a>>>16,this[b+2]=a>>>8,this[b+3]=a&255):objectWriteUInt32(this,a,b,!1);return b+4};function checkIEEE754(a,b,c,d,e,f){if(c+d>a.length)throw new RangeError("Index out of range");if(0>c)throw new RangeError("Index out of range");}function writeFloat(a,b,c,d,e){e||checkIEEE754(a,b,c,4);write(a,b,c,d,23,4);return c+4} | ||
Buffer.prototype.writeFloatLE=function(a,b,c){return writeFloat(this,a,b,!0,c)};Buffer.prototype.writeFloatBE=function(a,b,c){return writeFloat(this,a,b,!1,c)};function writeDouble(a,b,c,d,e){e||checkIEEE754(a,b,c,8);write(a,b,c,d,52,8);return c+8}Buffer.prototype.writeDoubleLE=function(a,b,c){return writeDouble(this,a,b,!0,c)};Buffer.prototype.writeDoubleBE=function(a,b,c){return writeDouble(this,a,b,!1,c)}; | ||
Buffer.prototype.copy=function(a,b,c,d){c||(c=0);d||0===d||(d=this.length);b>=a.length&&(b=a.length);b||(b=0);0<d&&d<c&&(d=c);if(d===c||0===a.length||0===this.length)return 0;if(0>b)throw new RangeError("targetStart out of bounds");if(0>c||c>=this.length)throw new RangeError("sourceStart out of bounds");if(0>d)throw new RangeError("sourceEnd out of bounds");d>this.length&&(d=this.length);a.length-b<d-c&&(d=a.length-b+c);var e=d-c;if(this===a&&c<b&&b<d)for(d=e-1;0<=d;--d)a[d+b]=this[d+c];else if(1E3> | ||
e||!Buffer.TYPED_ARRAY_SUPPORT)for(d=0;d<e;++d)a[d+b]=this[d+c];else Uint8Array.prototype.set.call(a,this.subarray(c,c+e),b);return e}; | ||
Buffer.prototype.fill=function(a,b,c,d){if("string"===typeof a){"string"===typeof b?(d=b,b=0,c=this.length):"string"===typeof c&&(d=c,c=this.length);if(1===a.length){var e=a.charCodeAt(0);256>e&&(a=e)}if(void 0!==d&&"string"!==typeof d)throw new TypeError("encoding must be a string");if("string"===typeof d&&!Buffer.isEncoding(d))throw new TypeError("Unknown encoding: "+d);}else"number"===typeof a&&(a&=255);if(0>b||this.length<b||this.length<c)throw new RangeError("Out of range index");if(c<=b)return this; | ||
b>>>=0;c=void 0===c?this.length:c>>>0;a||(a=0);if("number"===typeof a)for(d=b;d<c;++d)this[d]=a;else for(a=internalIsBuffer(a)?a:utf8ToBytes((new Buffer(a,d)).toString()),e=a.length,d=0;d<c-b;++d)this[d+b]=a[d%e];return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g;function base64clean(a){a=stringtrim(a).replace(INVALID_BASE64_RE,"");if(2>a.length)return"";for(;0!==a.length%4;)a+="=";return a}function stringtrim(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")} | ||
function toHex(a){return 16>a?"0"+a.toString(16):a.toString(16)} | ||
function utf8ToBytes(a,b){b=b||Infinity;for(var c,d=a.length,e=null,f=[],g=0;g<d;++g){c=a.charCodeAt(g);if(55295<c&&57344>c){if(!e){if(56319<c){-1<(b-=3)&&f.push(239,191,189);continue}else if(g+1===d){-1<(b-=3)&&f.push(239,191,189);continue}e=c;continue}if(56320>c){-1<(b-=3)&&f.push(239,191,189);e=c;continue}c=(e-55296<<10|c-56320)+65536}else e&&-1<(b-=3)&&f.push(239,191,189);e=null;if(128>c){if(0>--b)break;f.push(c)}else if(2048>c){if(0>(b-=2))break;f.push(c>>6|192,c&63|128)}else if(65536>c){if(0> | ||
(b-=3))break;f.push(c>>12|224,c>>6&63|128,c&63|128)}else if(1114112>c){if(0>(b-=4))break;f.push(c>>18|240,c>>12&63|128,c>>6&63|128,c&63|128)}else throw Error("Invalid code point");}return f}function asciiToBytes(a){for(var b=[],c=0;c<a.length;++c)b.push(a.charCodeAt(c)&255);return b}function utf16leToBytes(a,b){for(var c,d,e=[],f=0;f<a.length&&!(0>(b-=2));++f)c=a.charCodeAt(f),d=c>>8,c%=256,e.push(c),e.push(d);return e}function base64ToBytes(a){return toByteArray(base64clean(a))} | ||
function blitBuffer(a,b,c,d){for(var e=0;e<d&&!(e+c>=b.length||e>=a.length);++e)b[e+c]=a[e];return e}function isnan(a){return a!==a}function isBuffer(a){return null!=a&&(!!a._isBuffer||isFastBuffer(a)||isSlowBuffer(a))}function isFastBuffer(a){return!!a.constructor&&"function"===typeof a.constructor.isBuffer&&a.constructor.isBuffer(a)}function isSlowBuffer(a){return"function"===typeof a.readFloatLE&&"function"===typeof a.slice&&isFastBuffer(a.slice(0,0))} | ||
var NS_PER_SEC=1E9,getBigIntHrtime=function(a){var b=a();return function(c){c=a(c||b);return c[0]*NS_PER_SEC+c[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(a){process.kill(process.pid,a)},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= | ||
@@ -39,34 +101,34 @@ 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= | ||
defaultBindings=bindings; | ||
var msToNs=function(e){var c=Math.trunc(e);e=BigIntPolyfill(Math.round(1E3*(e-c)));return BigIntPolyfill(c)*BigIntPolyfill(1E3)+e},wrap=function(e){return function(){for(var c=[],f=0;f<arguments.length;f++)c[f]=arguments[f];try{return e.apply(void 0,__spread(c))}catch(d){if("number"===typeof d)return d;if(d&&d.errno)return ERROR_MAP[d.code]||WASI_EINVAL;throw d;}}},stat=function(e,c){var f=e.FD_MAP.get(c);if(!f)throw WASI_EBADF;if(void 0===f.filetype){var d=e.bindings.fs.fstatSync(f.real);e=translateFileAttributes(e, | ||
c,d);c=e.rightsBase;d=e.rightsInheriting;f.filetype=e.filetype;f.rights||(f.rights={base:c,inheriting:d})}return f},translateFileAttributes=function(e,c,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!==c&&e.bindings.isTTY(c)?{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 c(c){var d=e.call(this,"WASI Exit error: "+c)||this;d.code=c;return d}__extends(c,e); | ||
return c}(Error),WASIKillError=function(e){function c(c){var d=e.call(this,"WASI Kill signal: "+c)||this;d.signal=c;return d}__extends(c,e);return c}(Error),WASI=function(){function e(c){var e,d=this,x={};c&&c.preopenDirectories&&(x=c.preopenDirectories);var w={};c&&c.env&&(w=c.env);var v=[];c&&c.args&&(v=c.args);var r=defaultBindings;c&&c.bindings&&(r=c.bindings);this.view=this.memory=void 0;this.bindings=r;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(x)),y=z.next();!y.done;y=z.next()){var C=__read(y.value,2),G=C[0],D=C[1],H=g.openSync(D,g.constants.O_RDONLY),I=__spread(this.FD_MAP.keys()).reverse()[0]+ | ||
1;this.FD_MAP.set(I,{real:H,filetype:WASI_FILETYPE_DIRECTORY,rights:{base:RIGHTS_DIRECTORY_BASE,inheriting:RIGHTS_DIRECTORY_INHERITING},fakePath:G,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,b){d.refreshMemory();return Array.from({length:b},function(b,c){c=a+8*c;b=d.view.getUint32(c,!0);c=d.view.getUint32(c+4,!0);return new Uint8Array(d.memory.buffer,b,c)})},h=function(a,b){a=stat(d,a);if(b!==BigIntPolyfill(0)&&(a.rights.base& | ||
b)===BigIntPolyfill(0))throw WASI_EPERM;return a},J=r.hrtime(),B=function(a){switch(a){case WASI_CLOCK_MONOTONIC:case WASI_CLOCK_REALTIME:return r.hrtime();case WASI_CLOCK_PROCESS_CPUTIME_ID:case WASI_CLOCK_THREAD_CPUTIME_ID:return r.hrtime()-J;default:return null}};this.wasiImport={args_get:function(a,b){d.refreshMemory();var k=a,c=b;v.forEach(function(a){d.view.setUint32(k,c,!0);k+=4;c+=Buffer.from(d.memory.buffer).write(a+"\x00",c)});return WASI_ESUCCESS},args_sizes_get:function(a,b){d.refreshMemory(); | ||
d.view.setUint32(a,v.length,!0);a=v.reduce(function(a,b){return a+Buffer.byteLength(b)+1},0);d.view.setUint32(b,a,!0);return WASI_ESUCCESS},environ_get:function(a,b){d.refreshMemory();var k=a,c=b;Object.entries(w).forEach(function(a){var b=__read(a,2);a=b[0];b=b[1];d.view.setUint32(k,c,!0);k+=4;c+=Buffer.from(d.memory.buffer).write(a+"="+b+"\x00",c)});return WASI_ESUCCESS},environ_sizes_get:function(a,b){d.refreshMemory();var k=Object.entries(w).map(function(a){a=__read(a,2);return a[0]+"="+a[1]+ | ||
"\x00"}),c=k.reduce(function(a,b){return a+Buffer.byteLength(b)},0);d.view.setUint32(a,k.length,!0);d.view.setUint32(b,c,!0);return WASI_ESUCCESS},clock_res_get:function(a,b){d.view.setBigUint64(b,BigIntPolyfill(0));return WASI_ESUCCESS},clock_time_get:function(a,b,c){d.refreshMemory();a=B(a);if(null===a)return WASI_EINVAL;d.view.setBigUint64(c,BigIntPolyfill(a),!0);return WASI_ESUCCESS},fd_advise:wrap(function(a,b,d,c){h(a,WASI_RIGHT_FD_ADVISE);return WASI_ENOSYS}),fd_allocate:wrap(function(a,b, | ||
d){h(a,WASI_RIGHT_FD_ALLOCATE);return WASI_ENOSYS}),fd_close:wrap(function(a){var b=h(a,BigIntPolyfill(0));g.closeSync(b.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,b){a=h(a,BigIntPolyfill(0));d.refreshMemory();d.view.setUint8(b,a.filetype);d.view.setUint16(b+2,0,!0);d.view.setUint16(b+4,0,!0);d.view.setBigUint64(b+8,a.rights.base,!0);d.view.setBigUint64(b+8+8,a.rights.inheriting, | ||
!0);return WASI_ESUCCESS}),fd_fdstat_set_flags:wrap(function(a,b){h(a,WASI_RIGHT_FD_FDSTAT_SET_FLAGS);return WASI_ENOSYS}),fd_fdstat_set_rights:wrap(function(a,b,d){a=h(a,BigIntPolyfill(0));b|=a.rights.base;if(b>a.rights.base)return WASI_EPERM;d|=a.rights.inheriting;if(d>a.rights.inheriting)return WASI_EPERM;a.rights.base=b;a.rights.inheriting=d;return WASI_ESUCCESS}),fd_filestat_get:wrap(function(a,b){a=h(a,WASI_RIGHT_FD_FILESTAT_GET);var c=g.fstatSync(a.real);d.refreshMemory();d.view.setBigUint64(b, | ||
BigIntPolyfill(c.dev),!0);b+=8;d.view.setBigUint64(b,BigIntPolyfill(c.ino),!0);b+=8;d.view.setUint8(b,a.filetype);b+=4;d.view.setUint32(b,Number(c.nlink),!0);b+=4;d.view.setBigUint64(b,BigIntPolyfill(c.size),!0);b+=8;d.view.setBigUint64(b,msToNs(c.atimeMs),!0);b+=8;d.view.setBigUint64(b,msToNs(c.mtimeMs),!0);d.view.setBigUint64(b+8,msToNs(c.ctimeMs),!0);return WASI_ESUCCESS}),fd_filestat_set_size:wrap(function(a,b){a=h(a,WASI_RIGHT_FD_FILESTAT_SET_SIZE);g.ftruncate(a.real,Number(b));return WASI_ESUCCESS}), | ||
fd_filestat_set_times:wrap(function(a,b,d,c){a=h(a,WASI_RIGHT_FD_FILESTAT_SET_TIMES);var k=B(WASI_CLOCK_REALTIME);g.futimesSync(a.real,(c&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW?k:b,(c&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW?k:d);return WASI_ESUCCESS}),fd_prestat_get:wrap(function(a,b){a=h(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();d.view.setUint8(b,WASI_PREOPENTYPE_DIR);d.view.setUint32(b+4,Buffer.byteLength(a.fakePath),!0);return WASI_ESUCCESS}), | ||
fd_prestat_dir_name:wrap(function(a,b,c){a=h(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();Buffer.from(d.memory.buffer).write(a.fakePath,b,c,"utf8");return WASI_ESUCCESS}),fd_pwrite:wrap(function(a,b,c,e,u){var k=h(a,WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SEEK),f=0;A(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=g.writeSync(k.real,a,b,a.byteLength-b,e+f+b);f+=b});d.view.setUint32(u,f,!0);return WASI_ESUCCESS}),fd_write:wrap(function(a,b,c,e){var k=h(a,WASI_RIGHT_FD_WRITE), | ||
f=0;A(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=g.writeSync(k.real,a,b,a.byteLength-b);f+=b});d.view.setUint32(e,f,!0);return WASI_ESUCCESS}),fd_pread:wrap(function(a,b,c,e,f){var k=h(a,WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SEEK),u=0;A(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=g.readSync(k.real,a,b,a.byteLength-b,e+u+b);u+=b});d.view.setUint32(f,u,!0);return WASI_ESUCCESS}),fd_read:wrap(function(a,b,c,e){var k;a=h(a,WASI_RIGHT_FD_READ);var f=0;try{var q=__values(A(b,c)),t=q.next(); | ||
a:for(;!t.done;t=q.next()){var l=t.value;for(b=0;b<l.byteLength;){var n=g.readSync(a.real,l,b,l.byteLength-b);b+=n;f+=n;if(0===n)break a}}}catch(K){var m={error:K}}finally{try{t&&!t.done&&(k=q.return)&&k.call(q)}finally{if(m)throw m.error;}}d.view.setUint32(e,f,!0);return WASI_ESUCCESS}),fd_readdir:wrap(function(a,b,c,e,f){a=h(a,WASI_RIGHT_FD_READDIR);d.refreshMemory();var k=g.readdirSync(a.path,{withFileTypes:!0}),u=b;for(e=Number(e);e<k.length;e+=1){var q=k[e];d.view.setBigUint64(b,BigIntPolyfill(e+ | ||
1),!0);b+=8;var l=g.statSync(n.resolve(a.path,q.name));d.view.setBigUint64(b,BigIntPolyfill(l.ino),!0);b+=8;d.view.setUint32(b,Buffer.byteLength(q.name),!0);b+=4;switch(!0){case l.isBlockDevice():l=WASI_FILETYPE_BLOCK_DEVICE;break;case l.isCharacterDevice():l=WASI_FILETYPE_CHARACTER_DEVICE;break;case l.isDirectory():l=WASI_FILETYPE_DIRECTORY;break;case l.isFIFO():l=WASI_FILETYPE_SOCKET_STREAM;break;case l.isFile():l=WASI_FILETYPE_REGULAR_FILE;break;case l.isSocket():l=WASI_FILETYPE_SOCKET_STREAM; | ||
break;case l.isSymbolicLink():l=WASI_FILETYPE_SYMBOLIC_LINK;break;default:l=WASI_FILETYPE_UNKNOWN}d.view.setUint8(b,l);b+=1;b+=3;Buffer.from(d.memory.buffer).write(q.name,b,c-b);b+=Buffer.byteLength(q.name);b+=8%b}d.view.setUint32(f,b-u,!0);return WASI_ESUCCESS}),fd_renumber:wrap(function(a,b){h(a,BigIntPolyfill(0));h(b,BigIntPolyfill(0));g.closeSync(d.FD_MAP.get(a).real);d.FD_MAP.set(a,d.FD_MAP.get(b));d.FD_MAP.delete(b);return WASI_ESUCCESS}),fd_seek:wrap(function(a,b,c,e){h(a,WASI_RIGHT_FD_SEEK); | ||
d.refreshMemory();throw Error("fd_seek to be implemented (without binding)");}),fd_tell:wrap(function(a,b){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,b,c){a=h(a,WASI_RIGHT_PATH_CREATE_DIRECTORY);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();g.mkdirSync(n.resolve(a.path, | ||
b));return WASI_ESUCCESS}),path_filestat_get:wrap(function(a,b,c,e,f){a=h(a,WASI_RIGHT_PATH_FILESTAT_GET);if(!a.path)return WASI_EINVAL;d.refreshMemory();c=Buffer.from(d.memory.buffer,c,e).toString();c=g.statSync(n.resolve(a.path,c));d.view.setBigUint64(f,BigIntPolyfill(c.dev),!0);f+=8;d.view.setBigUint64(f,BigIntPolyfill(c.ino),!0);f+=8;d.view.setUint8(f,translateFileAttributes(d,void 0,c).filetype);f+=4;d.view.setUint32(f,Number(c.nlink),!0);f+=4;d.view.setBigUint64(f,BigIntPolyfill(c.size),!0); | ||
f+=8;d.view.setBigUint64(f,msToNs(c.atimeMs),!0);f+=8;d.view.setBigUint64(f,msToNs(c.mtimeMs),!0);d.view.setBigUint64(f+8,msToNs(c.ctimeMs),!0);return WASI_ESUCCESS}),path_filestat_set_times:wrap(function(a,b,c,e,f,p){a=h(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES);if(!a.path)return WASI_EINVAL;d.refreshMemory();var k=B(WASI_CLOCK_REALTIME),u=(b&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW;b=(b&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW;c=Buffer.from(d.memory.buffer,c,e).toString(); | ||
g.utimesSync(n.resolve(a.path,c),u?k:f,b?k:p);return WASI_ESUCCESS}),path_link:wrap(function(a,b,c,e,f,p,r){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();c=Buffer.from(d.memory.buffer,c,e).toString();p=Buffer.from(d.memory.buffer,p,r).toString();g.linkSync(n.resolve(a.path,c),n.resolve(f.path,p));return WASI_ESUCCESS}),path_open:wrap(function(a,b,c,e,f,p,r,t,l){b=h(a,WASI_RIGHT_PATH_OPEN);a=(p&(WASI_RIGHT_FD_READ|WASI_RIGHT_FD_READDIR))!== | ||
BigIntPolyfill(0);var k=(p&(WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_ALLOCATE|WASI_RIGHT_FD_FILESTAT_SET_SIZE))!==BigIntPolyfill(0);if(k&&a)var m=g.constants.O_RDWR;else a?m=g.constants.O_RDONLY:k&&(m=g.constants.O_WRONLY);a=WASI_RIGHT_PATH_OPEN;p|=r;0!==(f&WASI_O_CREAT)&&(m|=g.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(f&WASI_O_DIRECTORY)&&(m|=g.constants.O_DIRECTORY);0!==(f&WASI_O_EXCL)&&(m|=g.constants.O_EXCL);0!==(f&WASI_O_TRUNC)&&(m|=g.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE); | ||
0!==(t&WASI_FDFLAG_APPEND)&&(m|=g.constants.O_APPEND);0!==(t&WASI_FDFLAG_DSYNC)&&(m=g.constants.O_DSYNC?m|g.constants.O_DSYNC:m|g.constants.O_SYNC,p|=WASI_RIGHT_FD_DATASYNC);0!==(t&WASI_FDFLAG_NONBLOCK)&&(m|=g.constants.O_NONBLOCK);0!==(t&WASI_FDFLAG_RSYNC)&&(m=g.constants.O_RSYNC?m|g.constants.O_RSYNC:m|g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);0!==(t&WASI_FDFLAG_SYNC)&&(m|=g.constants.O_SYNC,p|=WASI_RIGHT_FD_SYNC);k&&0===(m&(g.constants.O_APPEND|g.constants.O_TRUNC))&&(p|=WASI_RIGHT_FD_SEEK);d.refreshMemory(); | ||
c=Buffer.from(d.memory.buffer,c,e).toString();c=n.resolve(b.path,c);if(n.relative(b.path,c).startsWith(".."))return WASI_ENOTCAPABLE;try{var q=g.realpathSync(c);if(n.relative(b.path,q).startsWith(".."))return WASI_ENOTCAPABLE}catch(F){if("ENOENT"===F.code)q=c;else throw F;}m=g.openSync(q,m);c=__spread(d.FD_MAP.keys()).reverse()[0]+1;d.FD_MAP.set(c,{real:m,filetype:void 0,rights:{base:a,inheriting:p},path:q});stat(d,c);d.view.setUint32(l,c,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,b, | ||
c,e,f,p){a=h(a,WASI_RIGHT_PATH_READLINK);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();b=n.resolve(a.path,b);b=g.readlinkSync(b);e=Buffer.from(d.memory.buffer).write(b,e,f);d.view.setUint32(p,e,!0);return WASI_ESUCCESS}),path_remove_directory:wrap(function(a,b,c){a=h(a,WASI_RIGHT_PATH_REMOVE_DIRECTORY);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();g.rmdirSync(n.resolve(a.path,b));return WASI_ESUCCESS}), | ||
path_rename:wrap(function(a,b,c,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();b=Buffer.from(d.memory.buffer,b,c).toString();f=Buffer.from(d.memory.buffer,f,p).toString();g.renameSync(n.resolve(a.path,b),n.resolve(e.path,f));return WASI_ESUCCESS}),path_symlink:wrap(function(a,b,c,e,f){c=h(c,WASI_RIGHT_PATH_SYMLINK);if(!c.path)return WASI_EINVAL;d.refreshMemory();a=Buffer.from(d.memory.buffer,a,b).toString(); | ||
e=Buffer.from(d.memory.buffer,e,f).toString();g.symlinkSync(a,n.resolve(c.path,e));return WASI_ESUCCESS}),path_unlink_file:wrap(function(a,b,c){a=h(a,WASI_RIGHT_PATH_UNLINK_FILE);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();g.unlinkSync(n.resolve(a.path,b));return WASI_ESUCCESS}),poll_oneoff:function(a,b,c,e){var f=0,g=0;d.refreshMemory();for(var h=0;h<c;h+=1){var k=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 m=d.view.getUint16(a,!0);a+=2;a+=6;var q=1===m;m=WASI_ESUCCESS;n=B(n);null===n?m=WASI_EINVAL:(l=q?l:n+l,g=l>g?l:g);d.view.setBigUint64(b,k,!0);b+=8;d.view.setUint16(b,m,!0);b+=2;d.view.setUint8(b,WASI_EVENTTYPE_CLOCK);b+=1;b+=5;f+=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,k,!0);b+=8; | ||
d.view.setUint16(b,WASI_ENOSYS,!0);b+=2;d.view.setUint8(b,l);b+=1;b+=5;f+=1;break;default:return WASI_EINVAL}}for(d.view.setUint32(e,f,!0);r.hrtime()<g;);return WASI_ESUCCESS},proc_exit:function(a){r.exit(a);return WASI_ESUCCESS},proc_raise:function(a){if(!(a in SIGNAL_MAP))return WASI_EINVAL;r.kill(SIGNAL_MAP[a]);return WASI_ESUCCESS},random_get:function(a,b){d.refreshMemory();r.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}}}e.prototype.refreshMemory=function(){this.view&&0!==this.view.buffer.byteLength||(this.view=new DataViewPolyfill(this.memory.buffer))};e.prototype.setMemory=function(c){this.memory=c};e.prototype.start=function(c){c=c.exports;if(null===c||"object"!==typeof c)throw Error("instance.exports must be an Object. Received "+c+".");var e=c.memory;if(!(e instanceof WebAssembly.Memory))throw Error("instance.exports.memory must be a WebAssembly.Memory. Recceived "+ | ||
e+".");this.setMemory(e);c._start&&c._start()};e.defaultBindings=defaultBindings;return e}();module.exports=WASI; | ||
var msToNs=function(a){var b=Math.trunc(a);a=BigIntPolyfill(Math.round(1E3*(a-b)));return BigIntPolyfill(b)*BigIntPolyfill(1E3)+a},wrap=function(a){return function(){for(var b=[],c=0;c<arguments.length;c++)b[c]=arguments[c];try{return a.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(a,b){var c=a.FD_MAP.get(b);if(!c)throw WASI_EBADF;if(void 0===c.filetype){var d=a.bindings.fs.fstatSync(c.real);a=translateFileAttributes(a, | ||
b,d);b=a.rightsBase;d=a.rightsInheriting;c.filetype=a.filetype;c.rights||(c.rights={base:b,inheriting:d})}return c},translateFileAttributes=function(a,b,c){switch(!0){case c.isBlockDevice():return{filetype:WASI_FILETYPE_BLOCK_DEVICE,rightsBase:RIGHTS_BLOCK_DEVICE_BASE,rightsInheriting:RIGHTS_BLOCK_DEVICE_INHERITING};case c.isCharacterDevice():return c=WASI_FILETYPE_CHARACTER_DEVICE,void 0!==b&&a.bindings.isTTY(b)?{filetype:c,rightsBase:RIGHTS_TTY_BASE,rightsInheriting:RIGHTS_TTY_INHERITING}:{filetype:c, | ||
rightsBase:RIGHTS_CHARACTER_DEVICE_BASE,rightsInheriting:RIGHTS_CHARACTER_DEVICE_INHERITING};case c.isDirectory():return{filetype:WASI_FILETYPE_DIRECTORY,rightsBase:RIGHTS_DIRECTORY_BASE,rightsInheriting:RIGHTS_DIRECTORY_INHERITING};case c.isFIFO():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case c.isFile():return{filetype:WASI_FILETYPE_REGULAR_FILE,rightsBase:RIGHTS_REGULAR_FILE_BASE,rightsInheriting:RIGHTS_REGULAR_FILE_INHERITING}; | ||
case c.isSocket():return{filetype:WASI_FILETYPE_SOCKET_STREAM,rightsBase:RIGHTS_SOCKET_BASE,rightsInheriting:RIGHTS_SOCKET_INHERITING};case c.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(a){function b(b){var c=a.call(this,"WASI Exit error: "+b)||this;c.code=b;return c}__extends(b,a); | ||
return b}(Error),WASIKillError=function(a){function b(b){var c=a.call(this,"WASI Kill signal: "+b)||this;c.signal=b;return c}__extends(b,a);return b}(Error),WASI=function(){function a(a){var b,d=this,e={};a&&a.preopenDirectories&&(e=a.preopenDirectories);var f={};a&&a.env&&(f=a.env);var g=[];a&&a.args&&(g=a.args);var k=defaultBindings;a&&a.bindings&&(k=a.bindings);this.view=this.memory=void 0;this.bindings=k;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 h=this.bindings.fs,n=this.bindings.path;try{for(var q=__values(Object.entries(e)),t=q.next();!t.done;t=q.next()){var u=__read(t.value,2),B=u[0],x=u[1],C=h.openSync(x,h.constants.O_RDONLY),D=__spread(this.FD_MAP.keys()).reverse()[0]+ | ||
1;this.FD_MAP.set(D,{real:C,filetype:WASI_FILETYPE_DIRECTORY,rights:{base:RIGHTS_DIRECTORY_BASE,inheriting:RIGHTS_DIRECTORY_INHERITING},fakePath:B,path:x})}}catch(p){var y={error:p}}finally{try{t&&!t.done&&(b=q.return)&&b.call(q)}finally{if(y)throw y.error;}}var v=function(a,b){d.refreshMemory();return Array.from({length:b},function(b,c){c=a+8*c;b=d.view.getUint32(c,!0);c=d.view.getUint32(c+4,!0);return new Uint8Array(d.memory.buffer,b,c)})},l=function(a,b){a=stat(d,a);if(b!==BigIntPolyfill(0)&&(a.rights.base& | ||
b)===BigIntPolyfill(0))throw WASI_EPERM;return a},E=k.hrtime(),w=function(a){switch(a){case WASI_CLOCK_MONOTONIC:case WASI_CLOCK_REALTIME:return k.hrtime();case WASI_CLOCK_PROCESS_CPUTIME_ID:case WASI_CLOCK_THREAD_CPUTIME_ID:return k.hrtime()-E;default:return null}};this.wasiImport={args_get:function(a,b){d.refreshMemory();var c=a,e=b;g.forEach(function(a){d.view.setUint32(c,e,!0);c+=4;e+=Buffer.from(d.memory.buffer).write(a+"\x00",e)});return WASI_ESUCCESS},args_sizes_get:function(a,b){d.refreshMemory(); | ||
d.view.setUint32(a,g.length,!0);a=g.reduce(function(a,b){return a+Buffer.byteLength(b)+1},0);d.view.setUint32(b,a,!0);return WASI_ESUCCESS},environ_get:function(a,b){d.refreshMemory();var c=a,e=b;Object.entries(f).forEach(function(a){var b=__read(a,2);a=b[0];b=b[1];d.view.setUint32(c,e,!0);c+=4;e+=Buffer.from(d.memory.buffer).write(a+"="+b+"\x00",e)});return WASI_ESUCCESS},environ_sizes_get:function(a,b){d.refreshMemory();var c=Object.entries(f).map(function(a){a=__read(a,2);return a[0]+"="+a[1]+ | ||
"\x00"}),e=c.reduce(function(a,b){return a+Buffer.byteLength(b)},0);d.view.setUint32(a,c.length,!0);d.view.setUint32(b,e,!0);return WASI_ESUCCESS},clock_res_get:function(a,b){d.view.setBigUint64(b,BigIntPolyfill(0));return WASI_ESUCCESS},clock_time_get:function(a,b,c){d.refreshMemory();a=w(a);if(null===a)return WASI_EINVAL;d.view.setBigUint64(c,BigIntPolyfill(a),!0);return WASI_ESUCCESS},fd_advise:wrap(function(a,b,c,d){l(a,WASI_RIGHT_FD_ADVISE);return WASI_ENOSYS}),fd_allocate:wrap(function(a,b, | ||
c){l(a,WASI_RIGHT_FD_ALLOCATE);return WASI_ENOSYS}),fd_close:wrap(function(a){var b=l(a,BigIntPolyfill(0));h.closeSync(b.real);d.FD_MAP.delete(a);return WASI_ESUCCESS}),fd_datasync:function(a){a=l(a,WASI_RIGHT_FD_DATASYNC);h.fdatasyncSync(a.real);return WASI_ESUCCESS},fd_fdstat_get:wrap(function(a,b){a=l(a,BigIntPolyfill(0));d.refreshMemory();d.view.setUint8(b,a.filetype);d.view.setUint16(b+2,0,!0);d.view.setUint16(b+4,0,!0);d.view.setBigUint64(b+8,a.rights.base,!0);d.view.setBigUint64(b+8+8,a.rights.inheriting, | ||
!0);return WASI_ESUCCESS}),fd_fdstat_set_flags:wrap(function(a,b){l(a,WASI_RIGHT_FD_FDSTAT_SET_FLAGS);return WASI_ENOSYS}),fd_fdstat_set_rights:wrap(function(a,b,c){a=l(a,BigIntPolyfill(0));b|=a.rights.base;if(b>a.rights.base)return WASI_EPERM;c|=a.rights.inheriting;if(c>a.rights.inheriting)return WASI_EPERM;a.rights.base=b;a.rights.inheriting=c;return WASI_ESUCCESS}),fd_filestat_get:wrap(function(a,b){a=l(a,WASI_RIGHT_FD_FILESTAT_GET);var c=h.fstatSync(a.real);d.refreshMemory();d.view.setBigUint64(b, | ||
BigIntPolyfill(c.dev),!0);b+=8;d.view.setBigUint64(b,BigIntPolyfill(c.ino),!0);b+=8;d.view.setUint8(b,a.filetype);b+=4;d.view.setUint32(b,Number(c.nlink),!0);b+=4;d.view.setBigUint64(b,BigIntPolyfill(c.size),!0);b+=8;d.view.setBigUint64(b,msToNs(c.atimeMs),!0);b+=8;d.view.setBigUint64(b,msToNs(c.mtimeMs),!0);d.view.setBigUint64(b+8,msToNs(c.ctimeMs),!0);return WASI_ESUCCESS}),fd_filestat_set_size:wrap(function(a,b){a=l(a,WASI_RIGHT_FD_FILESTAT_SET_SIZE);h.ftruncate(a.real,Number(b));return WASI_ESUCCESS}), | ||
fd_filestat_set_times:wrap(function(a,b,c,d){a=l(a,WASI_RIGHT_FD_FILESTAT_SET_TIMES);var e=w(WASI_CLOCK_REALTIME);h.futimesSync(a.real,(d&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW?e:b,(d&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW?e:c);return WASI_ESUCCESS}),fd_prestat_get:wrap(function(a,b){a=l(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();d.view.setUint8(b,WASI_PREOPENTYPE_DIR);d.view.setUint32(b+4,Buffer.byteLength(a.fakePath),!0);return WASI_ESUCCESS}), | ||
fd_prestat_dir_name:wrap(function(a,b,c){a=l(a,BigIntPolyfill(0));if(!a.path)return WASI_EINVAL;d.refreshMemory();Buffer.from(d.memory.buffer).write(a.fakePath,b,c,"utf8");return WASI_ESUCCESS}),fd_pwrite:wrap(function(a,b,c,e,f){var p=l(a,WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_SEEK),m=0;v(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=h.writeSync(p.real,a,b,a.byteLength-b,e+m+b);m+=b});d.view.setUint32(f,m,!0);return WASI_ESUCCESS}),fd_write:wrap(function(a,b,c,e){var p=l(a,WASI_RIGHT_FD_WRITE), | ||
f=0;v(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=h.writeSync(p.real,a,b,a.byteLength-b);f+=b});d.view.setUint32(e,f,!0);return WASI_ESUCCESS}),fd_pread:wrap(function(a,b,c,e,f){var p=l(a,WASI_RIGHT_FD_READ|WASI_RIGHT_FD_SEEK),m=0;v(b,c).forEach(function(a){for(var b=0;b<a.byteLength;)b+=h.readSync(p.real,a,b,a.byteLength-b,e+m+b);m+=b});d.view.setUint32(f,m,!0);return WASI_ESUCCESS}),fd_read:wrap(function(a,b,c,e){var p;a=l(a,WASI_RIGHT_FD_READ);var f=0;try{var m=__values(v(b,c)),r=m.next(); | ||
a:for(;!r.done;r=m.next()){var g=r.value;for(b=0;b<g.byteLength;){var k=h.readSync(a.real,g,b,g.byteLength-b);b+=k;f+=k;if(0===k)break a}}}catch(F){var z={error:F}}finally{try{r&&!r.done&&(p=m.return)&&p.call(m)}finally{if(z)throw z.error;}}d.view.setUint32(e,f,!0);return WASI_ESUCCESS}),fd_readdir:wrap(function(a,b,c,e,f){a=l(a,WASI_RIGHT_FD_READDIR);d.refreshMemory();var p=h.readdirSync(a.path,{withFileTypes:!0}),m=b;for(e=Number(e);e<p.length;e+=1){var r=p[e];d.view.setBigUint64(b,BigIntPolyfill(e+ | ||
1),!0);b+=8;var g=h.statSync(n.resolve(a.path,r.name));d.view.setBigUint64(b,BigIntPolyfill(g.ino),!0);b+=8;d.view.setUint32(b,Buffer.byteLength(r.name),!0);b+=4;switch(!0){case g.isBlockDevice():g=WASI_FILETYPE_BLOCK_DEVICE;break;case g.isCharacterDevice():g=WASI_FILETYPE_CHARACTER_DEVICE;break;case g.isDirectory():g=WASI_FILETYPE_DIRECTORY;break;case g.isFIFO():g=WASI_FILETYPE_SOCKET_STREAM;break;case g.isFile():g=WASI_FILETYPE_REGULAR_FILE;break;case g.isSocket():g=WASI_FILETYPE_SOCKET_STREAM; | ||
break;case g.isSymbolicLink():g=WASI_FILETYPE_SYMBOLIC_LINK;break;default:g=WASI_FILETYPE_UNKNOWN}d.view.setUint8(b,g);b+=1;b+=3;Buffer.from(d.memory.buffer).write(r.name,b,c-b);b+=Buffer.byteLength(r.name);b+=8%b}d.view.setUint32(f,b-m,!0);return WASI_ESUCCESS}),fd_renumber:wrap(function(a,b){l(a,BigIntPolyfill(0));l(b,BigIntPolyfill(0));h.closeSync(d.FD_MAP.get(a).real);d.FD_MAP.set(a,d.FD_MAP.get(b));d.FD_MAP.delete(b);return WASI_ESUCCESS}),fd_seek:wrap(function(a,b,c,e){l(a,WASI_RIGHT_FD_SEEK); | ||
d.refreshMemory();throw Error("fd_seek to be implemented (without binding)");}),fd_tell:wrap(function(a,b){l(a,WASI_RIGHT_FD_TELL);d.refreshMemory();throw Error("fd_tell to be implemented (without binding)");}),fd_sync:wrap(function(a){a=l(a,WASI_RIGHT_FD_SYNC);h.fsyncSync(a.real);return WASI_ESUCCESS}),path_create_directory:wrap(function(a,b,c){a=l(a,WASI_RIGHT_PATH_CREATE_DIRECTORY);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();h.mkdirSync(n.resolve(a.path, | ||
b));return WASI_ESUCCESS}),path_filestat_get:wrap(function(a,b,c,e,f){a=l(a,WASI_RIGHT_PATH_FILESTAT_GET);if(!a.path)return WASI_EINVAL;d.refreshMemory();c=Buffer.from(d.memory.buffer,c,e).toString();c=h.statSync(n.resolve(a.path,c));d.view.setBigUint64(f,BigIntPolyfill(c.dev),!0);f+=8;d.view.setBigUint64(f,BigIntPolyfill(c.ino),!0);f+=8;d.view.setUint8(f,translateFileAttributes(d,void 0,c).filetype);f+=4;d.view.setUint32(f,Number(c.nlink),!0);f+=4;d.view.setBigUint64(f,BigIntPolyfill(c.size),!0); | ||
f+=8;d.view.setBigUint64(f,msToNs(c.atimeMs),!0);f+=8;d.view.setBigUint64(f,msToNs(c.mtimeMs),!0);d.view.setBigUint64(f+8,msToNs(c.ctimeMs),!0);return WASI_ESUCCESS}),path_filestat_set_times:wrap(function(a,b,c,e,f,g){a=l(a,WASI_RIGHT_PATH_FILESTAT_SET_TIMES);if(!a.path)return WASI_EINVAL;d.refreshMemory();var p=w(WASI_CLOCK_REALTIME),m=(b&WASI_FILESTAT_SET_ATIM_NOW)===WASI_FILESTAT_SET_ATIM_NOW;b=(b&WASI_FILESTAT_SET_MTIM_NOW)===WASI_FILESTAT_SET_MTIM_NOW;c=Buffer.from(d.memory.buffer,c,e).toString(); | ||
h.utimesSync(n.resolve(a.path,c),m?p:f,b?p:g);return WASI_ESUCCESS}),path_link:wrap(function(a,b,c,e,f,g,k){a=l(a,WASI_RIGHT_PATH_LINK_SOURCE);f=l(f,WASI_RIGHT_PATH_LINK_TARGET);if(!a.path||!f.path)return WASI_EINVAL;d.refreshMemory();c=Buffer.from(d.memory.buffer,c,e).toString();g=Buffer.from(d.memory.buffer,g,k).toString();h.linkSync(n.resolve(a.path,c),n.resolve(f.path,g));return WASI_ESUCCESS}),path_open:wrap(function(a,b,c,e,f,g,k,q,t){b=l(a,WASI_RIGHT_PATH_OPEN);a=(g&(WASI_RIGHT_FD_READ|WASI_RIGHT_FD_READDIR))!== | ||
BigIntPolyfill(0);var p=(g&(WASI_RIGHT_FD_DATASYNC|WASI_RIGHT_FD_WRITE|WASI_RIGHT_FD_ALLOCATE|WASI_RIGHT_FD_FILESTAT_SET_SIZE))!==BigIntPolyfill(0);if(p&&a)var m=h.constants.O_RDWR;else a?m=h.constants.O_RDONLY:p&&(m=h.constants.O_WRONLY);a=WASI_RIGHT_PATH_OPEN;g|=k;0!==(f&WASI_O_CREAT)&&(m|=h.constants.O_CREAT,a|=WASI_RIGHT_PATH_CREATE_FILE);0!==(f&WASI_O_DIRECTORY)&&(m|=h.constants.O_DIRECTORY);0!==(f&WASI_O_EXCL)&&(m|=h.constants.O_EXCL);0!==(f&WASI_O_TRUNC)&&(m|=h.constants.O_TRUNC,a|=WASI_RIGHT_PATH_FILESTAT_SET_SIZE); | ||
0!==(q&WASI_FDFLAG_APPEND)&&(m|=h.constants.O_APPEND);0!==(q&WASI_FDFLAG_DSYNC)&&(m=h.constants.O_DSYNC?m|h.constants.O_DSYNC:m|h.constants.O_SYNC,g|=WASI_RIGHT_FD_DATASYNC);0!==(q&WASI_FDFLAG_NONBLOCK)&&(m|=h.constants.O_NONBLOCK);0!==(q&WASI_FDFLAG_RSYNC)&&(m=h.constants.O_RSYNC?m|h.constants.O_RSYNC:m|h.constants.O_SYNC,g|=WASI_RIGHT_FD_SYNC);0!==(q&WASI_FDFLAG_SYNC)&&(m|=h.constants.O_SYNC,g|=WASI_RIGHT_FD_SYNC);p&&0===(m&(h.constants.O_APPEND|h.constants.O_TRUNC))&&(g|=WASI_RIGHT_FD_SEEK);d.refreshMemory(); | ||
c=Buffer.from(d.memory.buffer,c,e).toString();c=n.resolve(b.path,c);if(n.relative(b.path,c).startsWith(".."))return WASI_ENOTCAPABLE;try{var r=h.realpathSync(c);if(n.relative(b.path,r).startsWith(".."))return WASI_ENOTCAPABLE}catch(A){if("ENOENT"===A.code)r=c;else throw A;}m=h.openSync(r,m);c=__spread(d.FD_MAP.keys()).reverse()[0]+1;d.FD_MAP.set(c,{real:m,filetype:void 0,rights:{base:a,inheriting:g},path:r});stat(d,c);d.view.setUint32(t,c,!0);return WASI_ESUCCESS}),path_readlink:wrap(function(a,b, | ||
c,e,f,g){a=l(a,WASI_RIGHT_PATH_READLINK);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();b=n.resolve(a.path,b);b=h.readlinkSync(b);e=Buffer.from(d.memory.buffer).write(b,e,f);d.view.setUint32(g,e,!0);return WASI_ESUCCESS}),path_remove_directory:wrap(function(a,b,c){a=l(a,WASI_RIGHT_PATH_REMOVE_DIRECTORY);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();h.rmdirSync(n.resolve(a.path,b));return WASI_ESUCCESS}), | ||
path_rename:wrap(function(a,b,c,e,f,g){a=l(a,WASI_RIGHT_PATH_RENAME_SOURCE);e=l(e,WASI_RIGHT_PATH_RENAME_TARGET);if(!a.path||!e.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();f=Buffer.from(d.memory.buffer,f,g).toString();h.renameSync(n.resolve(a.path,b),n.resolve(e.path,f));return WASI_ESUCCESS}),path_symlink:wrap(function(a,b,c,e,f){c=l(c,WASI_RIGHT_PATH_SYMLINK);if(!c.path)return WASI_EINVAL;d.refreshMemory();a=Buffer.from(d.memory.buffer,a,b).toString(); | ||
e=Buffer.from(d.memory.buffer,e,f).toString();h.symlinkSync(a,n.resolve(c.path,e));return WASI_ESUCCESS}),path_unlink_file:wrap(function(a,b,c){a=l(a,WASI_RIGHT_PATH_UNLINK_FILE);if(!a.path)return WASI_EINVAL;d.refreshMemory();b=Buffer.from(d.memory.buffer,b,c).toString();h.unlinkSync(n.resolve(a.path,b));return WASI_ESUCCESS}),poll_oneoff:function(a,b,c,e){var f=0,g=0;d.refreshMemory();for(var h=0;h<c;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 p=d.view.getUint16(a,!0);a+=2;a+=6;var q=1===p;p=WASI_ESUCCESS;n=w(n);null===n?p=WASI_EINVAL:(l=q?l:n+l,g=l>g?l:g);d.view.setBigUint64(b,m,!0);b+=8;d.view.setUint16(b,p,!0);b+=2;d.view.setUint8(b,WASI_EVENTTYPE_CLOCK);b+=1;b+=5;f+=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;f+=1;break;default:return WASI_EINVAL}}for(d.view.setUint32(e,f,!0);k.hrtime()<g;);return WASI_ESUCCESS},proc_exit:function(a){k.exit(a);return WASI_ESUCCESS},proc_raise:function(a){if(!(a in SIGNAL_MAP))return WASI_EINVAL;k.kill(SIGNAL_MAP[a]);return WASI_ESUCCESS},random_get:function(a,b){d.refreshMemory();k.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}}}a.prototype.refreshMemory=function(){this.view&&0!==this.view.buffer.byteLength||(this.view=new DataViewPolyfill(this.memory.buffer))};a.prototype.setMemory=function(a){this.memory=a};a.prototype.start=function(a){a=a.exports;if(null===a||"object"!==typeof a)throw Error("instance.exports must be an Object. Received "+a+".");var b=a.memory;if(!(b instanceof WebAssembly.Memory))throw Error("instance.exports.memory must be a WebAssembly.Memory. Recceived "+ | ||
b+".");this.setMemory(b);a._start&&a._start()};a.defaultBindings=defaultBindings;return a}();module.exports=WASI; |
{ | ||
"name": "@wasmer/wasi", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Isomorphic Javascript library for interacting with WASI Modules in Node.js and the Browser. 📚", | ||
@@ -47,6 +47,7 @@ "main": "dist/index.cjs.js", | ||
"browser-process-hrtime": "^1.0.0", | ||
"buffer-es6": "^4.9.3", | ||
"path-browserify": "^1.0.0", | ||
"randomfill": "^1.0.4" | ||
}, | ||
"gitHead": "8351e5dbceafc63169c146b2f8d0865af6846921" | ||
"gitHead": "78d80233e3b5c9848921e1430d358ec674bb1a29" | ||
} |
@@ -36,7 +36,18 @@ # `@wasmer/wasi` | ||
**This quick start is for browsers. For node, WasmFs is not required** | ||
```js | ||
import WASI from "@wasmer/wasi"; | ||
import WasmFs from "@wasmer/wasmfs"; | ||
// Instantiate a new WASI Instance | ||
let wasi = new WASI({ args: [], env: {} }); | ||
const wasmFs = new WasmFs(); | ||
let wasi = new WASI({ | ||
args: [], | ||
env: {}, | ||
bindings: { | ||
...WASI.defaultBindings, | ||
fs: wasmFs.fs | ||
} | ||
}); | ||
@@ -49,3 +60,3 @@ const startWasiTask = async () => { | ||
// Instantiate the WebAssembly file | ||
const wasm_bytes = new Uint8Array(responseArrayBuffer.buffer).buffer; | ||
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer; | ||
let { instance } = await WebAssembly.instantiate(wasm_bytes, { | ||
@@ -57,2 +68,6 @@ wasi_unstable: wasi.wasiImport | ||
wasi.start(instance); | ||
// Output what's inside of /dev/stdout! | ||
const stdout = await wasmFs.getStdOut(); | ||
console.log(stdout); | ||
}; | ||
@@ -59,0 +74,0 @@ startWasiTask(); |
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
204591
15
1118
155
4
+ Addedbuffer-es6@^4.9.3
+ Addedbuffer-es6@4.9.3(transitive)