Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit 0c14722

Browse files
committed
[#411] Add some tests for default-initialized roots
1 parent 2afcfa4 commit 0c14722

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,11 @@ macro_rules! rooted {
400400
};
401401
(in($cx:expr) let $name:ident: $type:ty) => {
402402
let mut __root = $crate::jsapi::Rooted::new_unrooted();
403-
let $name = $crate::rust::RootedGuard::new($cx, &mut __root, $type::default());
403+
let $name = $crate::rust::RootedGuard::new($cx, &mut __root, <$type as Default>::default());
404404
};
405405
(in($cx:expr) let mut $name:ident: $type:ty) => {
406406
let mut __root = $crate::jsapi::Rooted::new_unrooted();
407-
let mut $name = $crate::rust::RootedGuard::new($cx, &mut __root, $type::default());
407+
let mut $name = $crate::rust::RootedGuard::new($cx, &mut __root, <$type as Default>::default());
408408
};
409409
}
410410

tests/rooting.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use mozjs::jsapi::JSPROP_ENUMERATE;
2121
use mozjs::jsapi::JS_SetGCZeal;
2222
use mozjs::jsapi::OnNewGlobalHookOption;
2323
use mozjs::jsapi::Value;
24+
use mozjs::jsval::JSVal;
2425
use mozjs::rust::{Runtime, SIMPLE_GLOBAL_CLASS, define_methods};
2526
use std::ptr;
2627

@@ -48,6 +49,15 @@ fn rooting() {
4849
}
4950
}
5051

52+
#[test]
53+
fn type_rooting() {
54+
let runtime = Runtime::new().unwrap();
55+
let cx = runtime.cx();
56+
57+
rooted!(in(cx) let root : JSVal);
58+
assert_eq!(root.get().is_undefined(),true);
59+
}
60+
5161
unsafe extern "C" fn generic_method(_: *mut JSContext, _: u32, _: *mut Value) -> bool {
5262
true
5363
}

0 commit comments

Comments
 (0)