Skip to content

Commit

Permalink
Expose rust function for accessing wasm memory (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Jan 31, 2024
1 parent aec6c79 commit e0312b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 1 addition & 2 deletions tests/ffi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { Type } from "../src/types";

wasm.setPanicHook();

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

const TEST_TABLE = loadIPCTableFromDisk("tests/table.arrow");
const FFI_TABLE = arrowTableToFFI(TEST_TABLE);
Expand Down
3 changes: 1 addition & 2 deletions tests/record-batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { readFileSync } from "fs";

wasm.setPanicHook();

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

const TEST_TABLE = loadIPCTableFromDisk("tests/table.arrow");
const FFI_RECORD_BATCH = arrowTableToFFIRecordBatch(TEST_TABLE);
Expand Down
13 changes: 13 additions & 0 deletions tests/rust-arrow-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ pub fn set_panic_hook() {
// https://github.com/rustwasm/console_error_panic_hook#readme
console_error_panic_hook::set_once();
}

/// Returns a handle to this wasm instance's `WebAssembly.Memory`
#[wasm_bindgen(js_name = wasmMemory)]
pub fn memory() -> JsValue {
wasm_bindgen::memory()
}

/// Returns a handle to this wasm instance's `WebAssembly.Table` which is the indirect function
/// table used by Rust
#[wasm_bindgen(js_name = _functionTable)]
pub fn function_table() -> JsValue {
wasm_bindgen::function_table()
}

0 comments on commit e0312b4

Please sign in to comment.