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
///! Provides access to properties of the `memory` object.
///! Consider replacing with bindings that fit your own usage.
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(typescript_type = "(typeof memory)")]
    type Memory;

    #[wasm_bindgen]
    static memory: Memory;

    #[wasm_bindgen(method, structural, indexing_getter)]
    fn get(this: &Memory, prop: &JsValue) -> JsValue;

    #[wasm_bindgen(method, structural, indexing_setter)]
    fn set(this: &Memory, prop: &JsValue, val: &JsValue);

    #[wasm_bindgen(method, structural, indexing_deleter)]
    fn delete(this: &Memory, prop: &JsValue);
}

/// Retrieve the value of `memory[prop]`.
#[inline(always)]
pub fn get(prop: &JsValue) -> JsValue {
    memory.get(prop)
}

/// Set the value of `memory[prop]`.
#[inline(always)]
pub fn set(prop: &JsValue, val: &JsValue) {
    memory.set(prop, val)
}

/// Delete `memory[prop]`.
#[inline(always)]
pub fn delete(prop: &JsValue) {
    memory.delete(prop)
}