Skip to content

Commit

Permalink
Expose WebAssembly.Instance (#3296)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed May 9, 2023
1 parent 5621603 commit b7edbd2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/cli-support/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ intrinsics! {
#[symbol = "__wbindgen_memory"]
#[signature = fn() -> Externref]
Memory,
#[symbol = "__wbindgen_exports"]
#[signature = fn() -> Externref]
Exports,
#[symbol = "__wbindgen_module"]
#[signature = fn() -> Externref]
Module,
Expand Down
5 changes: 5 additions & 0 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,11 @@ impl<'a> Context<'a> {
format!("__wbg_init.__wbindgen_wasm_module")
}

Intrinsic::Exports => {
assert_eq!(args.len(), 0);
"wasm".to_string()
}

Intrinsic::Memory => {
assert_eq!(args.len(), 0);
let mut memories = self.module.memories.iter();
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ externs! {

fn __wbindgen_not(idx: u32) -> u32;

fn __wbindgen_exports() -> u32;
fn __wbindgen_memory() -> u32;
fn __wbindgen_module() -> u32;
fn __wbindgen_function_table() -> u32;
Expand Down Expand Up @@ -1358,6 +1359,11 @@ pub fn module() -> JsValue {
unsafe { JsValue::_new(__wbindgen_module()) }
}

/// Returns a handle to this wasm instance's `WebAssembly.Instance.prototype.exports`
pub fn exports() -> JsValue {
unsafe { JsValue::_new(__wbindgen_exports()) }
}

/// Returns a handle to this wasm instance's `WebAssembly.Memory`
pub fn memory() -> JsValue {
unsafe { JsValue::_new(__wbindgen_memory()) }
Expand Down

0 comments on commit b7edbd2

Please sign in to comment.