Add an accessor for wasm's own memory as a JS object

In addition to closing #495 this'll be useful eventually when instantiating
multiple wasm modules from Rust as you'd now be able to acquire a reference to
the current module in Rust itself.
This commit is contained in:
Alex Crichton
2018-08-21 10:42:52 -07:00
parent 85fd49f90a
commit e1474110d4
5 changed files with 40 additions and 1 deletions

View File

@ -437,6 +437,8 @@ externs! {
fn __wbindgen_json_parse(ptr: *const u8, len: usize) -> u32;
fn __wbindgen_json_serialize(idx: u32, ptr: *mut *mut u8) -> usize;
fn __wbindgen_jsval_eq(a: u32, b: u32) -> u32;
fn __wbindgen_memory() -> u32;
}
impl Clone for JsValue {
@ -562,6 +564,13 @@ pub fn throw(s: &str) -> ! {
}
}
/// Returns a handle to this wasm instance's `WebAssembly.Memory`
pub fn memory() -> JsValue {
unsafe {
JsValue { idx: __wbindgen_memory() }
}
}
#[doc(hidden)]
pub mod __rt {
use core::cell::{Cell, UnsafeCell};