New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bjorn3/browser_wasi_shim

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bjorn3/browser_wasi_shim - npm Package Compare versions

Comparing version 0.2.15 to 0.2.16

.eslintrc.cjs

2

dist/fd.js

@@ -1,1 +0,1 @@

export class Fd{fd_advise(offset,len,advice){return-1}fd_allocate(offset,len){return-1}fd_close(){return 0}fd_datasync(){return-1}fd_fdstat_get(){return{ret:-1,fdstat:null}}fd_fdstat_set_flags(flags){return-1}fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting){return-1}fd_filestat_get(){return{ret:-1,filestat:null}}fd_filestat_set_size(size){return-1}fd_filestat_set_times(atim,mtim,fst_flags){return-1}fd_pread(view8,iovs,offset){return{ret:-1,nread:0}}fd_prestat_get(){return{ret:-1,prestat:null}}fd_prestat_dir_name(path_ptr,path_len){return{ret:-1,prestat_dir_name:null}}fd_pwrite(view8,iovs,offset){return{ret:-1,nwritten:0}}fd_read(view8,iovs){return{ret:-1,nread:0}}fd_readdir_single(cookie){return{ret:-1,dirent:null}}fd_seek(offset,whence){return{ret:-1,offset:0n}}fd_sync(){return 0}fd_tell(){return{ret:-1,offset:0n}}fd_write(view8,iovs){return{ret:-1,nwritten:0}}path_create_directory(path){return-1}path_filestat_get(flags,path){return{ret:-1,filestat:null}}path_filestat_set_times(flags,path,atim,mtim,fst_flags){return-1}path_link(old_fd,old_flags,old_path,new_path){return-1}path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fdflags){return{ret:-1,fd_obj:null}}path_readlink(path){return{ret:-1,data:null}}path_remove_directory(path){return-1}path_rename(old_path,new_fd,new_path){return-1}path_symlink(old_path,new_path){return-1}path_unlink_file(path){return-1}}
export class Fd{fd_advise(offset,len,advice){return-1}fd_allocate(offset,len){return-1}fd_close(){return 0}fd_datasync(){return-1}fd_fdstat_get(){return{ret:-1,fdstat:null}}fd_fdstat_set_flags(flags){return-1}fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting){return-1}fd_filestat_get(){return{ret:-1,filestat:null}}fd_filestat_set_size(size){return-1}fd_filestat_set_times(atim,mtim,fst_flags){return-1}fd_pread(view8,iovs,offset){return{ret:-1,nread:0}}fd_prestat_get(){return{ret:-1,prestat:null}}fd_prestat_dir_name(){return{ret:-1,prestat_dir_name:null}}fd_pwrite(view8,iovs,offset){return{ret:-1,nwritten:0}}fd_read(view8,iovs){return{ret:-1,nread:0}}fd_readdir_single(cookie){return{ret:-1,dirent:null}}fd_seek(offset,whence){return{ret:-1,offset:0n}}fd_sync(){return 0}fd_tell(){return{ret:-1,offset:0n}}fd_write(view8,iovs){return{ret:-1,nwritten:0}}path_create_directory(path){return-1}path_filestat_get(flags,path){return{ret:-1,filestat:null}}path_filestat_set_times(flags,path,atim,mtim,fst_flags){return-1}path_link(old_fd,old_flags,old_path,new_path){return-1}path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fdflags){return{ret:-1,fd_obj:null}}path_readlink(path){return{ret:-1,data:null}}path_remove_directory(path){return-1}path_rename(old_path,new_fd,new_path){return-1}path_symlink(old_path,new_path){return-1}path_unlink_file(path){return-1}}

@@ -1,1 +0,1 @@

import{OpenDirectory,OpenFile,OpenSyncOPFSFile}from"./fs_fd.js";import*as wasi from"./wasi_defs.js";export class File{open(fd_flags){let file=new OpenFile(this);if(fd_flags&wasi.FDFLAGS_APPEND)file.fd_seek(0n,wasi.WHENCE_END);return file}get size(){return BigInt(this.data.byteLength)}stat(){return new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,this.size)}truncate(){if(this.readonly)return wasi.ERRNO_PERM;this.data=new Uint8Array([]);return wasi.ERRNO_SUCCESS}constructor(data,options){this.data=new Uint8Array(data);this.readonly=!!options?.readonly}}export class SyncOPFSFile{open(fd_flags){let file=new OpenSyncOPFSFile(this);if(fd_flags&wasi.FDFLAGS_APPEND)file.fd_seek(0n,wasi.WHENCE_END);return file}get size(){return BigInt(this.handle.getSize())}stat(){return new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,this.size)}truncate(){if(this.readonly)return wasi.ERRNO_PERM;this.handle.truncate(0);return wasi.ERRNO_SUCCESS}constructor(handle,options){this.handle=handle;this.readonly=!!options?.readonly}}export class Directory{open(fd_flags){return new OpenDirectory(this)}stat(){return new wasi.Filestat(wasi.FILETYPE_DIRECTORY,0n)}get_entry_for_path(path){let entry=this;for(let component of path.split("/")){if(component=="")break;if(component==".")continue;if(!(entry instanceof Directory)){return null}if(entry.contents[component]!=undefined){entry=entry.contents[component]}else{return null}}return entry}create_entry_for_path(path,is_dir){let entry=this;let components=path.split("/").filter(component=>component!="/");for(let i=0;i<components.length;i++){let component=components[i];if(entry.contents[component]!=undefined){entry=entry.contents[component]}else{if(i==components.length-1&&!is_dir){entry.contents[component]=new File(new ArrayBuffer(0))}else{entry.contents[component]=new Directory({})}entry=entry.contents[component]}}return entry}constructor(contents){this.readonly=false;this.contents=contents}}
import{debug}from"./debug.js";import{OpenDirectory,OpenFile,OpenSyncOPFSFile}from"./fs_fd.js";import*as wasi from"./wasi_defs.js";export class File{open(fd_flags){const file=new OpenFile(this);if(fd_flags&wasi.FDFLAGS_APPEND)file.fd_seek(0n,wasi.WHENCE_END);return file}get size(){return BigInt(this.data.byteLength)}stat(){return new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,this.size)}truncate(){if(this.readonly)return wasi.ERRNO_PERM;this.data=new Uint8Array([]);return wasi.ERRNO_SUCCESS}constructor(data,options){this.data=new Uint8Array(data);this.readonly=!!options?.readonly}}export class SyncOPFSFile{open(fd_flags){const file=new OpenSyncOPFSFile(this);if(fd_flags&wasi.FDFLAGS_APPEND)file.fd_seek(0n,wasi.WHENCE_END);return file}get size(){return BigInt(this.handle.getSize())}stat(){return new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,this.size)}truncate(){if(this.readonly)return wasi.ERRNO_PERM;this.handle.truncate(0);return wasi.ERRNO_SUCCESS}constructor(handle,options){this.handle=handle;this.readonly=!!options?.readonly}}export class Directory{open(fd_flags){return new OpenDirectory(this)}stat(){return new wasi.Filestat(wasi.FILETYPE_DIRECTORY,0n)}get_entry_for_path(path){let entry=this;for(const component of path.split("/")){if(component=="")break;if(component==".")continue;if(!(entry instanceof Directory)){return null}if(entry.contents[component]!=undefined){entry=entry.contents[component]}else{debug.log(component);return null}}return entry}create_entry_for_path(path,is_dir){let entry=this;const components=path.split("/").filter(component=>component!="/");for(let i=0;i<components.length;i++){const component=components[i];if(!(entry instanceof Directory)){break}if(entry.contents[component]!=undefined){entry=entry.contents[component]}else{debug.log("create",component);if(i==components.length-1&&!is_dir){entry.contents[component]=new File(new ArrayBuffer(0))}else{entry.contents[component]=new Directory({})}entry=entry.contents[component]}}return entry}constructor(contents){this.readonly=false;this.contents=contents}}

@@ -1,1 +0,1 @@

