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

Commit e204a99

Browse files
committed
Fix the tests and MutableHandle::handle
1 parent a564bff commit e204a99

File tree

7 files changed

+15
-17
lines changed

7 files changed

+15
-17
lines changed

src/rust.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ macro_rules! auto_root {
668668
}
669669
}
670670

671+
#[derive(Clone, Copy)]
671672
pub struct Handle<'a, T: 'a> {
672673
ptr: &'a T,
673674
}
@@ -677,6 +678,7 @@ pub struct MutableHandle<'a, T: 'a> {
677678
}
678679

679680
pub type MutableHandleValue<'a> = MutableHandle<'a, Value>;
681+
pub type MutableHandleObject<'a> = MutableHandle<'a, *mut JSObject>;
680682

681683
pub type HandleValue<'a> = Handle<'a, Value>;
682684
pub type HandleObject<'a> = Handle<'a, *mut JSObject>;
@@ -773,10 +775,8 @@ impl<'a, T> MutableHandle<'a, T> {
773775
RawMutableHandle::from_marked_location(ptr).into()
774776
}
775777

776-
pub fn handle(&self) -> RawHandle<T> {
777-
unsafe {
778-
RawHandle::from_marked_location(self.ptr as *const T)
779-
}
778+
pub fn handle(&self) -> Handle<T> {
779+
Handle::new(self.ptr)
780780
}
781781

782782
pub fn new(ptr: &'a mut T) -> Self {
@@ -795,7 +795,7 @@ impl<'a, T> MutableHandle<'a, T> {
795795
*self.ptr = v
796796
}
797797

798-
pub fn raw(&mut self) -> RawMutableHandle<T> {
798+
fn raw(&mut self) -> RawMutableHandle<T> {
799799
unsafe {
800800
RawMutableHandle::from_marked_location(self.ptr)
801801
}

src/typedarray.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use glue::GetUint8ArrayLengthAndData;
1717
use glue::GetUint8ClampedArrayLengthAndData;
1818
use jsapi::GetArrayBufferLengthAndData;
1919
use jsapi::GetArrayBufferViewLengthAndData;
20-
use jsapi::HandleObject;
2120
use jsapi::JSContext;
2221
use jsapi::JSObject;
2322
use jsapi::JS_GetArrayBufferData;
@@ -41,7 +40,6 @@ use jsapi::JS_NewUint16Array;
4140
use jsapi::JS_NewUint32Array;
4241
use jsapi::JS_NewUint8Array;
4342
use jsapi::JS_NewUint8ClampedArray;
44-
use jsapi::MutableHandleObject;
4543
use jsapi::Rooted;
4644
use jsapi::Type;
4745
use jsapi::UnwrapArrayBuffer;
@@ -55,7 +53,7 @@ use jsapi::UnwrapUint16Array;
5553
use jsapi::UnwrapUint32Array;
5654
use jsapi::UnwrapUint8Array;
5755
use jsapi::UnwrapUint8ClampedArray;
58-
use rust::RootedGuard;
56+
use rust::{HandleObject, MutableHandleObject, RootedGuard};
5957
use std::ptr;
6058
use std::slice;
6159

@@ -133,7 +131,7 @@ impl<'a, T: TypedArrayElementCreator + TypedArrayElement> TypedArray<'a, T> {
133131
/// be copied into the newly-allocated buffer. Returns the new JS reflector.
134132
pub unsafe fn create(cx: *mut JSContext,
135133
with: CreateWith<T::Element>,
136-
result: MutableHandleObject)
134+
mut result: MutableHandleObject)
137135
-> Result<(), ()> {
138136
let length = match with {
139137
CreateWith::Length(len) => len,

tests/callback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn callback() {
3535
rooted!(in(context) let global_root = global);
3636
let global = global_root.handle();
3737
let _ac = JSAutoCompartment::new(context, global.get());
38-
let function = JS_DefineFunction(context, global, b"puts\0".as_ptr() as *const libc::c_char,
38+
let function = JS_DefineFunction(context, global.into(), b"puts\0".as_ptr() as *const libc::c_char,
3939
Some(puts), 1, 0);
4040
assert!(!function.is_null());
4141
let javascript = "puts('Test Iñtërnâtiônàlizætiøn ┬─┬ノ( º _ ºノ) ');";
@@ -55,7 +55,7 @@ unsafe extern "C" fn puts(context: *mut JSContext, argc: u32, vp: *mut Value) ->
5555
let arg = args.get(0);
5656
let js = mozjs::rust::ToString(context, arg);
5757
rooted!(in(context) let message_root = js);
58-
let message = JS_EncodeStringToUTF8(context, message_root.handle());
58+
let message = JS_EncodeStringToUTF8(context, message_root.handle().into());
5959
let message = CStr::from_ptr(message);
6060
println!("{}", str::from_utf8(message.to_bytes()).unwrap());
6161

tests/capture_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn capture_stack() {
3131
rooted!(in(context) let global_root = global);
3232
let global = global_root.handle();
3333
let _ac = JSAutoCompartment::new(context, global.get());
34-
let function = JS_DefineFunction(context, global, b"print_stack\0".as_ptr() as *const libc::c_char,
34+
let function = JS_DefineFunction(context, global.into(), b"print_stack\0".as_ptr() as *const libc::c_char,
3535
Some(print_stack), 0, 0);
3636
assert!(!function.is_null());
3737
let javascript = "

tests/enumerate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ fn enumerate() {
3838

3939
rooted!(in(cx) let object = rval.to_object());
4040
let ids = IdVector::new(cx);
41-
assert!(GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY, ids.get()));
41+
assert!(GetPropertyKeys(cx, object.handle().into(), JSITER_OWNONLY, ids.get()));
4242

4343
assert_eq!(ids.len(), 1);
4444
rooted!(in(cx) let id = ids[0]);
4545

46-
assert!(RUST_JSID_IS_STRING(id.handle()));
47-
rooted!(in(cx) let id = RUST_JSID_TO_STRING(id.handle()));
46+
assert!(RUST_JSID_IS_STRING(id.handle().into()));
47+
rooted!(in(cx) let id = RUST_JSID_TO_STRING(id.handle().into()));
4848

4949
let mut matches = false;
5050
assert!(JS_StringEqualsAscii(cx,

tests/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn panic() {
3131
rooted!(in(context) let global_root = global);
3232
let global = global_root.handle();
3333
let _ac = JSAutoCompartment::new(context, global.get());
34-
let function = JS_DefineFunction(context, global,
34+
let function = JS_DefineFunction(context, global.into(),
3535
b"test\0".as_ptr() as *const _,
3636
Some(test), 0, 0);
3737
assert!(!function.is_null());

tests/vec_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn vec_conversion() {
3434
let global = global_root.handle();
3535

3636
let _ac = JSAutoCompartment::new(cx, global.get());
37-
assert!(JS_InitStandardClasses(cx, global));
37+
assert!(JS_InitStandardClasses(cx, global.into()));
3838

3939
rooted!(in(cx) let mut rval = UndefinedValue());
4040

0 commit comments

Comments
 (0)