1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use js_sys::wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
#[wasm_bindgen(js_namespace = WebAssembly, extends = js_sys::Object, typescript_type = "WebAssembly.Memory")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type JSMemory;
/// The `buffer` property of the `Memory` object, which is an `ArrayBuffer` or `SharedArrayBuffer`.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/Memory/buffer)
#[wasm_bindgen(method, getter, js_name = buffer, js_namespace = WebAssembly)]
pub fn buffer(this: &JSMemory) -> JsValue;
/// The `grow()` prototype method of the `Memory` object increases the
/// size of the memory instance by a specified number of WebAssembly
/// pages.
///
/// Takes the number of pages to grow (64KiB in size) and returns the
/// previous size of memory, in pages.
///
/// # Reimplementation
///
/// We re-implement `WebAssembly.Memory.grow` because it is
/// different from what `wasm-bindgen` declares. It marks the function
/// as `catch`, which means it can throw an exception.
///
/// See [the opened patch](https://github.com/rustwasm/wasm-bindgen/pull/2599).
///
/// # Exceptions
///
/// A `RangeError` is thrown if adding pages would exceed the maximum
/// memory.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
#[wasm_bindgen(catch, method, js_namespace = WebAssembly)]
pub fn grow(this: &JSMemory, pages: u32) -> Result<u32, JsValue>;
}