import*as wasi from"./wasi_defs.js";import{Directory}from"./fs_core.js";import{Fd}from"./fd.js";export class OpenFile extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_REGULAR_FILE,0)}}fd_read(view8,iovs){let nread=0;for(let iovec of iovs){if(this.file_pos<this.file.data.byteLength){let slice=this.file.data.slice(Number(this.file_pos),Number(this.file_pos+BigInt(iovec.buf_len)));view8.set(slice,iovec.buf);this.file_pos+=BigInt(slice.length);nread+=slice.length}else{break}}return{ret:0,nread}}fd_seek(offset,whence){let calculated_offset;switch(whence){case wasi.WHENCE_SET:calculated_offset=offset;break;case wasi.WHENCE_CUR:calculated_offset=this.file_pos+offset;break;case wasi.WHENCE_END:calculated_offset=BigInt(this.file.data.byteLength)+offset;break;default:return{ret:wasi.ERRNO_INVAL,offset:0n}}if(calculated_offset<0){return{ret:wasi.ERRNO_INVAL,offset:0n}}this.file_pos=calculated_offset;return{ret:0,offset:this.file_pos}}fd_write(view8,iovs){let nwritten=0;if(this.file.readonly)return{ret:wasi.ERRNO_BADF,nwritten};for(let iovec of iovs){let buffer=view8.slice(iovec.buf,iovec.buf+iovec.buf_len);if(this.file_pos+BigInt(buffer.byteLength)>this.file.size){let old=this.file.data;this.file.data=new Uint8Array(Number(this.file_pos+BigInt(buffer.byteLength)));this.file.data.set(old)}this.file.data.set(buffer.slice(0,Number(this.file.size-this.file_pos)),Number(this.file_pos));this.file_pos+=BigInt(buffer.byteLength);nwritten+=iovec.buf_len}return{ret:0,nwritten}}fd_filestat_get(){return{ret:0,filestat:this.file.stat()}}constructor(file){super();this.file_pos=0n;this.file=file}}export class OpenSyncOPFSFile extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_REGULAR_FILE,0)}}fd_filestat_get(){return{ret:0,filestat:new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,BigInt(this.file.handle.getSize()))}}fd_read(view8,iovs){let nread=0;for(let iovec of iovs){if(this.position<this.file.handle.getSize()){let buf=new Uint8Array(view8.buffer,iovec.buf,iovec.buf_len);let n=this.file.handle.read(buf,{at:Number(this.position)});this.position+=BigInt(n);nread+=n}else{break}}return{ret:0,nread}}fd_seek(offset,whence){let calculated_offset;switch(whence){case wasi.WHENCE_SET:calculated_offset=BigInt(offset);break;case wasi.WHENCE_CUR:calculated_offset=this.position+BigInt(offset);break;case wasi.WHENCE_END:calculated_offset=BigInt(this.file.handle.getSize())+BigInt(offset);break;default:return{ret:wasi.ERRNO_INVAL,offset:0n}}if(calculated_offset<0){return{ret:wasi.ERRNO_INVAL,offset:0n}}this.position=calculated_offset;return{ret:wasi.ERRNO_SUCCESS,offset:this.position}}fd_write(view8,iovs){let nwritten=0;if(this.file.readonly)return{ret:wasi.ERRNO_BADF,nwritten};for(let iovec of iovs){let buf=new Uint8Array(view8.buffer,iovec.buf,iovec.buf_len);let n=this.file.handle.write(buf,{at:Number(this.position)});this.position+=BigInt(n);nwritten+=n}return{ret:wasi.ERRNO_SUCCESS,nwritten}}fd_datasync(){this.file.handle.flush();return wasi.ERRNO_SUCCESS}fd_sync(){return this.fd_datasync()}fd_close(){return wasi.ERRNO_SUCCESS}constructor(file){super();this.position=0n;this.file=file}}export class OpenDirectory extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_DIRECTORY,0)}}fd_readdir_single(cookie){if(cookie>=BigInt(Object.keys(this.dir.contents).length)){return{ret:0,dirent:null}}let name=Object.keys(this.dir.contents)[Number(cookie)];let entry=this.dir.contents[name];let encoded_name=new TextEncoder("utf-8").encode(name);return{ret:0,dirent:new wasi.Dirent(cookie+1n,name,entry.stat().filetype)}}path_filestat_get(flags,path){let entry=this.dir.get_entry_for_path(path);if(entry==null){return{ret:wasi.ERRNO_EXIST,filestat:null}}return{ret:0,filestat:entry.stat()}}path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags){let entry=this.dir.get_entry_for_path(path);if(entry==null){if((oflags&wasi.OFLAGS_CREAT)==wasi.OFLAGS_CREAT){entry=this.dir.create_entry_for_path(path,(oflags&wasi.OFLAGS_DIRECTORY)==wasi.OFLAGS_DIRECTORY)}else{return{ret:wasi.ERRNO_NOENT,fd_obj:null}}}else if((oflags&wasi.OFLAGS_EXCL)==wasi.OFLAGS_EXCL){return{ret:wasi.ERRNO_EXIST,fd_obj:null}}if((oflags&wasi.OFLAGS_DIRECTORY)==wasi.OFLAGS_DIRECTORY&&entry.stat().filetype!=wasi.FILETYPE_DIRECTORY){return{ret:wasi.ERRNO_ISDIR,fd_obj:null}}if(entry.readonly&&(fs_rights_base&BigInt(wasi.RIGHTS_FD_WRITE))==BigInt(wasi.RIGHTS_FD_WRITE)){return{ret:wasi.ERRNO_PERM,fd_obj:null}}if(!(entry instanceof Directory)&&(oflags&wasi.OFLAGS_TRUNC)==wasi.OFLAGS_TRUNC){let ret=entry.truncate();if(ret!=wasi.ERRNO_SUCCESS)return{ret,fd_obj:null}}return{ret:wasi.ERRNO_SUCCESS,fd_obj:entry.open(fd_flags)}}path_create_directory(path){return this.path_open(0,path,wasi.OFLAGS_CREAT|wasi.OFLAGS_DIRECTORY,0n,0n,0).ret}constructor(dir){super();this.dir=dir}}export class PreopenDirectory extends OpenDirectory{fd_prestat_get(){return{ret:0,prestat:wasi.Prestat.dir(this.prestat_name.length)}}fd_prestat_dir_name(){return{ret:0,prestat_dir_name:this.prestat_name}}constructor(name,contents){super(new Directory(contents));this.prestat_name=new TextEncoder("utf-8").encode(name)}}
import*as wasi from"./wasi_defs.js";import{Directory}from"./fs_core.js";import{Fd}from"./fd.js";import{debug}from"./debug.js";export class OpenFile extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_REGULAR_FILE,0)}}fd_read(view8,iovs){let nread=0;for(const iovec of iovs){if(this.file_pos<this.file.data.byteLength){const slice=this.file.data.slice(Number(this.file_pos),Number(this.file_pos+BigInt(iovec.buf_len)));view8.set(slice,iovec.buf);this.file_pos+=BigInt(slice.length);nread+=slice.length}else{break}}return{ret:0,nread}}fd_pread(view8,iovs,offset){let nread=0;for(const iovec of iovs){if(offset<this.file.data.byteLength){const slice=this.file.data.slice(Number(offset),Number(offset+BigInt(iovec.buf_len)));view8.set(slice,iovec.buf);offset+=BigInt(slice.length);nread+=slice.length}else{break}}return{ret:0,nread}}fd_seek(offset,whence){let calculated_offset;switch(whence){case wasi.WHENCE_SET:calculated_offset=offset;break;case wasi.WHENCE_CUR:calculated_offset=this.file_pos+offset;break;case wasi.WHENCE_END:calculated_offset=BigInt(this.file.data.byteLength)+offset;break;default:return{ret:wasi.ERRNO_INVAL,offset:0n}}if(calculated_offset<0){return{ret:wasi.ERRNO_INVAL,offset:0n}}this.file_pos=calculated_offset;return{ret:0,offset:this.file_pos}}fd_write(view8,iovs){let nwritten=0;if(this.file.readonly)return{ret:wasi.ERRNO_BADF,nwritten};for(const iovec of iovs){const buffer=view8.slice(iovec.buf,iovec.buf+iovec.buf_len);if(this.file_pos+BigInt(buffer.byteLength)>this.file.size){const old=this.file.data;this.file.data=new Uint8Array(Number(this.file_pos+BigInt(buffer.byteLength)));this.file.data.set(old)}this.file.data.set(buffer.slice(0,Number(this.file.size-this.file_pos)),Number(this.file_pos));this.file_pos+=BigInt(buffer.byteLength);nwritten+=iovec.buf_len}return{ret:0,nwritten}}fd_filestat_get(){return{ret:0,filestat:this.file.stat()}}constructor(file){super();this.file_pos=0n;this.file=file}}export class OpenSyncOPFSFile extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_REGULAR_FILE,0)}}fd_filestat_get(){return{ret:0,filestat:new wasi.Filestat(wasi.FILETYPE_REGULAR_FILE,BigInt(this.file.handle.getSize()))}}fd_read(view8,iovs){let nread=0;for(const iovec of iovs){if(this.position<this.file.handle.getSize()){const buf=new Uint8Array(view8.buffer,iovec.buf,iovec.buf_len);const n=this.file.handle.read(buf,{at:Number(this.position)});this.position+=BigInt(n);nread+=n}else{break}}return{ret:0,nread}}fd_seek(offset,whence){let calculated_offset;switch(whence){case wasi.WHENCE_SET:calculated_offset=BigInt(offset);break;case wasi.WHENCE_CUR:calculated_offset=this.position+BigInt(offset);break;case wasi.WHENCE_END:calculated_offset=BigInt(this.file.handle.getSize())+BigInt(offset);break;default:return{ret:wasi.ERRNO_INVAL,offset:0n}}if(calculated_offset<0){return{ret:wasi.ERRNO_INVAL,offset:0n}}this.position=calculated_offset;return{ret:wasi.ERRNO_SUCCESS,offset:this.position}}fd_write(view8,iovs){let nwritten=0;if(this.file.readonly)return{ret:wasi.ERRNO_BADF,nwritten};for(const iovec of iovs){const buf=new Uint8Array(view8.buffer,iovec.buf,iovec.buf_len);const n=this.file.handle.write(buf,{at:Number(this.position)});this.position+=BigInt(n);nwritten+=n}return{ret:wasi.ERRNO_SUCCESS,nwritten}}fd_datasync(){this.file.handle.flush();return wasi.ERRNO_SUCCESS}fd_sync(){return this.fd_datasync()}fd_close(){return wasi.ERRNO_SUCCESS}constructor(file){super();this.position=0n;this.file=file}}export class OpenDirectory extends Fd{fd_fdstat_get(){return{ret:0,fdstat:new wasi.Fdstat(wasi.FILETYPE_DIRECTORY,0)}}fd_readdir_single(cookie){if(debug.enabled){debug.log("readdir_single",cookie);debug.log(cookie,Object.keys(this.dir.contents))}debug.log(cookie,Object.keys(this.dir.contents).slice(Number(cookie)));if(cookie>=BigInt(Object.keys(this.dir.contents).length)){return{ret:0,dirent:null}}const name=Object.keys(this.dir.contents)[Number(cookie)];const entry=this.dir.contents[name];return{ret:0,dirent:new wasi.Dirent(cookie+1n,name,entry.stat().filetype)}}path_filestat_get(flags,path){const entry=this.dir.get_entry_for_path(path);if(entry==null){return{ret:wasi.ERRNO_NOENT,filestat:null}}return{ret:0,filestat:entry.stat()}}path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags){let entry=this.dir.get_entry_for_path(path);if(entry==null){if((oflags&wasi.OFLAGS_CREAT)==wasi.OFLAGS_CREAT){entry=this.dir.create_entry_for_path(path,(oflags&wasi.OFLAGS_DIRECTORY)==wasi.OFLAGS_DIRECTORY)}else{return{ret:wasi.ERRNO_NOENT,fd_obj:null}}}else if((oflags&wasi.OFLAGS_EXCL)==wasi.OFLAGS_EXCL){return{ret:wasi.ERRNO_EXIST,fd_obj:null}}if((oflags&wasi.OFLAGS_DIRECTORY)==wasi.OFLAGS_DIRECTORY&&entry.stat().filetype!==wasi.FILETYPE_DIRECTORY){return{ret:wasi.ERRNO_NOTDIR,fd_obj:null}}if(entry.readonly&&(fs_rights_base&BigInt(wasi.RIGHTS_FD_WRITE))==BigInt(wasi.RIGHTS_FD_WRITE)){return{ret:wasi.ERRNO_PERM,fd_obj:null}}if(!(entry instanceof Directory)&&(oflags&wasi.OFLAGS_TRUNC)==wasi.OFLAGS_TRUNC){const ret=entry.truncate();if(ret!=wasi.ERRNO_SUCCESS)return{ret,fd_obj:null}}return{ret:wasi.ERRNO_SUCCESS,fd_obj:entry.open(fd_flags)}}path_create_directory(path){return this.path_open(0,path,wasi.OFLAGS_CREAT|wasi.OFLAGS_DIRECTORY,0n,0n,0).ret}constructor(dir){super();this.dir=dir}}export class PreopenDirectory extends OpenDirectory{fd_prestat_get(){return{ret:0,prestat:wasi.Prestat.dir(this.prestat_name.length)}}fd_prestat_dir_name(){return{ret:0,prestat_dir_name:this.prestat_name}}constructor(name,contents){super(new Directory(contents));this.prestat_name=new TextEncoder().encode(name)}}

