Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up JSTraceable and how we use it #14473

Merged
merged 7 commits into from Dec 7, 2016
Next

Mark JSTraceable and its method as unsafe

  • Loading branch information
nox committed Dec 6, 2016
commit 620a67ff14b21c9da2d23bd96ecb9bb191738457
@@ -41,10 +41,11 @@ fn expand_string(input: &str) -> String {
}

let tokens = quote! {
impl #impl_generics ::dom::bindings::trace::JSTraceable for #name #ty_generics #where_clause {
#[allow(unsafe_code)]
unsafe impl #impl_generics ::dom::bindings::trace::JSTraceable for #name #ty_generics #where_clause {
#[inline]
#[allow(unused_variables, unused_imports)]
fn trace(&self, tracer: *mut ::js::jsapi::JSTracer) {
unsafe fn trace(&self, tracer: *mut ::js::jsapi::JSTracer) {
use ::dom::bindings::trace::JSTraceable;
match *self {
#match_body
@@ -122,8 +122,8 @@ which has an area, and the trait provides a way to get that object's area.
Now let's look at the `JSTraceable` trait, which we use for tracing:

```rust
pub trait JSTraceable {
fn trace(&self, trc: *mut JSTracer);
pub unsafe trait JSTraceable {
unsafe fn trace(&self, trc: *mut JSTracer);
}
```

@@ -182,7 +182,7 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref
}
impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
unsafe fn trace(&self, trc: *mut JSTracer) {
trace_reflector(trc, "", unsafe { (**self.ptr).reflector() });
}
}
@@ -105,18 +105,18 @@ impl<T: Reflectable> Deref for JS<T> {
}
}

impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
unsafe impl<T: Reflectable> JSTraceable for JS<T> {
unsafe fn trace(&self, trc: *mut JSTracer) {
#[cfg(debug_assertions)]
let trace_str = format!("for {} on heap", unsafe { type_name::<T>() });
let trace_str = format!("for {} on heap", type_name::<T>());
#[cfg(debug_assertions)]
let trace_info = &trace_str[..];
#[cfg(not(debug_assertions))]
let trace_info = "for DOM object on heap";

trace_reflector(trc,
trace_info,
unsafe { (**self.ptr).reflector() });
(**self.ptr).reflector());
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.