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

Commit f1ee669

Browse files
committed
[#411] Use the GCMethods trait to set initial value && Complete other test cases
1 parent 0c14722 commit f1ee669

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
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 as Default>::default());
403+
let $name = $crate::rust::RootedGuard::new($cx, &mut __root, <$type as GCMethods>::initial());
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 as Default>::default());
407+
let mut $name = $crate::rust::RootedGuard::new($cx, &mut __root, <$type as GCMethods>::initial());
408408
};
409409
}
410410

tests/rooting.rs

Lines changed: 14 additions & 2 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::jsapi::{JSObject, JSString, JSFunction};
2425
use mozjs::jsval::JSVal;
2526
use mozjs::rust::{Runtime, SIMPLE_GLOBAL_CLASS, define_methods};
2627
use std::ptr;
@@ -54,8 +55,19 @@ fn type_rooting() {
5455
let runtime = Runtime::new().unwrap();
5556
let cx = runtime.cx();
5657

57-
rooted!(in(cx) let root : JSVal);
58-
assert_eq!(root.get().is_undefined(),true);
58+
unsafe{
59+
rooted!(in(cx) let root : JSVal);
60+
assert_eq!(root.get().is_undefined(), true);
61+
62+
rooted!(in(cx) let root : *mut JSObject);
63+
assert_eq!(root.get().is_null(), true);
64+
65+
rooted!(in(cx) let root : *mut JSString);
66+
assert_eq!(root.get().is_null(), true);
67+
68+
rooted!(in(cx) let root : *mut JSFunction);
69+
assert_eq!(root.get().is_null(), true);
70+
}
5971
}
6072

6173
unsafe extern "C" fn generic_method(_: *mut JSContext, _: u32, _: *mut Value) -> bool {

0 commit comments

Comments
 (0)