@@ -1,1 +0,1 @@

export function strace(imports,no_trace){return new Proxy(imports,{get(target,prop,receiver){let f=Reflect.get(target,prop,receiver);if(no_trace.includes(prop)){return f}return function(...args){console.log(prop,"(",...args,")");let result=Reflect.apply(f,receiver,args);console.log(" =",result);return result}}})}
export function strace(imports,no_trace){return new Proxy(imports,{get(target,prop,receiver){const f=Reflect.get(target,prop,receiver);if(no_trace.includes(prop)){return f}return function(...args){console.log(prop,"(",...args,")");const result=Reflect.apply(f,receiver,args);console.log(" =",result);return result}}})}

@@ -1,1 +0,1 @@

export const FD_STDIN=0;export const FD_STDOUT=1;export const FD_STDERR=2;export const CLOCKID_REALTIME=0;export const CLOCKID_MONOTONIC=1;export const CLOCKID_PROCESS_CPUTIME_ID=2;export const CLOCKID_THREAD_CPUTIME_ID=3;export const ERRNO_SUCCESS=0;export const ERRNO_2BIG=1;export const ERRNO_ACCES=2;export const ERRNO_ADDRINUSE=3;export const ERRNO_ADDRNOTAVAIL=4;export const ERRNO_AFNOSUPPORT=5;export const ERRNO_AGAIN=6;export const ERRNO_ALREADY=7;export const ERRNO_BADF=8;export const ERRNO_BADMSG=9;export const ERRNO_BUSY=10;export const ERRNO_CANCELED=11;export const ERRNO_CHILD=12;export const ERRNO_CONNABORTED=13;export const ERRNO_CONNREFUSED=14;export const ERRNO_CONNRESET=15;export const ERRNO_DEADLK=16;export const ERRNO_DESTADDRREQ=17;export const ERRNO_DOM=18;export const ERRNO_DQUOT=19;export const ERRNO_EXIST=20;export const ERRNO_FAULT=21;export const ERRNO_FBIG=22;export const ERRNO_HOSTUNREACH=23;export const ERRNO_IDRM=24;export const ERRNO_ILSEQ=25;export const ERRNO_INPROGRESS=26;export const ERRNO_INTR=27;export const ERRNO_INVAL=28;export const ERRNO_IO=29;export const ERRNO_ISCONN=30;export const ERRNO_ISDIR=31;export const ERRNO_LOOP=32;export const ERRNO_MFILE=33;export const ERRNO_MLINK=34;export const ERRNO_MSGSIZE=35;export const ERRNO_MULTIHOP=36;export const ERRNO_NAMETOOLONG=37;export const ERRNO_NETDOWN=38;export const ERRNO_NETRESET=39;export const ERRNO_NETUNREACH=40;export const ERRNO_NFILE=41;export const ERRNO_NOBUFS=42;export const ERRNO_NODEV=43;export const ERRNO_NOENT=44;export const ERRNO_NOEXEC=45;export const ERRNO_NOLCK=46;export const ERRNO_NOLINK=47;export const ERRNO_NOMEM=48;export const ERRNO_NOMSG=49;export const ERRNO_NOPROTOOPT=50;export const ERRNO_NOSPC=51;export const ERRNO_NOSYS=52;export const ERRNO_NOTCONN=53;export const ERRNO_NOTDIR=54;export const ERRNO_NOTEMPTY=55;export const ERRNO_NOTRECOVERABLE=56;export const ERRNO_NOTSOCK=57;export const ERRNO_NOTSUP=58;export const ERRNO_NOTTY=59;export const ERRNO_NXIO=60;export const ERRNO_OVERFLOW=61;export const ERRNO_OWNERDEAD=62;export const ERRNO_PERM=63;export const ERRNO_PIPE=64;export const ERRNO_PROTO=65;export const ERRNO_PROTONOSUPPORT=66;export const ERRNO_PROTOTYPE=67;export const ERRNO_RANGE=68;export const ERRNO_ROFS=69;export const ERRNO_SPIPE=70;export const ERRNO_SRCH=71;export const ERRNO_STALE=72;export const ERRNO_TIMEDOUT=73;export const ERRNO_TXTBSY=74;export const ERRNO_XDEV=75;export const ERRNO_NOTCAPABLE=76;export const RIGHTS_FD_DATASYNC=1<<0;export const RIGHTS_FD_READ=1<<1;export const RIGHTS_FD_SEEK=1<<2;export const RIGHTS_FD_FDSTAT_SET_FLAGS=1<<3;export const RIGHTS_FD_SYNC=1<<4;export const RIGHTS_FD_TELL=1<<5;export const RIGHTS_FD_WRITE=1<<6;export const RIGHTS_FD_ADVISE=1<<7;export const RIGHTS_FD_ALLOCATE=1<<8;export const RIGHTS_PATH_CREATE_DIRECTORY=1<<9;export const RIGHTS_PATH_CREATE_FILE=1<<10;export const RIGHTS_PATH_LINK_SOURCE=1<<11;export const RIGHTS_PATH_LINK_TARGET=1<<12;export const RIGHTS_PATH_OPEN=1<<13;export const RIGHTS_FD_READDIR=1<<14;export const RIGHTS_PATH_READLINK=1<<15;export const RIGHTS_PATH_RENAME_SOURCE=1<<16;export const RIGHTS_PATH_RENAME_TARGET=1<<17;export const RIGHTS_PATH_FILESTAT_GET=1<<18;export const RIGHTS_PATH_FILESTAT_SET_SIZE=1<<19;export const RIGHTS_PATH_FILESTAT_SET_TIMES=1<<20;export const RIGHTS_FD_FILESTAT_GET=1<<21;export const RIGHTS_FD_FILESTAT_SET_SIZE=1<<22;export const RIGHTS_FD_FILESTAT_SET_TIMES=1<<23;export const RIGHTS_PATH_SYMLINK=1<<24;export const RIGHTS_PATH_REMOVE_DIRECTORY=1<<25;export const RIGHTS_PATH_UNLINK_FILE=1<<26;export const RIGHTS_POLL_FD_READWRITE=1<<27;export const RIGHTS_SOCK_SHUTDOWN=1<<28;export class Iovec{static read_bytes(view,ptr){let iovec=new Iovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){let iovecs=[];for(let i=0;i<len;i++){iovecs.push(Iovec.read_bytes(view,ptr+8*i))}return iovecs}}export class Ciovec{static read_bytes(view,ptr){let iovec=new Ciovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){let iovecs=[];for(let i=0;i<len;i++){iovecs.push(Ciovec.read_bytes(view,ptr+8*i))}return iovecs}}export const WHENCE_SET=0;export const WHENCE_CUR=1;export const WHENCE_END=2;export const FILETYPE_UNKNOWN=0;export const FILETYPE_BLOCK_DEVICE=1;export const FILETYPE_CHARACTER_DEVICE=2;export const FILETYPE_DIRECTORY=3;export const FILETYPE_REGULAR_FILE=4;export const FILETYPE_SOCKET_DGRAM=5;export const FILETYPE_SOCKET_STREAM=6;export const FILETYPE_SYMBOLIC_LINK=7;export class Dirent{head_length(){return 24}name_length(){return this.dir_name.byteLength}write_head_bytes(view,ptr){view.setBigUint64(ptr,this.d_next,true);view.setBigUint64(ptr+8,this.d_ino,true);view.setUint32(ptr+16,this.dir_name.length,true);view.setUint8(ptr+20,this.d_type)}write_name_bytes(view8,ptr,buf_len){view8.set(this.dir_name.slice(0,Math.min(this.dir_name.byteLength,buf_len)),ptr)}constructor(next_cookie,name,type){this.d_ino=1n;let encoded_name=new TextEncoder("utf-8").encode(name);this.d_next=next_cookie;this.d_namlen=encoded_name.byteLength;this.d_type=type;this.dir_name=encoded_name}}export const ADVICE_NORMAL=0;export const ADVICE_SEQUENTIAL=1;export const ADVICE_RANDOM=2;export const ADVICE_WILLNEED=3;export const ADVICE_DONTNEED=4;export const ADVICE_NOREUSE=5;export const FDFLAGS_APPEND=1<<0;export const FDFLAGS_DSYNC=1<<1;export const FDFLAGS_NONBLOCK=1<<2;export const FDFLAGS_RSYNC=1<<3;export const FDFLAGS_SYNC=1<<4;export class Fdstat{write_bytes(view,ptr){view.setUint8(ptr,this.fs_filetype);view.setUint16(ptr+2,this.fs_flags,true);view.setBigUint64(ptr+8,this.fs_rights_base,true);view.setBigUint64(ptr+16,this.fs_rights_inherited,true)}constructor(filetype,flags){this.fs_rights_base=0n;this.fs_rights_inherited=0n;this.fs_filetype=filetype;this.fs_flags=flags}}export const FSTFLAGS_ATIM=1<<0;export const FSTFLAGS_ATIM_NOW=1<<1;export const FSTFLAGS_MTIM=1<<2;export const FSTFLAGS_MTIM_NOW=1<<3;export const OFLAGS_CREAT=1<<0;export const OFLAGS_DIRECTORY=1<<1;export const OFLAGS_EXCL=1<<2;export const OFLAGS_TRUNC=1<<3;export class Filestat{write_bytes(view,ptr){view.setBigUint64(ptr,this.dev,true);view.setBigUint64(ptr+8,this.ino,true);view.setUint8(ptr+16,this.filetype);view.setBigUint64(ptr+24,this.nlink,true);view.setBigUint64(ptr+32,this.size,true);view.setBigUint64(ptr+38,this.atim,true);view.setBigUint64(ptr+46,this.mtim,true);view.setBigUint64(ptr+52,this.ctim,true)}constructor(filetype,size){this.dev=0n;this.ino=0n;this.nlink=0n;this.atim=0n;this.mtim=0n;this.ctim=0n;this.filetype=filetype;this.size=size}}export const EVENTTYPE_CLOCK=0;export const EVENTTYPE_FD_READ=1;export const EVENTTYPE_FD_WRITE=2;export const EVENTRWFLAGS_FD_READWRITE_HANGUP=1<<0;export const SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME=1<<0;export const SIGNAL_NONE=0;export const SIGNAL_HUP=1;export const SIGNAL_INT=2;export const SIGNAL_QUIT=3;export const SIGNAL_ILL=4;export const SIGNAL_TRAP=5;export const SIGNAL_ABRT=6;export const SIGNAL_BUS=7;export const SIGNAL_FPE=8;export const SIGNAL_KILL=9;export const SIGNAL_USR1=10;export const SIGNAL_SEGV=11;export const SIGNAL_USR2=12;export const SIGNAL_PIPE=13;export const SIGNAL_ALRM=14;export const SIGNAL_TERM=15;export const SIGNAL_CHLD=16;export const SIGNAL_CONT=17;export const SIGNAL_STOP=18;export const SIGNAL_TSTP=19;export const SIGNAL_TTIN=20;export const SIGNAL_TTOU=21;export const SIGNAL_URG=22;export const SIGNAL_XCPU=23;export const SIGNAL_XFSZ=24;export const SIGNAL_VTALRM=25;export const SIGNAL_PROF=26;export const SIGNAL_WINCH=27;export const SIGNAL_POLL=28;export const SIGNAL_PWR=29;export const SIGNAL_SYS=30;export const RIFLAGS_RECV_PEEK=1<<0;export const RIFLAGS_RECV_WAITALL=1<<1;export const ROFLAGS_RECV_DATA_TRUNCATED=1<<0;export const SDFLAGS_RD=1<<0;export const SDFLAGS_WR=1<<1;export const PREOPENTYPE_DIR=0;export class PrestatDir{write_bytes(view,ptr){view.setUint32(ptr,this.pr_name_len,true)}constructor(name_len){this.pr_name_len=name_len}}export class Prestat{static dir(name_len){let prestat=new Prestat;prestat.tag=PREOPENTYPE_DIR;prestat.inner=new PrestatDir(name_len);return prestat}write_bytes(view,ptr){view.setUint32(ptr,this.tag,true);this.inner.write_bytes(view,ptr+4)}}
export const FD_STDIN=0;export const FD_STDOUT=1;export const FD_STDERR=2;export const CLOCKID_REALTIME=0;export const CLOCKID_MONOTONIC=1;export const CLOCKID_PROCESS_CPUTIME_ID=2;export const CLOCKID_THREAD_CPUTIME_ID=3;export const ERRNO_SUCCESS=0;export const ERRNO_2BIG=1;export const ERRNO_ACCES=2;export const ERRNO_ADDRINUSE=3;export const ERRNO_ADDRNOTAVAIL=4;export const ERRNO_AFNOSUPPORT=5;export const ERRNO_AGAIN=6;export const ERRNO_ALREADY=7;export const ERRNO_BADF=8;export const ERRNO_BADMSG=9;export const ERRNO_BUSY=10;export const ERRNO_CANCELED=11;export const ERRNO_CHILD=12;export const ERRNO_CONNABORTED=13;export const ERRNO_CONNREFUSED=14;export const ERRNO_CONNRESET=15;export const ERRNO_DEADLK=16;export const ERRNO_DESTADDRREQ=17;export const ERRNO_DOM=18;export const ERRNO_DQUOT=19;export const ERRNO_EXIST=20;export const ERRNO_FAULT=21;export const ERRNO_FBIG=22;export const ERRNO_HOSTUNREACH=23;export const ERRNO_IDRM=24;export const ERRNO_ILSEQ=25;export const ERRNO_INPROGRESS=26;export const ERRNO_INTR=27;export const ERRNO_INVAL=28;export const ERRNO_IO=29;export const ERRNO_ISCONN=30;export const ERRNO_ISDIR=31;export const ERRNO_LOOP=32;export const ERRNO_MFILE=33;export const ERRNO_MLINK=34;export const ERRNO_MSGSIZE=35;export const ERRNO_MULTIHOP=36;export const ERRNO_NAMETOOLONG=37;export const ERRNO_NETDOWN=38;export const ERRNO_NETRESET=39;export const ERRNO_NETUNREACH=40;export const ERRNO_NFILE=41;export const ERRNO_NOBUFS=42;export const ERRNO_NODEV=43;export const ERRNO_NOENT=44;export const ERRNO_NOEXEC=45;export const ERRNO_NOLCK=46;export const ERRNO_NOLINK=47;export const ERRNO_NOMEM=48;export const ERRNO_NOMSG=49;export const ERRNO_NOPROTOOPT=50;export const ERRNO_NOSPC=51;export const ERRNO_NOSYS=52;export const ERRNO_NOTCONN=53;export const ERRNO_NOTDIR=54;export const ERRNO_NOTEMPTY=55;export const ERRNO_NOTRECOVERABLE=56;export const ERRNO_NOTSOCK=57;export const ERRNO_NOTSUP=58;export const ERRNO_NOTTY=59;export const ERRNO_NXIO=60;export const ERRNO_OVERFLOW=61;export const ERRNO_OWNERDEAD=62;export const ERRNO_PERM=63;export const ERRNO_PIPE=64;export const ERRNO_PROTO=65;export const ERRNO_PROTONOSUPPORT=66;export const ERRNO_PROTOTYPE=67;export const ERRNO_RANGE=68;export const ERRNO_ROFS=69;export const ERRNO_SPIPE=70;export const ERRNO_SRCH=71;export const ERRNO_STALE=72;export const ERRNO_TIMEDOUT=73;export const ERRNO_TXTBSY=74;export const ERRNO_XDEV=75;export const ERRNO_NOTCAPABLE=76;export const RIGHTS_FD_DATASYNC=1<<0;export const RIGHTS_FD_READ=1<<1;export const RIGHTS_FD_SEEK=1<<2;export const RIGHTS_FD_FDSTAT_SET_FLAGS=1<<3;export const RIGHTS_FD_SYNC=1<<4;export const RIGHTS_FD_TELL=1<<5;export const RIGHTS_FD_WRITE=1<<6;export const RIGHTS_FD_ADVISE=1<<7;export const RIGHTS_FD_ALLOCATE=1<<8;export const RIGHTS_PATH_CREATE_DIRECTORY=1<<9;export const RIGHTS_PATH_CREATE_FILE=1<<10;export const RIGHTS_PATH_LINK_SOURCE=1<<11;export const RIGHTS_PATH_LINK_TARGET=1<<12;export const RIGHTS_PATH_OPEN=1<<13;export const RIGHTS_FD_READDIR=1<<14;export const RIGHTS_PATH_READLINK=1<<15;export const RIGHTS_PATH_RENAME_SOURCE=1<<16;export const RIGHTS_PATH_RENAME_TARGET=1<<17;export const RIGHTS_PATH_FILESTAT_GET=1<<18;export const RIGHTS_PATH_FILESTAT_SET_SIZE=1<<19;export const RIGHTS_PATH_FILESTAT_SET_TIMES=1<<20;export const RIGHTS_FD_FILESTAT_GET=1<<21;export const RIGHTS_FD_FILESTAT_SET_SIZE=1<<22;export const RIGHTS_FD_FILESTAT_SET_TIMES=1<<23;export const RIGHTS_PATH_SYMLINK=1<<24;export const RIGHTS_PATH_REMOVE_DIRECTORY=1<<25;export const RIGHTS_PATH_UNLINK_FILE=1<<26;export const RIGHTS_POLL_FD_READWRITE=1<<27;export const RIGHTS_SOCK_SHUTDOWN=1<<28;export class Iovec{static read_bytes(view,ptr){const iovec=new Iovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){const iovecs=[];for(let i=0;i<len;i++){iovecs.push(Iovec.read_bytes(view,ptr+8*i))}return iovecs}}export class Ciovec{static read_bytes(view,ptr){const iovec=new Ciovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){const iovecs=[];for(let i=0;i<len;i++){iovecs.push(Ciovec.read_bytes(view,ptr+8*i))}return iovecs}}export const WHENCE_SET=0;export const WHENCE_CUR=1;export const WHENCE_END=2;export const FILETYPE_UNKNOWN=0;export const FILETYPE_BLOCK_DEVICE=1;export const FILETYPE_CHARACTER_DEVICE=2;export const FILETYPE_DIRECTORY=3;export const FILETYPE_REGULAR_FILE=4;export const FILETYPE_SOCKET_DGRAM=5;export const FILETYPE_SOCKET_STREAM=6;export const FILETYPE_SYMBOLIC_LINK=7;export class Dirent{head_length(){return 24}name_length(){return this.dir_name.byteLength}write_head_bytes(view,ptr){view.setBigUint64(ptr,this.d_next,true);view.setBigUint64(ptr+8,this.d_ino,true);view.setUint32(ptr+16,this.dir_name.length,true);view.setUint8(ptr+20,this.d_type)}write_name_bytes(view8,ptr,buf_len){view8.set(this.dir_name.slice(0,Math.min(this.dir_name.byteLength,buf_len)),ptr)}constructor(next_cookie,name,type){this.d_ino=1n;const encoded_name=new TextEncoder().encode(name);this.d_next=next_cookie;this.d_namlen=encoded_name.byteLength;this.d_type=type;this.dir_name=encoded_name}}export const ADVICE_NORMAL=0;export const ADVICE_SEQUENTIAL=1;export const ADVICE_RANDOM=2;export const ADVICE_WILLNEED=3;export const ADVICE_DONTNEED=4;export const ADVICE_NOREUSE=5;export const FDFLAGS_APPEND=1<<0;export const FDFLAGS_DSYNC=1<<1;export const FDFLAGS_NONBLOCK=1<<2;export const FDFLAGS_RSYNC=1<<3;export const FDFLAGS_SYNC=1<<4;export class Fdstat{write_bytes(view,ptr){view.setUint8(ptr,this.fs_filetype);view.setUint16(ptr+2,this.fs_flags,true);view.setBigUint64(ptr+8,this.fs_rights_base,true);view.setBigUint64(ptr+16,this.fs_rights_inherited,true)}constructor(filetype,flags){this.fs_rights_base=0n;this.fs_rights_inherited=0n;this.fs_filetype=filetype;this.fs_flags=flags}}export const FSTFLAGS_ATIM=1<<0;export const FSTFLAGS_ATIM_NOW=1<<1;export const FSTFLAGS_MTIM=1<<2;export const FSTFLAGS_MTIM_NOW=1<<3;export const OFLAGS_CREAT=1<<0;export const OFLAGS_DIRECTORY=1<<1;export const OFLAGS_EXCL=1<<2;export const OFLAGS_TRUNC=1<<3;export class Filestat{write_bytes(view,ptr){view.setBigUint64(ptr,this.dev,true);view.setBigUint64(ptr+8,this.ino,true);view.setUint8(ptr+16,this.filetype);view.setBigUint64(ptr+24,this.nlink,true);view.setBigUint64(ptr+32,this.size,true);view.setBigUint64(ptr+38,this.atim,true);view.setBigUint64(ptr+46,this.mtim,true);view.setBigUint64(ptr+52,this.ctim,true)}constructor(filetype,size){this.dev=0n;this.ino=0n;this.nlink=0n;this.atim=0n;this.mtim=0n;this.ctim=0n;this.filetype=filetype;this.size=size}}export const EVENTTYPE_CLOCK=0;export const EVENTTYPE_FD_READ=1;export const EVENTTYPE_FD_WRITE=2;export const EVENTRWFLAGS_FD_READWRITE_HANGUP=1<<0;export const SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME=1<<0;export const SIGNAL_NONE=0;export const SIGNAL_HUP=1;export const SIGNAL_INT=2;export const SIGNAL_QUIT=3;export const SIGNAL_ILL=4;export const SIGNAL_TRAP=5;export const SIGNAL_ABRT=6;export const SIGNAL_BUS=7;export const SIGNAL_FPE=8;export const SIGNAL_KILL=9;export const SIGNAL_USR1=10;export const SIGNAL_SEGV=11;export const SIGNAL_USR2=12;export const SIGNAL_PIPE=13;export const SIGNAL_ALRM=14;export const SIGNAL_TERM=15;export const SIGNAL_CHLD=16;export const SIGNAL_CONT=17;export const SIGNAL_STOP=18;export const SIGNAL_TSTP=19;export const SIGNAL_TTIN=20;export const SIGNAL_TTOU=21;export const SIGNAL_URG=22;export const SIGNAL_XCPU=23;export const SIGNAL_XFSZ=24;export const SIGNAL_VTALRM=25;export const SIGNAL_PROF=26;export const SIGNAL_WINCH=27;export const SIGNAL_POLL=28;export const SIGNAL_PWR=29;export const SIGNAL_SYS=30;export const RIFLAGS_RECV_PEEK=1<<0;export const RIFLAGS_RECV_WAITALL=1<<1;export const ROFLAGS_RECV_DATA_TRUNCATED=1<<0;export const SDFLAGS_RD=1<<0;export const SDFLAGS_WR=1<<1;export const PREOPENTYPE_DIR=0;export class PrestatDir{write_bytes(view,ptr){view.setUint32(ptr,this.pr_name_len,true)}constructor(name_len){this.pr_name_len=name_len}}export class Prestat{static dir(name_len){const prestat=new Prestat;prestat.tag=PREOPENTYPE_DIR;prestat.inner=new PrestatDir(name_len);return prestat}write_bytes(view,ptr){view.setUint32(ptr,this.tag,true);this.inner.write_bytes(view,ptr+4)}}

