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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Functions for passing arbitrary Rust values across the JS boundary and back to Rust, ex. as a return value from a promise.
use ;
/// Boxes an object, returning a JS wrapper that `js_unbox` can consume to turn back into the object.
///
/// The contents of the return value should be untouched, both by rust code and by JS code, for
/// safe usage with `js_unbox`.
/// Unboxes a value created by `js_box`, returning the original object.
///
/// Returns `Some(v)` if the unboxing succeeded, or `None` if the value was not a valid box object
/// or it was already unboxed.
///
/// This mutates the object, so that calling `js_unbox` on the same object will return `None`.
///
/// Safety
/// ------
///
/// Assumes that the object has been untouched since being returned from `js_box` or `js_box_from_std_box`,
/// and that the type argument is the same as the one used to box it.
///
/// JS or Rust code could modify the object or construct a JS object with an invalid internal pointer,
/// which this function can't check for. In such a case, the result is undefined.
///
/// If the value is sent across a thread, the caller needs to ensure that `T` implements `Send`
/// (TODO: is this even possible with wasm?).
///
/// The lifetime of `T` must still be valid. If in doubt, require `'static`.
pub unsafe