Skip to content

Commit e0312b4

Browse files
authored
Expose rust function for accessing wasm memory (#93)
1 parent aec6c79 commit e0312b4

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

tests/ffi.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { Type } from "../src/types";
1313

1414
wasm.setPanicHook();
1515

16-
// @ts-expect-error
17-
const WASM_MEMORY: WebAssembly.Memory = wasm.__wasm.memory;
16+
const WASM_MEMORY = wasm.wasmMemory();
1817

1918
const TEST_TABLE = loadIPCTableFromDisk("tests/table.arrow");
2019
const FFI_TABLE = arrowTableToFFI(TEST_TABLE);

tests/record-batch.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { readFileSync } from "fs";
1010

1111
wasm.setPanicHook();
1212

13-
// @ts-expect-error
14-
const WASM_MEMORY: WebAssembly.Memory = wasm.__wasm.memory;
13+
const WASM_MEMORY = wasm.wasmMemory()
1514

1615
const TEST_TABLE = loadIPCTableFromDisk("tests/table.arrow");
1716
const FFI_RECORD_BATCH = arrowTableToFFIRecordBatch(TEST_TABLE);

tests/rust-arrow-ffi/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ pub fn set_panic_hook() {
5757
// https://github.com/rustwasm/console_error_panic_hook#readme
5858
console_error_panic_hook::set_once();
5959
}
60+
61+
/// Returns a handle to this wasm instance's `WebAssembly.Memory`
62+
#[wasm_bindgen(js_name = wasmMemory)]
63+
pub fn memory() -> JsValue {
64+
wasm_bindgen::memory()
65+
}
66+
67+
/// Returns a handle to this wasm instance's `WebAssembly.Table` which is the indirect function
68+
/// table used by Rust
69+
#[wasm_bindgen(js_name = _functionTable)]
70+
pub fn function_table() -> JsValue {
71+
wasm_bindgen::function_table()
72+
}

0 commit comments

Comments
 (0)