@@ -1,1 +0,1 @@

import*as wasi from"./wasi_defs.js";let WASI=class WASI{start(instance){this.inst=instance;instance.exports._start()}initialize(instance){this.inst=instance;instance.exports._initialize()}constructor(args,env,fds){this.args=[];this.env=[];this.fds=[];this.args=args;this.env=env;this.fds=fds;let self=this;this.wasiImport={args_sizes_get(argc,argv_buf_size){let buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(argc,self.args.length,true);let buf_size=0;for(let arg of self.args){buf_size+=arg.length+1}buffer.setUint32(argv_buf_size,buf_size,true);return 0},args_get(argv,argv_buf){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);let orig_argv_buf=argv_buf;for(let i=0;i<self.args.length;i++){buffer.setUint32(argv,argv_buf,true);argv+=4;let arg=new TextEncoder("utf-8").encode(self.args[i]);buffer8.set(arg,argv_buf);buffer.setUint8(argv_buf+arg.length,0);argv_buf+=arg.length+1}return 0},environ_sizes_get(environ_count,environ_size){let buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(environ_count,self.env.length,true);let buf_size=0;for(let environ of self.env){buf_size+=environ.length+1}buffer.setUint32(environ_size,buf_size,true);return 0},environ_get(environ,environ_buf){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);let orig_environ_buf=environ_buf;for(let i=0;i<env.length;i++){buffer.setUint32(environ,environ_buf,true);environ+=4;let e=new TextEncoder("utf-8").encode(env[i]);buffer8.set(e,environ_buf);buffer.setUint8(environ_buf+e.length,0);environ_buf+=e.length+1}return 0},clock_res_get(id,res_ptr){throw"unimplemented"},clock_time_get(id,precision,time){let buffer=new DataView(self.inst.exports.memory.buffer);if(id===wasi.CLOCKID_REALTIME){buffer.setBigUint64(time,BigInt(new Date().getTime())*1000000n,true)}else if(id==wasi.CLOCKID_MONOTONIC){let monotonic_time;try{monotonic_time=BigInt(Math.round(performance.now()*1e6))}catch(e){monotonic_time=0n}buffer.setBigUint64(time,monotonic_time,true)}else{buffer.setBigUint64(time,0n,true)}return 0},fd_advise(fd,offset,len,advice){if(self.fds[fd]!=undefined){return self.fds[fd].fd_advise(offset,len,advice)}else{return wasi.ERRNO_BADF}},fd_allocate(fd,offset,len){if(self.fds[fd]!=undefined){return self.fds[fd].fd_allocate(offset,len)}else{return wasi.ERRNO_BADF}},fd_close(fd){if(self.fds[fd]!=undefined){let ret=self.fds[fd].fd_close();self.fds[fd]=undefined;return ret}else{return wasi.ERRNO_BADF}},fd_datasync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_datasync()}else{return wasi.ERRNO_BADF}},fd_fdstat_get(fd,fdstat_ptr){if(self.fds[fd]!=undefined){let{ret,fdstat}=self.fds[fd].fd_fdstat_get();if(fdstat!=null){fdstat.write_bytes(new DataView(self.inst.exports.memory.buffer),fdstat_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_fdstat_set_flags(fd,flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_flags(flags)}else{return wasi.ERRNO_BADF}},fd_fdstat_set_rights(fd,fs_rights_base,fs_rights_inheriting){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting)}else{return wasi.ERRNO_BADF}},fd_filestat_get(fd,filestat_ptr){if(self.fds[fd]!=undefined){let{ret,filestat}=self.fds[fd].fd_filestat_get();if(filestat!=null){filestat.write_bytes(new DataView(self.inst.exports.memory.buffer),filestat_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_filestat_set_size(fd,size){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_size(size)}else{return wasi.ERRNO_BADF}},fd_filestat_set_times(fd,atim,mtim,fst_flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_times(atim,mtim,fst_flags)}else{return wasi.ERRNO_BADF}},fd_pread(fd,iovs_ptr,iovs_len,offset,nread_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let iovecs=wasi.Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let{ret,nread}=self.fds[fd].fd_pread(buffer8,iovecs,offset);buffer.setUint32(nread_ptr,nread,true);return ret}else{return wasi.ERRNO_BADF}},fd_prestat_get(fd,buf_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let{ret,prestat}=self.fds[fd].fd_prestat_get();if(prestat!=null){prestat.write_bytes(buffer,buf_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_prestat_dir_name(fd,path_ptr,path_len){if(self.fds[fd]!=undefined){let{ret,prestat_dir_name}=self.fds[fd].fd_prestat_dir_name();if(prestat_dir_name!=null){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);buffer8.set(prestat_dir_name,path_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_pwrite(fd,iovs_ptr,iovs_len,offset,nwritten_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let iovecs=wasi.Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let{ret,nwritten}=self.fds[fd].fd_pwrite(buffer8,iovecs,offset);buffer.setUint32(nwritten_ptr,nwritten,true);return ret}else{return wasi.ERRNO_BADF}},fd_read(fd,iovs_ptr,iovs_len,nread_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let iovecs=wasi.Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let{ret,nread}=self.fds[fd].fd_read(buffer8,iovecs);buffer.setUint32(nread_ptr,nread,true);return ret}else{return wasi.ERRNO_BADF}},fd_readdir(fd,buf,buf_len,cookie,bufused_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let bufused=0;while(true){let{ret,dirent}=self.fds[fd].fd_readdir_single(cookie);if(ret!=0){buffer.setUint32(bufused_ptr,bufused,true);return ret}if(dirent==null){break}if(buf_len-bufused<dirent.head_length()){bufused=buf_len;break}let head_bytes=new ArrayBuffer(dirent.head_length());dirent.write_head_bytes(new DataView(head_bytes),0);buffer8.set(new Uint8Array(head_bytes).slice(0,Math.min(head_bytes.byteLength,buf_len-bufused)),buf);buf+=dirent.head_length();bufused+=dirent.head_length();if(buf_len-bufused<dirent.name_length()){bufused=buf_len;break}dirent.write_name_bytes(buffer8,buf,buf_len-bufused);buf+=dirent.name_length();bufused+=dirent.name_length();cookie=dirent.d_next}buffer.setUint32(bufused_ptr,bufused,true);return 0}else{return wasi.ERRNO_BADF}},fd_renumber(fd,to){if(self.fds[fd]!=undefined&&self.fds[to]!=undefined){let ret=self.fds[to].fd_close();if(ret!=0){return ret}self.fds[to]=self.fds[fd];self.fds[fd]=undefined;return 0}else{return wasi.ERRNO_BADF}},fd_seek(fd,offset,whence,offset_out_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let{ret,offset:offset_out}=self.fds[fd].fd_seek(offset,whence);buffer.setBigInt64(offset_out_ptr,offset_out,true);return ret}else{return wasi.ERRNO_BADF}},fd_sync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_sync()}else{return wasi.ERRNO_BADF}},fd_tell(fd,offset_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let{ret,offset}=self.fds[fd].fd_tell();buffer.setBigUint64(offset_ptr,offset,true);return ret}else{return wasi.ERRNO_BADF}},fd_write(fd,iovs_ptr,iovs_len,nwritten_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let iovecs=wasi.Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let{ret,nwritten}=self.fds[fd].fd_write(buffer8,iovecs);buffer.setUint32(nwritten_ptr,nwritten,true);return ret}else{return wasi.ERRNO_BADF}},path_create_directory(fd,path_ptr,path_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_create_directory(path)}},path_filestat_get(fd,flags,path_ptr,path_len,filestat_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));let{ret,filestat}=self.fds[fd].path_filestat_get(flags,path);if(filestat!=null){filestat.write_bytes(buffer,filestat_ptr)}return ret}else{return wasi.ERRNO_BADF}},path_filestat_set_times(fd,flags,path_ptr,path_len,atim,mtim,fst_flags){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_filestat_set_times(flags,path,atim,mtim,fst_flags)}else{return wasi.ERRNO_BADF}},path_link(old_fd,old_flags,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[old_fd]!=undefined&&self.fds[new_fd]!=undefined){let old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));let new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));return self.fds[new_fd].path_link(old_fd,old_flags,old_path,new_path)}else{return wasi.ERRNO_BADF}},path_open(fd,dirflags,path_ptr,path_len,oflags,fs_rights_base,fs_rights_inheriting,fd_flags,opened_fd_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));let{ret,fd_obj}=self.fds[fd].path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags);if(ret!=0){return ret}self.fds.push(fd_obj);let opened_fd=self.fds.length-1;buffer.setUint32(opened_fd_ptr,opened_fd,true);return 0}else{return wasi.ERRNO_BADF}},path_readlink(fd,path_ptr,path_len,buf_ptr,buf_len,nread_ptr){let buffer=new DataView(self.inst.exports.memory.buffer);let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));let{ret,data}=self.fds[fd].path_readlink(path);if(data!=null){if(data.length>buf_len){buffer.setUint32(nread_ptr,0,true);return wasi.ERRNO_BADF}buffer8.set(data,buf_ptr);buffer.setUint32(nread_ptr,data.length,true)}return ret}else{return wasi.ERRNO_BADF}},path_remove_directory(fd,path_ptr,path_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_remove_directory(path)}else{return wasi.ERRNO_BADF}},path_rename(fd,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){throw"FIXME what is the best abstraction for this?"},path_symlink(old_path_ptr,old_path_len,fd,new_path_ptr,new_path_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));let new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));return self.fds[fd].path_symlink(old_path,new_path)}else{return wasi.ERRNO_BADF}},path_unlink_file(fd,path_ptr,path_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_unlink_file(path)}else{return wasi.ERRNO_BADF}},poll_oneoff(in_,out,nsubscriptions){throw"async io not supported"},proc_exit(exit_code){throw"exit with exit code "+exit_code},proc_raise(sig){throw"raised signal "+sig},sched_yield(){},random_get(buf,buf_len){let buffer8=new Uint8Array(self.inst.exports.memory.buffer);for(let i=0;i<buf_len;i++){buffer8[buf+i]=Math.random()*256|0}},sock_recv(fd,ri_data,ri_flags){throw"sockets not supported"},sock_send(fd,si_data,si_flags){throw"sockets not supported"},sock_shutdown(fd,how){throw"sockets not supported"},sock_accept(fd,flags){throw"sockets not supported"}}}};export{WASI as default};
import*as wasi from"./wasi_defs.js";import{debug}from"./debug.js";let WASI=class WASI{start(instance){this.inst=instance;instance.exports._start()}initialize(instance){this.inst=instance;instance.exports._initialize()}constructor(args,env,fds,options={}){this.args=[];this.env=[];this.fds=[];debug.enable(options.debug);this.args=args;this.env=env;this.fds=fds;const self=this;this.wasiImport={args_sizes_get(argc,argv_buf_size){const buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(argc,self.args.length,true);let buf_size=0;for(const arg of self.args){buf_size+=arg.length+1}buffer.setUint32(argv_buf_size,buf_size,true);debug.log(buffer.getUint32(argc,true),buffer.getUint32(argv_buf_size,true));return 0},args_get(argv,argv_buf){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);const orig_argv_buf=argv_buf;for(let i=0;i<self.args.length;i++){buffer.setUint32(argv,argv_buf,true);argv+=4;const arg=new TextEncoder().encode(self.args[i]);buffer8.set(arg,argv_buf);buffer.setUint8(argv_buf+arg.length,0);argv_buf+=arg.length+1}if(debug.enabled){debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_argv_buf,argv_buf)))}return 0},environ_sizes_get(environ_count,environ_size){const buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(environ_count,self.env.length,true);let buf_size=0;for(const environ of self.env){buf_size+=environ.length+1}buffer.setUint32(environ_size,buf_size,true);debug.log(buffer.getUint32(environ_count,true),buffer.getUint32(environ_size,true));return 0},environ_get(environ,environ_buf){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);const orig_environ_buf=environ_buf;for(let i=0;i<self.env.length;i++){buffer.setUint32(environ,environ_buf,true);environ+=4;const e=new TextEncoder().encode(self.env[i]);buffer8.set(e,environ_buf);buffer.setUint8(environ_buf+e.length,0);environ_buf+=e.length+1}if(debug.enabled){debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_environ_buf,environ_buf)))}return 0},clock_res_get(id,res_ptr){throw"unimplemented"},clock_time_get(id,precision,time){const buffer=new DataView(self.inst.exports.memory.buffer);if(id===wasi.CLOCKID_REALTIME){buffer.setBigUint64(time,BigInt(new Date().getTime())*1000000n,true)}else if(id==wasi.CLOCKID_MONOTONIC){let monotonic_time;try{monotonic_time=BigInt(Math.round(performance.now()*1e6))}catch(e){monotonic_time=0n}buffer.setBigUint64(time,monotonic_time,true)}else{buffer.setBigUint64(time,0n,true)}return 0},fd_advise(fd,offset,len,advice){if(self.fds[fd]!=undefined){return self.fds[fd].fd_advise(offset,len,advice)}else{return wasi.ERRNO_BADF}},fd_allocate(fd,offset,len){if(self.fds[fd]!=undefined){return self.fds[fd].fd_allocate(offset,len)}else{return wasi.ERRNO_BADF}},fd_close(fd){if(self.fds[fd]!=undefined){const ret=self.fds[fd].fd_close();self.fds[fd]=undefined;return ret}else{return wasi.ERRNO_BADF}},fd_datasync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_datasync()}else{return wasi.ERRNO_BADF}},fd_fdstat_get(fd,fdstat_ptr){if(self.fds[fd]!=undefined){const{ret,fdstat}=self.fds[fd].fd_fdstat_get();if(fdstat!=null){fdstat.write_bytes(new DataView(self.inst.exports.memory.buffer),fdstat_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_fdstat_set_flags(fd,flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_flags(flags)}else{return wasi.ERRNO_BADF}},fd_fdstat_set_rights(fd,fs_rights_base,fs_rights_inheriting){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting)}else{return wasi.ERRNO_BADF}},fd_filestat_get(fd,filestat_ptr){if(self.fds[fd]!=undefined){const{ret,filestat}=self.fds[fd].fd_filestat_get();if(filestat!=null){filestat.write_bytes(new DataView(self.inst.exports.memory.buffer),filestat_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_filestat_set_size(fd,size){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_size(size)}else{return wasi.ERRNO_BADF}},fd_filestat_set_times(fd,atim,mtim,fst_flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_times(atim,mtim,fst_flags)}else{return wasi.ERRNO_BADF}},fd_pread(fd,iovs_ptr,iovs_len,offset,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=wasi.Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);const{ret,nread}=self.fds[fd].fd_pread(buffer8,iovecs,offset);buffer.setUint32(nread_ptr,nread,true);return ret}else{return wasi.ERRNO_BADF}},fd_prestat_get(fd,buf_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,prestat}=self.fds[fd].fd_prestat_get();if(prestat!=null){prestat.write_bytes(buffer,buf_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_prestat_dir_name(fd,path_ptr,path_len){if(self.fds[fd]!=undefined){const{ret,prestat_dir_name}=self.fds[fd].fd_prestat_dir_name();if(prestat_dir_name!=null){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);buffer8.set(prestat_dir_name,path_ptr)}return ret}else{return wasi.ERRNO_BADF}},fd_pwrite(fd,iovs_ptr,iovs_len,offset,nwritten_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=wasi.Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);const{ret,nwritten}=self.fds[fd].fd_pwrite(buffer8,iovecs,offset);buffer.setUint32(nwritten_ptr,nwritten,true);return ret}else{return wasi.ERRNO_BADF}},fd_read(fd,iovs_ptr,iovs_len,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=wasi.Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);const{ret,nread}=self.fds[fd].fd_read(buffer8,iovecs);buffer.setUint32(nread_ptr,nread,true);return ret}else{return wasi.ERRNO_BADF}},fd_readdir(fd,buf,buf_len,cookie,bufused_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let bufused=0;while(true){const{ret,dirent}=self.fds[fd].fd_readdir_single(cookie);if(ret!=0){buffer.setUint32(bufused_ptr,bufused,true);return ret}if(dirent==null){break}if(buf_len-bufused<dirent.head_length()){bufused=buf_len;break}const head_bytes=new ArrayBuffer(dirent.head_length());dirent.write_head_bytes(new DataView(head_bytes),0);buffer8.set(new Uint8Array(head_bytes).slice(0,Math.min(head_bytes.byteLength,buf_len-bufused)),buf);buf+=dirent.head_length();bufused+=dirent.head_length();if(buf_len-bufused<dirent.name_length()){bufused=buf_len;break}dirent.write_name_bytes(buffer8,buf,buf_len-bufused);buf+=dirent.name_length();bufused+=dirent.name_length();cookie=dirent.d_next}buffer.setUint32(bufused_ptr,bufused,true);return 0}else{return wasi.ERRNO_BADF}},fd_renumber(fd,to){if(self.fds[fd]!=undefined&&self.fds[to]!=undefined){const ret=self.fds[to].fd_close();if(ret!=0){return ret}self.fds[to]=self.fds[fd];self.fds[fd]=undefined;return 0}else{return wasi.ERRNO_BADF}},fd_seek(fd,offset,whence,offset_out_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,offset:offset_out}=self.fds[fd].fd_seek(offset,whence);buffer.setBigInt64(offset_out_ptr,offset_out,true);return ret}else{return wasi.ERRNO_BADF}},fd_sync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_sync()}else{return wasi.ERRNO_BADF}},fd_tell(fd,offset_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,offset}=self.fds[fd].fd_tell();buffer.setBigUint64(offset_ptr,offset,true);return ret}else{return wasi.ERRNO_BADF}},fd_write(fd,iovs_ptr,iovs_len,nwritten_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=wasi.Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);const{ret,nwritten}=self.fds[fd].fd_write(buffer8,iovecs);buffer.setUint32(nwritten_ptr,nwritten,true);return ret}else{return wasi.ERRNO_BADF}},path_create_directory(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_create_directory(path)}},path_filestat_get(fd,flags,path_ptr,path_len,filestat_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));const{ret,filestat}=self.fds[fd].path_filestat_get(flags,path);if(filestat!=null){filestat.write_bytes(buffer,filestat_ptr)}return ret}else{return wasi.ERRNO_BADF}},path_filestat_set_times(fd,flags,path_ptr,path_len,atim,mtim,fst_flags){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_filestat_set_times(flags,path,atim,mtim,fst_flags)}else{return wasi.ERRNO_BADF}},path_link(old_fd,old_flags,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[old_fd]!=undefined&&self.fds[new_fd]!=undefined){const old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));const new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));return self.fds[new_fd].path_link(old_fd,old_flags,old_path,new_path)}else{return wasi.ERRNO_BADF}},path_open(fd,dirflags,path_ptr,path_len,oflags,fs_rights_base,fs_rights_inheriting,fd_flags,opened_fd_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));debug.log(path);const{ret,fd_obj}=self.fds[fd].path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags);if(ret!=0){return ret}self.fds.push(fd_obj);const opened_fd=self.fds.length-1;buffer.setUint32(opened_fd_ptr,opened_fd,true);return 0}else{return wasi.ERRNO_BADF}},path_readlink(fd,path_ptr,path_len,buf_ptr,buf_len,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));debug.log(path);const{ret,data}=self.fds[fd].path_readlink(path);if(data!=null){if(data.length>buf_len){buffer.setUint32(nread_ptr,0,true);return wasi.ERRNO_BADF}buffer8.set(data,buf_ptr);buffer.setUint32(nread_ptr,data.length,true)}return ret}else{return wasi.ERRNO_BADF}},path_remove_directory(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_remove_directory(path)}else{return wasi.ERRNO_BADF}},path_rename(fd,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){throw"FIXME what is the best abstraction for this?"},path_symlink(old_path_ptr,old_path_len,fd,new_path_ptr,new_path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));const new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));return self.fds[fd].path_symlink(old_path,new_path)}else{return wasi.ERRNO_BADF}},path_unlink_file(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_unlink_file(path)}else{return wasi.ERRNO_BADF}},poll_oneoff(in_,out,nsubscriptions){throw"async io not supported"},proc_exit(exit_code){throw"exit with exit code "+exit_code},proc_raise(sig){throw"raised signal "+sig},sched_yield(){},random_get(buf,buf_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);for(let i=0;i<buf_len;i++){buffer8[buf+i]=Math.random()*256|0}},sock_recv(fd,ri_data,ri_flags){throw"sockets not supported"},sock_send(fd,si_data,si_flags){throw"sockets not supported"},sock_shutdown(fd,how){throw"sockets not supported"},sock_accept(fd,flags){throw"sockets not supported"}}}};export{WASI as default};
{
"name": "@bjorn3/browser_wasi_shim",
"version": "0.2.15",
"version": "0.2.16",
"license": "MIT OR Apache-2.0",

@@ -10,3 +10,3 @@ "description": "A pure javascript shim for WASI",

"prepare": "swc src -d dist && tsc --emitDeclarationOnly",
"check": "tsc --noEmit"
"check": "tsc --noEmit && prettier src -c && eslint src/"
},

