mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
2e81cbab76
Right now they're duplicated because we need a new serde release (ping @dtolnay), a new cssparser release (ping @SimonSapin) and a new release of html5ever with https://github.com/servo/html5ever/pull/336 Source-Repo: https://github.com/servo/servo Source-Revision: 6cb78057bb115262f31548ef651b24a48957f11d --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : fc0f0e8c9c82e44f307c33d3a137a2a1324b236e
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#[macro_use] extern crate quote;
|
|
#[macro_use] extern crate syn;
|
|
#[macro_use] extern crate synstructure;
|
|
|
|
decl_derive!([JSTraceable] => js_traceable_derive);
|
|
|
|
fn js_traceable_derive(s: synstructure::Structure) -> quote::Tokens {
|
|
let match_body = s.each(|binding| {
|
|
Some(quote!(#binding.trace(tracer);))
|
|
});
|
|
|
|
let ast = s.ast();
|
|
let name = ast.ident;
|
|
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
|
|
let mut where_clause = where_clause.unwrap_or(&parse_quote!(where)).clone();
|
|
for param in ast.generics.type_params() {
|
|
let ident = param.ident;
|
|
where_clause.predicates.push(parse_quote!(#ident: ::dom::bindings::trace::JSTraceable))
|
|
}
|
|
|
|
let tokens = quote! {
|
|
#[allow(unsafe_code)]
|
|
unsafe impl #impl_generics ::dom::bindings::trace::JSTraceable for #name #ty_generics #where_clause {
|
|
#[inline]
|
|
#[allow(unused_variables, unused_imports)]
|
|
unsafe fn trace(&self, tracer: *mut ::js::jsapi::JSTracer) {
|
|
use ::dom::bindings::trace::JSTraceable;
|
|
match *self {
|
|
#match_body
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
tokens
|
|
}
|