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
#[macro_export]
macro_rules! rooted {
	(in($cx:expr) let $($var:ident)+ = $init:expr) => {
        let mut __root = $crate::jsapi::Rooted::new_unrooted();
        let $($var)+ = $crate::gc::RootedGuard::new($cx, &mut __root, $init);
    };
	(in($cx:expr) let $($var:ident)+: $type:ty = $init:expr) => {
        let mut __root = $crate::jsapi::Rooted::new_unrooted();
        let $($var)+: $crate::gc::RootedGuard<$type> = $crate::gc::RootedGuard::new($cx, &mut __root, $init);
    };
	(in($cx:expr) let $($var:ident)+: $type:ty) => {
        let mut __root = $crate::jsapi::Rooted::new_unrooted();
        // SAFETY:
        // We're immediately storing the initial value in a rooted location.
        let $($var)+: $crate::gc::RootedGuard<$type> = $crate::gc::RootedGuard::new(
            $cx,
            &mut __root,
            unsafe { <$type as $crate::gc::GCMethods>::initial() },
        );
    };
}

#[macro_export]
macro_rules! rooted_vec {
    (let mut $name:ident) => {
        let mut __root = $crate::gc::RootableVec::new_unrooted();
        let mut $name = $crate::gc::RootedVec::new(&mut __root);
    };
    (let mut $name:ident: $type:ty) => {
        let mut __root = $crate::gc::RootableVec::new_unrooted();
        let mut $name: $crate::gc::RootedVec<$type> = $crate::gc::RootedVec::new(&mut __root);
    };
    (let mut $name:ident = $init:expr) => {
        let mut __root = $crate::gc::RootableVec::new_unrooted();
        let mut $name = $crate::gc::RootedVec::new(&mut __root);
        ::std::iter::Extend::extend(&mut $name, $init);
    };
    (let mut $name:ident: $type:ty = $init:expr) => {
        let mut __root = $crate::gc::RootableVec::new_unrooted();
        let mut $name: $crate::gc::RootedVec<$type> = $crate::gc::RootedVec::new(&mut __root);
        ::std::iter::Extend::extend(&mut $name, $init);
    };
}

#[macro_export]
macro_rules! auto_root {
    (in($cx:expr) let $($var:ident)+ = $init:expr) => {
        let mut __root = $crate::gc::CustomAutoRooter::new($init);
        let $($var)+ = __root.root($cx);
    };
	(in($cx:expr) let $($var:ident)+: $type:ty = $init:expr) => {
        let mut __root = $crate::gc::CustomAutoRooter::new($init);
        let $($var)+: $crate::rust::CustomAutoRootedGuard<$type> = __root.root($cx);
    };
}