Skip to content

Commit

Permalink
Changed from get_imports to getImports. Also fixed wasmerio#301
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Aug 31, 2022
1 parent 26b593c commit 94dc85b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import load, { WASI } from "./pkg/index";
export * from "./pkg/wasmer_wasi_js";
import { InitInput } from "./pkg/wasmer_wasi_js";
// import { InitInput } from "./pkg/wasmer_wasi_js";
import load from "./pkg/wasmer_wasi_js";
import wasm_bytes from "./pkg/wasmer_wasi_js_bg.wasm";

Expand Down Expand Up @@ -71,6 +71,8 @@ function dataUriToBuffer(uri: string): MimeBuffer {
return buffer;
}

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

let inited: Promise<any> | null = null;
export const init = async (input?: InitInput | Promise<InitInput>, force?: boolean) => {
if (inited === null || force === true) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/wasmer_wasi_js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class WASI {
* @param {WebAssembly.Module} module
* @returns {object}
*/
get_imports(module: WebAssembly.Module): object;
getImports(module: WebAssembly.Module): object;
/**
* @param {any} module
* @param {object | undefined} imports
Expand Down Expand Up @@ -173,7 +173,7 @@ export interface InitOutput {
readonly __wbg_wasi_free: (a: number) => void;
readonly wasi_new: (a: number) => number;
readonly wasi_fs: (a: number) => number;
readonly wasi_get_imports: (a: number, b: number) => number;
readonly wasi_getImports: (a: number, b: number) => number;
readonly wasi_instantiate: (a: number, b: number, c: number) => number;
readonly wasi_start: (a: number, b: number) => number;
readonly wasi_getStdoutBuffer: (a: number, b: number) => void;
Expand Down
4 changes: 2 additions & 2 deletions pkg/wasmer_wasi_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ export class WASI {
* @param {WebAssembly.Module} module
* @returns {object}
*/
get_imports(module) {
var ret = wasm.wasi_get_imports(this.ptr, addHeapObject(module));
getImports(module) {
var ret = wasm.wasi_getImports(this.ptr, addHeapObject(module));
return takeObject(ret);
}
/**
Expand Down
Binary file modified pkg/wasmer_wasi_js_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/wasmer_wasi_js_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function __wbg_wasmerruntimeerror_free(a: number): void;
export function __wbg_wasi_free(a: number): void;
export function wasi_new(a: number): number;
export function wasi_fs(a: number): number;
export function wasi_get_imports(a: number, b: number): number;
export function wasi_getImports(a: number, b: number): number;
export function wasi_instantiate(a: number, b: number, c: number): number;
export function wasi_start(a: number, b: number): number;
export function wasi_getStdoutBuffer(a: number, b: number): void;
Expand Down
1 change: 1 addition & 0 deletions src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl WASI {
Ok(mem_fs.clone())
}

#[wasm_bindgen(js_name = getImports)]
pub fn get_imports(
&mut self,
module: js_sys::WebAssembly::Module,
Expand Down
4 changes: 2 additions & 2 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test('wasi start empty fails', async() => {
let moduleBytes = fs.readFileSync(__dirname + '/test.wasm');
let wasi = new WASI({});
const module = await WebAssembly.compile(moduleBytes);
let imports = wasi.get_imports(module);
let imports = wasi.getImports(module);
// console.log(imports);
let instance = await WebAssembly.instantiate(module, {
...imports,
Expand All @@ -97,7 +97,7 @@ test('get imports', async() => {
let moduleBytes = fs.readFileSync(__dirname + '/test.wasm');
let wasi = new WASI({});
const module = await WebAssembly.compile(moduleBytes);
let imports = wasi.get_imports(module);
let imports = wasi.getImports(module);
// console.log(imports);
let instance = await WebAssembly.instantiate(module, {
...imports,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["*"],
"include": ["pkg"],
"exclude": ["dist"],
"compilerOptions": {
"outDir": "./dist/",
Expand Down

0 comments on commit 94dc85b

Please sign in to comment.