Skip to content

Commit

Permalink
This PR adds random_get to the WASI implementation in tye Typescrip…
Browse files Browse the repository at this point in the history
…t Host (#94)

Signed-off-by: Shivansh Vij <[email protected]>
  • Loading branch information
ShivanshVij authored Apr 17, 2023
1 parent 6e94e31 commit dff15da
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ts/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface RequiredFunctions extends WebAssembly.ModuleImports {
proc_exit(rval: number): number
path_open(fd: number, dirflags: number, path_ptr: number, path_len: number, oflags: number, fs_rights_base: number, fs_rights_inheriting: number, fd_flags: number, opened_fd_ptr: number): number
clock_time_get(id: number, precision: BigInt, time: number): number
random_get(buf: number, buf_len: number): void
}

export class DisabledWASI {
Expand Down Expand Up @@ -148,6 +149,13 @@ export class DisabledWASI {
return DisabledWASI.ESUCCESS;
}

public random_get(buf: number, buf_len: number): void {
let buffer = this.getDataView();
for (let i = 0; i < buf_len; i++) {
buffer.setInt8(buf+i, (Math.random() * 256) | 0);
}
}

public GetImports(): RequiredFunctions {
return {
environ_sizes_get: this.environ_sizes_get.bind(this),
Expand All @@ -166,6 +174,7 @@ export class DisabledWASI {
proc_exit: this.proc_exit.bind(this),
path_open: this.path_open.bind(this),
clock_time_get: this.clock_time_get.bind(this),
random_get: this.random_get.bind(this),
}
}
}

0 comments on commit dff15da

Please sign in to comment.