|
6 | 6 |
|
7 | 7 | use std::ptr; |
8 | 8 |
|
| 9 | +use mozjs::jsapi::SetGCZeal; |
9 | 10 | use mozjs::jsapi::JSPROP_ENUMERATE; |
10 | | -use mozjs::jsapi::{ |
11 | | - GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto, SetGCZeal, |
12 | | -}; |
13 | 11 | use mozjs::jsapi::{ |
14 | 12 | JSAutoRealm, JSClass, JSContext, JSFunction, JSFunctionSpec, JSNativeWrapper, JSObject, |
15 | 13 | JSPropertySpec_Name, JSString, OnNewGlobalHookOption, Value, |
16 | 14 | }; |
17 | 15 | use mozjs::jsval::JSVal; |
18 | 16 | use mozjs::rooted; |
| 17 | +use mozjs::rust::wrappers2::{ |
| 18 | + GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto, |
| 19 | +}; |
19 | 20 | use mozjs::rust::{define_methods, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; |
20 | 21 |
|
21 | 22 | #[test] |
22 | 23 | fn rooting() { |
23 | 24 | let engine = JSEngine::init().unwrap(); |
24 | 25 | let mut runtime = Runtime::new(engine.handle()); |
25 | | - let context = **runtime.cx(); |
| 26 | + let context = runtime.cx(); |
26 | 27 | let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; |
27 | 28 | let c_option = RealmOptions::default(); |
28 | 29 |
|
29 | 30 | unsafe { |
30 | | - SetGCZeal(context, 2, 1); |
31 | | - rooted!(in(context) let global = JS_NewGlobalObject( |
| 31 | + SetGCZeal(context.raw_cx(), 2, 1); |
| 32 | + rooted!(&in(context) let global = JS_NewGlobalObject( |
32 | 33 | context, |
33 | 34 | &SIMPLE_GLOBAL_CLASS, |
34 | 35 | ptr::null_mut(), |
35 | 36 | h_option, |
36 | 37 | &*c_option, |
37 | 38 | )); |
38 | | - let _ac = JSAutoRealm::new(context, global.get()); |
| 39 | + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); |
39 | 40 |
|
40 | | - rooted!(in(context) let prototype_proto = GetRealmObjectPrototype(context)); |
41 | | - rooted!(in(context) let proto = JS_NewObjectWithGivenProto(context, &CLASS as *const _, prototype_proto.handle().into())); |
42 | | - define_methods(context, proto.handle(), METHODS).unwrap(); |
| 41 | + rooted!(&in(context) let prototype_proto = GetRealmObjectPrototype(context)); |
| 42 | + rooted!(&in(context) let proto = JS_NewObjectWithGivenProto(context, &CLASS as *const _, prototype_proto.handle().into())); |
| 43 | + define_methods(context.raw_cx(), proto.handle(), METHODS).unwrap(); |
43 | 44 |
|
44 | | - rooted!(in(context) let root: JSVal); |
| 45 | + rooted!(&in(context) let root: JSVal); |
45 | 46 | assert_eq!(root.get().is_undefined(), true); |
46 | 47 |
|
47 | | - rooted!(in(context) let root: *mut JSObject); |
| 48 | + rooted!(&in(context) let root: *mut JSObject); |
48 | 49 | assert_eq!(root.get().is_null(), true); |
49 | 50 |
|
50 | | - rooted!(in(context) let root: *mut JSString); |
| 51 | + rooted!(&in(context) let root: *mut JSString); |
51 | 52 | assert_eq!(root.get().is_null(), true); |
52 | 53 |
|
53 | | - rooted!(in(context) let root: *mut JSFunction); |
| 54 | + rooted!(&in(context) let root: *mut JSFunction); |
54 | 55 | assert_eq!(root.get().is_null(), true); |
55 | 56 | } |
56 | 57 | } |
|
0 commit comments