@@ -32,4 +32,8 @@ "repository": {

"@swc/core": "^1.3.37",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.50.0",
"prettier": "^3.0.3",
"typescript": "^4.9.5"
}
}

@@ -34,2 +34,26 @@ # A pure javascript shim for WASI

## Building
```
$ npm install
$ npm run build
```
## Running the demo
The demo requires the wasm rustc artifacts and the xterm js package. To get them run:
```
$ git submodule update --init
$ cd examples && npm install
```
Run the demo with a static web server from the root of this project:
```
$ npx http-server
```
And visit [http://127.0.0.1:8080/examples/rustc.html]() in your browser.
## License

@@ -36,0 +60,0 @@

@@ -27,3 +27,3 @@ import * as wasi from "./wasi_defs.js";

};
fd_prestat_dir_name(path_ptr: number, path_len: number): {
fd_prestat_dir_name(): {
ret: number;

@@ -30,0 +30,0 @@ prestat_dir_name: any;

@@ -47,4 +47,4 @@ import { OpenDirectory, OpenFile, OpenSyncOPFSFile } from "./fs_fd.js";

get_entry_for_path(path: string): File | Directory | SyncOPFSFile | null;
create_entry_for_path(path: string, is_dir: boolean): File | Directory;
create_entry_for_path(path: string, is_dir: boolean): File | Directory | SyncOPFSFile;
}
export {};

@@ -16,2 +16,6 @@ import * as wasi from "./wasi_defs.js";

};
fd_pread(view8: Uint8Array, iovs: Array<wasi.Iovec>, offset: bigint): {
ret: number;
nread: number;
};
fd_seek(offset: bigint, whence: number): {

@@ -18,0 +22,0 @@ ret: number;

import WASI from "./wasi.js";
export { WASI };
export { Fd } from './fd.js';
export { Fd } from "./fd.js";
export { File, SyncOPFSFile, Directory } from "./fs_core.js";
export { OpenFile, OpenDirectory, OpenSyncOPFSFile, PreopenDirectory } from "./fs_fd.js";
export { OpenFile, OpenDirectory, OpenSyncOPFSFile, PreopenDirectory, } from "./fs_fd.js";
export { strace } from "./strace.js";
import { Fd } from "./fd.js";
type mixed = any;
export interface Options {
debug?: boolean;
}
export default class WASI {

@@ -13,3 +15,3 @@ args: Array<string>;

wasiImport: {
[key: string]: (...args: Array<any>) => mixed;
[key: string]: (...args: Array<unknown>) => unknown;
};

@@ -19,3 +21,3 @@ start(instance: {

memory: WebAssembly.Memory;
_start: () => mixed;
_start: () => unknown;
};

@@ -26,7 +28,6 @@ }): void;

memory: WebAssembly.Memory;
_initialize: () => mixed;
_initialize: () => unknown;
};
}): void;
constructor(args: Array<string>, env: Array<string>, fds: Array<Fd>);
constructor(args: Array<string>, env: Array<string>, fds: Array<Fd>, options?: Options);
}
export {};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc