Skip to content

Commit 733c412

Browse files
committed
f
Signed-off-by: sagudev <[email protected]>
1 parent b52d3fa commit 733c412

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

mozjs/tests/rootable.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use std::ptr;
88

9-
use mozjs::jsapi::{GetRealmObjectPrototype, JS_NewGlobalObject, SetGCZeal};
9+
use mozjs::jsapi::SetGCZeal;
1010
use mozjs::jsapi::{JSAutoRealm, JSTracer, OnNewGlobalHookOption, Value};
1111
use mozjs::jsval::ObjectValue;
1212
use mozjs::rooted;
13+
use mozjs::rust::wrappers2::{GetRealmObjectPrototype, JS_NewGlobalObject};
1314
use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS};
1415

1516
impl mozjs::gc::Rootable for ContainsGCValue {}
@@ -33,26 +34,26 @@ struct ContainsGCValue {
3334
fn rooting() {
3435
let engine = JSEngine::init().unwrap();
3536
let mut runtime = Runtime::new(engine.handle());
36-
let context = **runtime.cx();
37+
let context = runtime.cx();
3738
let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
3839
let c_option = RealmOptions::default();
3940

4041
unsafe {
41-
SetGCZeal(context, 2, 1);
42-
rooted!(in(context) let global = JS_NewGlobalObject(
42+
SetGCZeal(context.raw_cx(), 2, 1);
43+
rooted!(&in(context) let global = JS_NewGlobalObject(
4344
context,
4445
&SIMPLE_GLOBAL_CLASS,
4546
ptr::null_mut(),
4647
h_option,
4748
&*c_option,
4849
));
49-
let _ac = JSAutoRealm::new(context, global.get());
50+
let _ac = JSAutoRealm::new(context.raw_cx(), global.get());
5051

51-
rooted!(in(context) let prototype_proto = GetRealmObjectPrototype(context));
52-
rooted!(in(context) let some_container = ContainsGCValue {
52+
rooted!(&in(context) let prototype_proto = GetRealmObjectPrototype(context));
53+
rooted!(&in(context) let some_container = ContainsGCValue {
5354
val: ObjectValue(prototype_proto.get())
5455
});
55-
rooted!(in(context) let some_optional_container = Some(ContainsGCValue {
56+
rooted!(&in(context) let some_optional_container = Some(ContainsGCValue {
5657
val: ObjectValue(prototype_proto.get())
5758
}));
5859
assert_eq!(some_container.val.to_object(), prototype_proto.get());

mozjs/tests/rooting.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,52 @@
66

77
use std::ptr;
88

9+
use mozjs::jsapi::SetGCZeal;
910
use mozjs::jsapi::JSPROP_ENUMERATE;
10-
use mozjs::jsapi::{
11-
GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto, SetGCZeal,
12-
};
1311
use mozjs::jsapi::{
1412
JSAutoRealm, JSClass, JSContext, JSFunction, JSFunctionSpec, JSNativeWrapper, JSObject,
1513
JSPropertySpec_Name, JSString, OnNewGlobalHookOption, Value,
1614
};
1715
use mozjs::jsval::JSVal;
1816
use mozjs::rooted;
17+
use mozjs::rust::wrappers2::{
18+
GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto,
19+
};
1920
use mozjs::rust::{define_methods, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS};
2021

2122
#[test]
2223
fn rooting() {
2324
let engine = JSEngine::init().unwrap();
2425
let mut runtime = Runtime::new(engine.handle());
25-
let context = **runtime.cx();
26+
let context = runtime.cx();
2627
let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
2728
let c_option = RealmOptions::default();
2829

2930
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(
3233
context,
3334
&SIMPLE_GLOBAL_CLASS,
3435
ptr::null_mut(),
3536
h_option,
3637
&*c_option,
3738
));
38-
let _ac = JSAutoRealm::new(context, global.get());
39+
let _ac = JSAutoRealm::new(context.raw_cx(), global.get());
3940

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();
4344

44-
rooted!(in(context) let root: JSVal);
45+
rooted!(&in(context) let root: JSVal);
4546
assert_eq!(root.get().is_undefined(), true);
4647

47-
rooted!(in(context) let root: *mut JSObject);
48+
rooted!(&in(context) let root: *mut JSObject);
4849
assert_eq!(root.get().is_null(), true);
4950

50-
rooted!(in(context) let root: *mut JSString);
51+
rooted!(&in(context) let root: *mut JSString);
5152
assert_eq!(root.get().is_null(), true);
5253

53-
rooted!(in(context) let root: *mut JSFunction);
54+
rooted!(&in(context) let root: *mut JSFunction);
5455
assert_eq!(root.get().is_null(), true);
5556
}
5657
}

0 commit comments

Comments
 (0)