Skip to content

Commit

Permalink
Merge pull request #36 from Picovoice/wasm-extra-imports
Browse files Browse the repository at this point in the history
add wasi imports to wasm
  • Loading branch information
mrrostam authored Jul 12, 2024
2 parents 0231731 + feed0f1 commit 10e09d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/web-utils",
"version": "1.4.1",
"version": "1.4.2",
"description": "Picovoice web utility functions",
"author": "Picovoice",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function arrayBufferToStringAtIndex(
indexEnd++;
}
const utf8decoder = new TextDecoder('utf-8');
return utf8decoder.decode(arrayBuffer.subarray(indexStart, indexEnd));
return utf8decoder.decode(arrayBuffer.slice(indexStart, indexEnd));
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export type pv_free_type = (ptr: number) => Promise<void>;
* @param wasm The wasm file in base64 string or stream to public path (i.e. fetch("file.wasm")) to initialize.
* @param pvError The PvError object to store error details.
* @param additionalImports Extra WASM imports.
* @param wasiImports Additional WASI imports.
* @returns An object containing the exported functions from WASM.
*/
export async function buildWasm(
memory: WebAssembly.Memory,
wasm: string | Promise<Response>,
pvError?: PvError,
additionalImports: Record<string, any> = {},
wasiImports: Record<string, any> = {}
): Promise<any> {
const setInt = (address: number, value: number) => {
const memoryBufferInt32 = new Int32Array(memory.buffer);
Expand Down Expand Up @@ -404,8 +406,11 @@ export async function buildWasm(
pv_file_seek_wasm: pvFileSeekWasm,
pv_file_tell_wasm: pvFileTellWasm,
pv_file_remove_wasm: pvFileRemoveWasm,
...additionalImports
...additionalImports,
},
wasi: {
...wasiImports,
}
};

let instance: WebAssembly.Instance;
Expand Down

0 comments on commit 10e09d0

Please sign in to comment.