From e0312b405b081528669ea2a72ef17f1739126c57 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 30 Jan 2024 21:01:05 -0500 Subject: [PATCH] Expose rust function for accessing wasm memory (#93) --- tests/ffi.test.ts | 3 +-- tests/record-batch.test.ts | 3 +-- tests/rust-arrow-ffi/src/lib.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/ffi.test.ts b/tests/ffi.test.ts index e54654f..107f432 100644 --- a/tests/ffi.test.ts +++ b/tests/ffi.test.ts @@ -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); diff --git a/tests/record-batch.test.ts b/tests/record-batch.test.ts index 40ae0ed..899d59c 100644 --- a/tests/record-batch.test.ts +++ b/tests/record-batch.test.ts @@ -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); diff --git a/tests/rust-arrow-ffi/src/lib.rs b/tests/rust-arrow-ffi/src/lib.rs index b392539..1366b3b 100644 --- a/tests/rust-arrow-ffi/src/lib.rs +++ b/tests/rust-arrow-ffi/src/lib.rs @@ -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() +}