Refactor #[jstraceable] to #[derive(JSTraceable)]

fixes #6524
This commit is contained in:
David Winslow 2015-07-01 16:31:07 -04:00
parent e958d92be6
commit 4cf46bff2d
51 changed files with 97 additions and 137 deletions

View file

@ -16,7 +16,7 @@ pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotat
let mut item2 = (*item).clone(); let mut item2 = (*item).clone();
item2.attrs.push(quote_attr!(cx, #[must_root])); item2.attrs.push(quote_attr!(cx, #[must_root]));
item2.attrs.push(quote_attr!(cx, #[privatize])); item2.attrs.push(quote_attr!(cx, #[privatize]));
item2.attrs.push(quote_attr!(cx, #[jstraceable])); item2.attrs.push(quote_attr!(cx, #[derive(JSTraceable)]));
// The following attributes are only for internal usage // The following attributes are only for internal usage
item2.attrs.push(quote_attr!(cx, #[_generate_reflector])); item2.attrs.push(quote_attr!(cx, #[_generate_reflector]));
@ -30,7 +30,7 @@ pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotat
} }
} }
/// Provides the hook to expand `#[jstraceable]` into an implementation of `JSTraceable` /// Provides the hook to expand `#[derive(JSTraceable)]` into an implementation of `JSTraceable`
/// ///
/// The expansion basically calls `trace()` on all of the fields of the struct/enum, erroring if they do not /// The expansion basically calls `trace()` on all of the fields of the struct/enum, erroring if they do not
/// implement the method. /// implement the method.

View file

@ -7,10 +7,10 @@
//! Attributes this crate provides: //! Attributes this crate provides:
//! //!
//! - `#[privatize]` : Forces all fields in a struct/enum to be private //! - `#[privatize]` : Forces all fields in a struct/enum to be private
//! - `#[jstraceable]` : Auto-derives an implementation of `JSTraceable` for a struct in the script crate //! - `#[derive(JSTraceable)]` : Auto-derives an implementation of `JSTraceable` for a struct in the script crate
//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. //! - `#[must_root]` : Prevents data of the marked type from being used on the stack.
//! See the lints module for more details //! See the lints module for more details
//! - `#[dom_struct]` : Implies `#[privatize]`,`#[jstraceable]`, and `#[must_root]`. //! - `#[dom_struct]` : Implies `#[privatize]`,`#[derive(JSTraceable)]`, and `#[must_root]`.
//! Use this for structs that correspond to a DOM type //! Use this for structs that correspond to a DOM type
#![feature(plugin_registrar, quote, plugin, box_syntax, rustc_private)] #![feature(plugin_registrar, quote, plugin, box_syntax, rustc_private)]
@ -29,7 +29,7 @@ use syntax::ext::base::*;
use syntax::parse::token::intern; use syntax::parse::token::intern;
// Public for documentation to show up // Public for documentation to show up
/// Handles the auto-deriving for `#[jstraceable]` /// Handles the auto-deriving for `#[derive(JSTraceable)]`
pub mod jstraceable; pub mod jstraceable;
/// Handles the auto-deriving for `#[derive(HeapSizeOf)]` /// Handles the auto-deriving for `#[derive(HeapSizeOf)]`
pub mod heap_size; pub mod heap_size;
@ -43,7 +43,7 @@ pub mod casing;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct)); reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct));
reg.register_syntax_extension(intern("jstraceable"), MultiDecorator(box jstraceable::expand_jstraceable)); reg.register_syntax_extension(intern("derive_JSTraceable"), MultiDecorator(box jstraceable::expand_jstraceable));
reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector)); reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector));
reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heap_size::expand_heap_size)); reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heap_size::expand_heap_size));
reg.register_macro("to_lower", casing::expand_lower); reg.register_macro("to_lower", casing::expand_lower);

View file

@ -11,8 +11,7 @@ use net_traits::{Metadata, load_whole_resource, ResourceTask, PendingAsyncLoad};
use net_traits::AsyncResponseTarget; use net_traits::AsyncResponseTarget;
use url::Url; use url::Url;
#[jstraceable] #[derive(JSTraceable, PartialEq, Clone, Debug)]
#[derive(PartialEq, Clone, Debug)]
pub enum LoadType { pub enum LoadType {
Image(Url), Image(Url),
Script(Url), Script(Url),
@ -33,14 +32,14 @@ impl LoadType {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
pub struct DocumentLoader { pub struct DocumentLoader {
pub resource_task: ResourceTask, pub resource_task: ResourceTask,
notifier_data: Option<NotifierData>, notifier_data: Option<NotifierData>,
blocking_loads: Vec<LoadType>, blocking_loads: Vec<LoadType>,
} }
#[jstraceable] #[derive(JSTraceable)]
pub struct NotifierData { pub struct NotifierData {
pub script_chan: Box<ScriptChan + Send>, pub script_chan: Box<ScriptChan + Send>,
pub pipeline: PipelineId, pub pipeline: PipelineId,

View file

@ -28,8 +28,7 @@ pub enum AttrSettingType {
ReplacedAttr, ReplacedAttr,
} }
#[derive(PartialEq, Clone)] #[derive(JSTraceable, PartialEq, Clone)]
#[jstraceable]
pub enum AttrValue { pub enum AttrValue {
String(DOMString), String(DOMString),
TokenList(DOMString, Vec<Atom>), TokenList(DOMString, Vec<Atom>),

View file

@ -33,8 +33,7 @@ pub enum ExceptionHandling {
} }
/// A common base class for representing IDL callback function types. /// A common base class for representing IDL callback function types.
#[derive(PartialEq)] #[derive(JSTraceable, PartialEq)]
#[jstraceable]
pub struct CallbackFunction { pub struct CallbackFunction {
object: CallbackObject object: CallbackObject
} }
@ -57,8 +56,7 @@ impl CallbackFunction {
} }
/// A common base class for representing IDL callback interface types. /// A common base class for representing IDL callback interface types.
#[derive(PartialEq)] #[derive(JSTraceable, PartialEq)]
#[jstraceable]
pub struct CallbackInterface { pub struct CallbackInterface {
object: CallbackObject object: CallbackObject
} }
@ -66,7 +64,7 @@ pub struct CallbackInterface {
/// A common base class for representing IDL callback function and /// A common base class for representing IDL callback function and
/// callback interface types. /// callback interface types.
#[allow(raw_pointer_derive)] #[allow(raw_pointer_derive)]
#[jstraceable] #[derive(JSTraceable)]
struct CallbackObject { struct CallbackObject {
/// The underlying `JSObject`. /// The underlying `JSObject`.
callback: Heap<*mut JSObject>, callback: Heap<*mut JSObject>,

View file

@ -3189,8 +3189,7 @@ class CGEnum(CGThing):
decl = """\ decl = """\
#[repr(usize)] #[repr(usize)]
#[derive(PartialEq, Copy, Clone)] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[jstraceable]
pub enum %s { pub enum %s {
%s %s
} }
@ -5181,7 +5180,7 @@ class CGCallback(CGClass):
bases=[ClassBase(baseName)], bases=[ClassBase(baseName)],
constructors=self.getConstructors(), constructors=self.getConstructors(),
methods=realMethods+getters+setters, methods=realMethods+getters+setters,
decorators="#[derive(PartialEq)]#[jstraceable]") decorators="#[derive(JSTraceable, PartialEq)]")
def getConstructors(self): def getConstructors(self):
return [ClassConstructor( return [ClassConstructor(

View file

@ -46,7 +46,7 @@ pub enum GlobalRoot {
/// A traced reference to a global object, for use in fields of traced Rust /// A traced reference to a global object, for use in fields of traced Rust
/// structures. /// structures.
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
pub enum GlobalField { pub enum GlobalField {
/// A field for a `Window` object. /// A field for a `Window` object.

View file

@ -164,7 +164,7 @@ impl<T: Reflectable> HeapGCValue for JS<T> {
/// Must be used in place of traditional interior mutability to ensure proper /// Must be used in place of traditional interior mutability to ensure proper
/// GC barriers are enforced. /// GC barriers are enforced.
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable)]
pub struct MutHeapJSVal { pub struct MutHeapJSVal {
val: UnsafeCell<Heap<JSVal>>, val: UnsafeCell<Heap<JSVal>>,
} }
@ -196,7 +196,7 @@ impl MutHeapJSVal {
/// A holder that provides interior mutability for GC-managed values such as /// A holder that provides interior mutability for GC-managed values such as
/// `JS<T>`. /// `JS<T>`.
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable)]
pub struct MutHeap<T: HeapGCValue+Copy> { pub struct MutHeap<T: HeapGCValue+Copy> {
val: Cell<T>, val: Cell<T>,
} }
@ -225,7 +225,7 @@ impl<T: HeapGCValue+Copy> MutHeap<T> {
/// place of traditional internal mutability to ensure that the proper GC /// place of traditional internal mutability to ensure that the proper GC
/// barriers are enforced. /// barriers are enforced.
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable)]
pub struct MutNullableHeap<T: HeapGCValue+Copy> { pub struct MutNullableHeap<T: HeapGCValue+Copy> {
ptr: Cell<Option<T>> ptr: Cell<Option<T>>
} }

View file

@ -9,8 +9,7 @@ use num::Float;
use std::ops::Deref; use std::ops::Deref;
/// Encapsulates the IDL restricted float type. /// Encapsulates the IDL restricted float type.
#[derive(Clone,Eq,PartialEq)] #[derive(JSTraceable,Clone,Eq,PartialEq)]
#[jstraceable]
pub struct Finite<T: Float>(T); pub struct Finite<T: Float>(T);
unsafe impl<T: Float> Zeroable for Finite<T> {} unsafe impl<T: Float> Zeroable for Finite<T> {}

View file

@ -12,8 +12,7 @@ use std::str;
use std::str::FromStr; use std::str::FromStr;
/// Encapsulates the IDL `ByteString` type. /// Encapsulates the IDL `ByteString` type.
#[derive(Clone,Eq,PartialEq)] #[derive(JSTraceable,Clone,Eq,PartialEq)]
#[jstraceable]
pub struct ByteString(Vec<u8>); pub struct ByteString(Vec<u8>);
impl ByteString { impl ByteString {

View file

@ -12,7 +12,7 @@
//! phase. (This happens through `JSClass.trace` for non-proxy bindings, and //! phase. (This happens through `JSClass.trace` for non-proxy bindings, and
//! through `ProxyTraps.trace` otherwise.) //! through `ProxyTraps.trace` otherwise.)
//! 2. `_trace` calls `Foo::trace()` (an implementation of `JSTraceable`). //! 2. `_trace` calls `Foo::trace()` (an implementation of `JSTraceable`).
//! This is typically derived via a `#[dom_struct]` (implies `#[jstraceable]`) annotation. //! This is typically derived via a `#[dom_struct]` (implies `#[derive(JSTraceable)]`) annotation.
//! Non-JS-managed types have an empty inline `trace()` method, //! Non-JS-managed types have an empty inline `trace()` method,
//! achieved via `no_jsmanaged_fields!` or similar. //! achieved via `no_jsmanaged_fields!` or similar.
//! 3. For all fields, `Foo::trace()` //! 3. For all fields, `Foo::trace()`
@ -410,7 +410,7 @@ impl RootedTraceableSet {
/// If you have GC things like *mut JSObject or JSVal, use jsapi::Rooted. /// If you have GC things like *mut JSObject or JSVal, use jsapi::Rooted.
/// If you have an arbitrary number of Reflectables to root, use RootedVec<JS<T>> /// If you have an arbitrary number of Reflectables to root, use RootedVec<JS<T>>
/// If you know what you're doing, use this. /// If you know what you're doing, use this.
#[jstraceable] #[derive(JSTraceable)]
pub struct RootedTraceable<'a, T: 'a + JSTraceable> { pub struct RootedTraceable<'a, T: 'a + JSTraceable> {
ptr: &'a T ptr: &'a T
} }
@ -434,7 +434,7 @@ impl<'a, T: JSTraceable> Drop for RootedTraceable<'a, T> {
/// Must be a reflectable /// Must be a reflectable
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
#[no_move] #[no_move]
#[jstraceable] #[derive(JSTraceable)]
pub struct RootedVec<T: JSTraceable + Reflectable> { pub struct RootedVec<T: JSTraceable + Reflectable> {
v: Vec<T> v: Vec<T>
} }

View file

@ -65,7 +65,7 @@ use string_cache::{Atom, Namespace};
pub struct WindowProxyHandler(pub *const libc::c_void); pub struct WindowProxyHandler(pub *const libc::c_void);
#[allow(raw_pointer_derive)] #[allow(raw_pointer_derive)]
#[jstraceable] #[derive(JSTraceable)]
/// Static data associated with a global object. /// Static data associated with a global object.
pub struct GlobalStaticData { pub struct GlobalStaticData {
/// The WindowProxy proxy handler for this global. /// The WindowProxy proxy handler for this global.

View file

@ -17,7 +17,7 @@ use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cmp::{min, max}; use std::cmp::{min, max};
#[jstraceable] #[derive(JSTraceable)]
pub enum BlobTypeId { pub enum BlobTypeId {
Blob, Blob,
File, File,

View file

@ -27,7 +27,7 @@ use js::{JSTrue, JSFalse};
use std::ptr; use std::ptr;
use std::default::Default; use std::default::Default;
#[jstraceable] #[derive(JSTraceable)]
#[privatize] #[privatize]
#[allow(raw_pointer_derive)] #[allow(raw_pointer_derive)]
pub struct BrowserContext { pub struct BrowserContext {
@ -87,7 +87,7 @@ impl BrowserContext {
// without a reflector, so we don't mark this as #[dom_struct] // without a reflector, so we don't mark this as #[dom_struct]
#[must_root] #[must_root]
#[privatize] #[privatize]
#[jstraceable] #[derive(JSTraceable)]
pub struct SessionHistoryEntry { pub struct SessionHistoryEntry {
document: JS<Document>, document: JS<Document>,
children: Vec<BrowserContext> children: Vec<BrowserContext>

View file

@ -21,8 +21,7 @@ pub struct CanvasGradient {
stops: DOMRefCell<Vec<CanvasGradientStop>>, stops: DOMRefCell<Vec<CanvasGradientStop>>,
} }
#[jstraceable] #[derive(JSTraceable, Clone)]
#[derive(Clone)]
pub enum CanvasGradientStyle { pub enum CanvasGradientStyle {
Linear(LinearGradientStyle), Linear(LinearGradientStyle),
Radial(RadialGradientStyle), Radial(RadialGradientStyle),

View file

@ -48,8 +48,7 @@ use url::Url;
use util::vec::byte_swap; use util::vec::byte_swap;
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable, Clone)]
#[derive(Clone)]
pub enum CanvasFillOrStrokeStyle { pub enum CanvasFillOrStrokeStyle {
Color(RGBA), Color(RGBA),
Gradient(JS<CanvasGradient>), Gradient(JS<CanvasGradient>),
@ -68,8 +67,7 @@ pub struct CanvasRenderingContext2D {
} }
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable, Clone)]
#[derive(Clone)]
struct CanvasContextState { struct CanvasContextState {
global_alpha: f64, global_alpha: f64,
global_composition: CompositionOrBlending, global_composition: CompositionOrBlending,

View file

@ -154,8 +154,7 @@ impl<'a> CharacterDataMethods for &'a CharacterData {
} }
/// The different types of CharacterData. /// The different types of CharacterData.
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(JSTraceable, Copy, Clone, PartialEq, Debug)]
#[jstraceable]
pub enum CharacterDataTypeId { pub enum CharacterDataTypeId {
Comment, Comment,
Text, Text,

View file

@ -45,8 +45,7 @@ use std::sync::mpsc::{Sender, Receiver, channel};
/// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with /// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
/// every message. While this SendableWorkerScriptChan is alive, the associated Worker object /// every message. While this SendableWorkerScriptChan is alive, the associated Worker object
/// will remain alive. /// will remain alive.
#[derive(Clone)] #[derive(JSTraceable, Clone)]
#[jstraceable]
pub struct SendableWorkerScriptChan { pub struct SendableWorkerScriptChan {
sender: Sender<(TrustedWorkerAddress, ScriptMsg)>, sender: Sender<(TrustedWorkerAddress, ScriptMsg)>,
worker: TrustedWorkerAddress, worker: TrustedWorkerAddress,

View file

@ -100,8 +100,7 @@ use std::sync::mpsc::channel;
use std::rc::Rc; use std::rc::Rc;
use time; use time;
#[derive(PartialEq)] #[derive(JSTraceable, PartialEq)]
#[jstraceable]
pub enum IsHTMLDocument { pub enum IsHTMLDocument {
HTMLDocument, HTMLDocument,
NonHTMLDocument, NonHTMLDocument,
@ -164,7 +163,7 @@ impl DocumentDerived for EventTarget {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct ImagesFilter; struct ImagesFilter;
impl CollectionFilter for ImagesFilter { impl CollectionFilter for ImagesFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -172,7 +171,7 @@ impl CollectionFilter for ImagesFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct EmbedsFilter; struct EmbedsFilter;
impl CollectionFilter for EmbedsFilter { impl CollectionFilter for EmbedsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -180,7 +179,7 @@ impl CollectionFilter for EmbedsFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct LinksFilter; struct LinksFilter;
impl CollectionFilter for LinksFilter { impl CollectionFilter for LinksFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -189,7 +188,7 @@ impl CollectionFilter for LinksFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct FormsFilter; struct FormsFilter;
impl CollectionFilter for FormsFilter { impl CollectionFilter for FormsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -197,7 +196,7 @@ impl CollectionFilter for FormsFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct ScriptsFilter; struct ScriptsFilter;
impl CollectionFilter for ScriptsFilter { impl CollectionFilter for ScriptsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -205,7 +204,7 @@ impl CollectionFilter for ScriptsFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct AnchorsFilter; struct AnchorsFilter;
impl CollectionFilter for AnchorsFilter { impl CollectionFilter for AnchorsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -213,7 +212,7 @@ impl CollectionFilter for AnchorsFilter {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
struct AppletsFilter; struct AppletsFilter;
impl CollectionFilter for AppletsFilter { impl CollectionFilter for AppletsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
@ -1748,7 +1747,7 @@ impl<'a> DocumentMethods for &'a Document {
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
fn NamedGetter(self, _cx: *mut JSContext, name: DOMString, found: &mut bool) fn NamedGetter(self, _cx: *mut JSContext, name: DOMString, found: &mut bool)
-> *mut JSObject { -> *mut JSObject {
#[jstraceable] #[derive(JSTraceable)]
struct NamedElementFilter { struct NamedElementFilter {
name: Atom, name: Atom,
} }

View file

@ -13,8 +13,7 @@ use util::str::DOMString;
use std::borrow::ToOwned; use std::borrow::ToOwned;
#[repr(u16)] #[repr(u16)]
#[derive(Copy, Clone, Debug)] #[derive(JSTraceable, Copy, Clone, Debug)]
#[jstraceable]
pub enum DOMErrorName { pub enum DOMErrorName {
IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR, IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR,
HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR, HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR,

View file

@ -117,8 +117,7 @@ impl PartialEq for Element {
} }
} }
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(JSTraceable, Copy, Clone, PartialEq, Debug)]
#[jstraceable]
pub enum ElementTypeId { pub enum ElementTypeId {
HTMLElement(HTMLElementTypeId), HTMLElement(HTMLElementTypeId),
Element, Element,

View file

@ -18,8 +18,7 @@ use std::default::Default;
use time; use time;
#[jstraceable] #[derive(JSTraceable, Copy, Clone)]
#[derive(Copy, Clone)]
#[repr(u16)] #[repr(u16)]
pub enum EventPhase { pub enum EventPhase {
None = EventConstants::NONE, None = EventConstants::NONE,
@ -28,8 +27,7 @@ pub enum EventPhase {
Bubbling = EventConstants::BUBBLING_PHASE, Bubbling = EventConstants::BUBBLING_PHASE,
} }
#[derive(PartialEq)] #[derive(JSTraceable, PartialEq)]
#[jstraceable]
pub enum EventTypeId { pub enum EventTypeId {
CustomEvent, CustomEvent,
HTMLEvent, HTMLEvent,

View file

@ -36,15 +36,13 @@ use url::Url;
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Copy, Clone, PartialEq)] #[derive(JSTraceable, Copy, Clone, PartialEq)]
#[jstraceable]
pub enum ListenerPhase { pub enum ListenerPhase {
Capturing, Capturing,
Bubbling, Bubbling,
} }
#[derive(Copy, Clone)] #[derive(JSTraceable, Copy, Clone)]
#[jstraceable]
pub enum EventTargetTypeId { pub enum EventTargetTypeId {
Node(NodeTypeId), Node(NodeTypeId),
WebSocket, WebSocket,
@ -90,8 +88,7 @@ impl EventTargetTypeId {
} }
} }
#[derive(Clone, PartialEq)] #[derive(JSTraceable, Clone, PartialEq)]
#[jstraceable]
pub enum EventListenerType { pub enum EventListenerType {
Additive(Rc<EventListener>), Additive(Rc<EventListener>),
Inline(Rc<EventListener>), Inline(Rc<EventListener>),
@ -106,8 +103,7 @@ impl EventListenerType {
} }
} }
#[derive(Clone, PartialEq)] #[derive(JSTraceable, Clone, PartialEq)]
#[jstraceable]
#[privatize] #[privatize]
pub struct EventListenerEntry { pub struct EventListenerEntry {
phase: ListenerPhase, phase: ListenerPhase,

View file

@ -21,8 +21,7 @@ use std::borrow::ToOwned;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::Entry::{Occupied, Vacant};
#[derive(Clone)] #[derive(JSTraceable, Clone)]
#[jstraceable]
#[must_root] #[must_root]
pub enum FormDatum { pub enum FormDatum {
StringData(DOMString), StringData(DOMString),

View file

@ -27,8 +27,7 @@ use std::borrow::ToOwned;
use util::str::DOMString; use util::str::DOMString;
use std::cell::Cell; use std::cell::Cell;
#[jstraceable] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
#[allow(dead_code)] #[allow(dead_code)]
enum ButtonType { enum ButtonType {
ButtonSubmit, ButtonSubmit,

View file

@ -37,9 +37,8 @@ use std::sync::mpsc::Sender;
const DEFAULT_WIDTH: u32 = 300; const DEFAULT_WIDTH: u32 = 300;
const DEFAULT_HEIGHT: u32 = 150; const DEFAULT_HEIGHT: u32 = 150;
#[jstraceable]
#[must_root] #[must_root]
#[derive(Clone, Copy)] #[derive(JSTraceable, Clone, Copy)]
pub enum CanvasContext { pub enum CanvasContext {
Context2d(JS<CanvasRenderingContext2D>), Context2d(JS<CanvasRenderingContext2D>),
WebGL(JS<WebGLRenderingContext>), WebGL(JS<WebGLRenderingContext>),

View file

@ -23,7 +23,7 @@ pub trait CollectionFilter : JSTraceable {
fn filter<'a>(&self, elem: &'a Element, root: &'a Node) -> bool; fn filter<'a>(&self, elem: &'a Element, root: &'a Node) -> bool;
} }
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
pub enum CollectionTypeId { pub enum CollectionTypeId {
Static(Vec<JS<Element>>), Static(Vec<JS<Element>>),
@ -58,7 +58,7 @@ impl HTMLCollection {
fn all_elements(window: &Window, root: &Node, fn all_elements(window: &Window, root: &Node,
namespace_filter: Option<Namespace>) -> Root<HTMLCollection> { namespace_filter: Option<Namespace>) -> Root<HTMLCollection> {
#[jstraceable] #[derive(JSTraceable)]
struct AllElementFilter { struct AllElementFilter {
namespace_filter: Option<Namespace> namespace_filter: Option<Namespace>
} }
@ -80,7 +80,7 @@ impl HTMLCollection {
return HTMLCollection::all_elements(window, root, None); return HTMLCollection::all_elements(window, root, None);
} }
#[jstraceable] #[derive(JSTraceable)]
struct TagNameFilter { struct TagNameFilter {
tag: Atom, tag: Atom,
ascii_lower_tag: Atom, ascii_lower_tag: Atom,
@ -111,7 +111,7 @@ impl HTMLCollection {
if tag == "*" { if tag == "*" {
return HTMLCollection::all_elements(window, root, namespace_filter); return HTMLCollection::all_elements(window, root, namespace_filter);
} }
#[jstraceable] #[derive(JSTraceable)]
struct TagNameNSFilter { struct TagNameNSFilter {
tag: Atom, tag: Atom,
namespace_filter: Option<Namespace> namespace_filter: Option<Namespace>
@ -136,7 +136,7 @@ impl HTMLCollection {
pub fn by_class_name(window: &Window, root: &Node, classes: DOMString) pub fn by_class_name(window: &Window, root: &Node, classes: DOMString)
-> Root<HTMLCollection> { -> Root<HTMLCollection> {
#[jstraceable] #[derive(JSTraceable)]
struct ClassNameFilter { struct ClassNameFilter {
classes: Vec<Atom> classes: Vec<Atom>
} }
@ -154,7 +154,7 @@ impl HTMLCollection {
} }
pub fn children(window: &Window, root: &Node) -> Root<HTMLCollection> { pub fn children(window: &Window, root: &Node) -> Root<HTMLCollection> {
#[jstraceable] #[derive(JSTraceable)]
struct ElementChildFilter; struct ElementChildFilter;
impl CollectionFilter for ElementChildFilter { impl CollectionFilter for ElementChildFilter {
fn filter(&self, elem: &Element, root: &Node) -> bool { fn filter(&self, elem: &Element, root: &Node) -> bool {

View file

@ -50,7 +50,7 @@ impl HTMLDataListElement {
impl<'a> HTMLDataListElementMethods for &'a HTMLDataListElement { impl<'a> HTMLDataListElementMethods for &'a HTMLDataListElement {
fn Options(self) -> Root<HTMLCollection> { fn Options(self) -> Root<HTMLCollection> {
#[jstraceable] #[derive(JSTraceable)]
struct HTMLDataListOptionsFilter; struct HTMLDataListOptionsFilter;
impl CollectionFilter for HTMLDataListOptionsFilter { impl CollectionFilter for HTMLDataListOptionsFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {

View file

@ -309,8 +309,7 @@ impl<'a> VirtualMethods for &'a HTMLElement {
} }
} }
#[derive(Copy, Clone, Debug)] #[derive(JSTraceable, Copy, Clone, Debug)]
#[jstraceable]
pub enum HTMLElementTypeId { pub enum HTMLElementTypeId {
HTMLElement, HTMLElement,

View file

@ -56,7 +56,7 @@ impl HTMLFieldSetElement {
impl<'a> HTMLFieldSetElementMethods for &'a HTMLFieldSetElement { impl<'a> HTMLFieldSetElementMethods for &'a HTMLFieldSetElement {
// https://www.whatwg.org/html/#dom-fieldset-elements // https://www.whatwg.org/html/#dom-fieldset-elements
fn Elements(self) -> Root<HTMLCollection> { fn Elements(self) -> Root<HTMLCollection> {
#[jstraceable] #[derive(JSTraceable)]
struct ElementsFilter; struct ElementsFilter;
impl CollectionFilter for ElementsFilter { impl CollectionFilter for ElementsFilter {
fn filter<'a>(&self, elem: &'a Element, _root: &'a Node) -> bool { fn filter<'a>(&self, elem: &'a Element, _root: &'a Node) -> bool {

View file

@ -12,7 +12,7 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeTypeId};
use util::str::DOMString; use util::str::DOMString;
#[jstraceable] #[derive(JSTraceable)]
pub enum HeadingLevel { pub enum HeadingLevel {
Heading1, Heading1,
Heading2, Heading2,

View file

@ -45,8 +45,7 @@ use std::cell::Cell;
const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; const DEFAULT_SUBMIT_VALUE: &'static str = "Submit";
const DEFAULT_RESET_VALUE: &'static str = "Reset"; const DEFAULT_RESET_VALUE: &'static str = "Reset";
#[jstraceable] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
#[allow(dead_code)] #[allow(dead_code)]
enum InputType { enum InputType {
InputSubmit, InputSubmit,
@ -80,7 +79,7 @@ impl PartialEq for HTMLInputElement {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
struct InputActivationState { struct InputActivationState {
indeterminate: bool, indeterminate: bool,

View file

@ -41,8 +41,7 @@ impl HTMLMediaElement {
} }
} }
#[derive(Copy, Clone, Debug)] #[derive(JSTraceable, Copy, Clone, Debug)]
#[jstraceable]
pub enum HTMLMediaElementTypeId { pub enum HTMLMediaElementTypeId {
HTMLAudioElement = 0, HTMLAudioElement = 0,
HTMLVideoElement = 1, HTMLVideoElement = 1,

View file

@ -22,8 +22,7 @@ use std::cmp::max;
const DEFAULT_COLSPAN: u32 = 1; const DEFAULT_COLSPAN: u32 = 1;
#[derive(Copy, Clone, Debug)] #[derive(JSTraceable, Copy, Clone, Debug)]
#[jstraceable]
pub enum HTMLTableCellElementTypeId { pub enum HTMLTableCellElementTypeId {
HTMLTableDataCellElement = 0, HTMLTableDataCellElement = 0,
HTMLTableHeaderCellElement = 1, HTMLTableHeaderCellElement = 1,

View file

@ -214,7 +214,7 @@ macro_rules! make_atomic_setter(
); );
/// For use on non-jsmanaged types /// For use on non-jsmanaged types
/// Use #[jstraceable] on JS managed types /// Use #[derive(JSTraceable)] on JS managed types
macro_rules! no_jsmanaged_fields( macro_rules! no_jsmanaged_fields(
($($ty:ident),+) => ( ($($ty:ident),+) => (
$( $(

View file

@ -135,7 +135,7 @@ impl NodeDerived for EventTarget {
bitflags! { bitflags! {
#[doc = "Flags for node items."] #[doc = "Flags for node items."]
#[jstraceable] #[derive(JSTraceable)]
flags NodeFlags: u16 { flags NodeFlags: u16 {
#[doc = "Specifies whether this node is in a document."] #[doc = "Specifies whether this node is in a document."]
const IS_IN_DOC = 0x01, const IS_IN_DOC = 0x01,
@ -279,8 +279,7 @@ impl LayoutDataRef {
} }
/// The different types of nodes. /// The different types of nodes.
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(JSTraceable, Copy, Clone, PartialEq, Debug)]
#[jstraceable]
pub enum NodeTypeId { pub enum NodeTypeId {
CharacterData(CharacterDataTypeId), CharacterData(CharacterDataTypeId),
DocumentType, DocumentType,

View file

@ -217,7 +217,7 @@ impl<'a> PrivateNodeIteratorHelpers for &'a NodeIterator {
} }
#[jstraceable] #[derive(JSTraceable)]
pub enum Filter { pub enum Filter {
None, None,
Native(fn (node: &Node) -> u16), Native(fn (node: &Node) -> u16),

View file

@ -10,7 +10,7 @@ use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::node::{Node, NodeHelpers}; use dom::node::{Node, NodeHelpers};
use dom::window::Window; use dom::window::Window;
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
pub enum NodeListType { pub enum NodeListType {
Simple(Vec<JS<Node>>), Simple(Vec<JS<Node>>),

View file

@ -290,7 +290,7 @@ impl<'a> RangeMethods for &'a Range {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
#[privatize] #[privatize]
pub struct RangeInner { pub struct RangeInner {
@ -424,7 +424,7 @@ impl RangeInner {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
#[privatize] #[privatize]
pub struct BoundaryPoint { pub struct BoundaryPoint {

View file

@ -36,7 +36,7 @@ use hyper::header::ContentType;
use hyper::mime::{Mime, TopLevel, SubLevel}; use hyper::mime::{Mime, TopLevel, SubLevel};
#[must_root] #[must_root]
#[jstraceable] #[derive(JSTraceable)]
pub struct Sink { pub struct Sink {
pub base_url: Option<Url>, pub base_url: Option<Url>,
pub document: JS<Document>, pub document: JS<Document>,

View file

@ -502,7 +502,7 @@ impl<'a> Iterator for &'a TreeWalker {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
pub enum Filter { pub enum Filter {
None, None,
Native(fn (node: &Node) -> u16), Native(fn (node: &Node) -> u16),

View file

@ -33,8 +33,7 @@ use websocket::stream::WebSocketStream;
use websocket::client::request::Url; use websocket::client::request::Url;
use websocket::Client; use websocket::Client;
#[derive(PartialEq, Copy, Clone)] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[jstraceable]
enum WebSocketRequestState { enum WebSocketRequestState {
Connecting = 0, Connecting = 0,
Open = 1, Open = 1,

View file

@ -70,8 +70,7 @@ use std::sync::mpsc::TryRecvError::{Empty, Disconnected};
use time; use time;
/// Current state of the window object /// Current state of the window object
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(JSTraceable, Copy, Clone, Debug, PartialEq)]
#[jstraceable]
enum WindowState { enum WindowState {
Alive, Alive,
Zombie, // Pipeline is closed, but the window hasn't been GCed yet. Zombie, // Pipeline is closed, but the window hasn't been GCed yet.

View file

@ -33,8 +33,7 @@ use std::default::Default;
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc; use std::rc::Rc;
#[derive(Copy, Clone, PartialEq)] #[derive(JSTraceable, Copy, Clone, PartialEq)]
#[jstraceable]
pub enum WorkerGlobalScopeTypeId { pub enum WorkerGlobalScopeTypeId {
DedicatedGlobalScope, DedicatedGlobalScope,
} }

View file

@ -67,8 +67,7 @@ use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLS
pub type SendParam = StringOrURLSearchParams; pub type SendParam = StringOrURLSearchParams;
#[derive(PartialEq, Copy, Clone)] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[jstraceable]
enum XMLHttpRequestState { enum XMLHttpRequestState {
Unsent = 0, Unsent = 0,
Opened = 1, Opened = 1,
@ -77,8 +76,7 @@ enum XMLHttpRequestState {
Done = 4, Done = 4,
} }
#[derive(PartialEq, Clone, Copy)] #[derive(JSTraceable, PartialEq, Clone, Copy)]
#[jstraceable]
pub struct GenerationId(u32); pub struct GenerationId(u32);
/// Closure of required data for each async network event that comprises the /// Closure of required data for each async network event that comprises the

View file

@ -8,8 +8,7 @@ use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived; use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived;
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
#[derive(Copy, Clone, PartialEq)] #[derive(JSTraceable, Copy, Clone, PartialEq)]
#[jstraceable]
pub enum XMLHttpRequestEventTargetTypeId { pub enum XMLHttpRequestEventTargetTypeId {
XMLHttpRequest, XMLHttpRequest,
XMLHttpRequestUpload, XMLHttpRequestUpload,

View file

@ -11,6 +11,7 @@
#![feature(core)] #![feature(core)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(custom_attribute)] #![feature(custom_attribute)]
#![feature(custom_derive)]
#![feature(drain)] #![feature(drain)]
#![feature(hashmap_hasher)] #![feature(hashmap_hasher)]
#![feature(mpsc_select)] #![feature(mpsc_select)]

View file

@ -14,7 +14,7 @@ use std::rc::Rc;
use url::Url; use url::Url;
/// Encapsulates a handle to a frame in a frame tree. /// Encapsulates a handle to a frame in a frame tree.
#[jstraceable] #[derive(JSTraceable)]
pub struct Page { pub struct Page {
/// Pipeline id associated with this page. /// Pipeline id associated with this page.
id: PipelineId, id: PipelineId,
@ -133,7 +133,7 @@ impl Page {
} }
/// Information for one frame in the browsing context. /// Information for one frame in the browsing context.
#[jstraceable] #[derive(JSTraceable)]
#[must_root] #[must_root]
pub struct Frame { pub struct Frame {
/// The document for this frame. /// The document for this frame.

View file

@ -121,7 +121,7 @@ unsafe extern fn trace_rust_roots(tr: *mut JSTracer, _data: *mut libc::c_void) {
/// data that will need to be present when the document and frame tree entry are created, /// data that will need to be present when the document and frame tree entry are created,
/// but is only easily available at initiation of the load and on a push basis (so some /// but is only easily available at initiation of the load and on a push basis (so some
/// data will be updated according to future resize events, viewport changes, etc.) /// data will be updated according to future resize events, viewport changes, etc.)
#[jstraceable] #[derive(JSTraceable)]
struct InProgressLoad { struct InProgressLoad {
/// The pipeline which requested this load. /// The pipeline which requested this load.
pipeline_id: PipelineId, pipeline_id: PipelineId,
@ -226,7 +226,7 @@ impl ScriptPort for Receiver<(TrustedWorkerAddress, ScriptMsg)> {
} }
/// Encapsulates internal communication within the script task. /// Encapsulates internal communication within the script task.
#[jstraceable] #[derive(JSTraceable)]
pub struct NonWorkerScriptChan(pub Sender<ScriptMsg>); pub struct NonWorkerScriptChan(pub Sender<ScriptMsg>);
impl ScriptChan for NonWorkerScriptChan { impl ScriptChan for NonWorkerScriptChan {
@ -269,7 +269,7 @@ impl Drop for StackRootTLS {
/// Information for an entire page. Pages are top-level browsing contexts and can contain multiple /// Information for an entire page. Pages are top-level browsing contexts and can contain multiple
/// frames. /// frames.
#[jstraceable] #[derive(JSTraceable)]
pub struct ScriptTask { pub struct ScriptTask {
/// A handle to the information pertaining to page layout /// A handle to the information pertaining to page layout
page: DOMRefCell<Option<Rc<Page>>>, page: DOMRefCell<Option<Rc<Page>>>,

View file

@ -21,8 +21,7 @@ pub enum Selection {
NotSelected NotSelected
} }
#[jstraceable] #[derive(JSTraceable, Copy, Clone)]
#[derive(Copy, Clone)]
pub struct TextPoint { pub struct TextPoint {
/// 0-based line number /// 0-based line number
pub line: usize, pub line: usize,
@ -31,7 +30,7 @@ pub struct TextPoint {
} }
/// Encapsulated state for handling keyboard input in a single or multiline text input control. /// Encapsulated state for handling keyboard input in a single or multiline text input control.
#[jstraceable] #[derive(JSTraceable)]
pub struct TextInput<T: ClipboardProvider> { pub struct TextInput<T: ClipboardProvider> {
/// Current text input content, split across lines without trailing '\n' /// Current text input content, split across lines without trailing '\n'
lines: Vec<DOMString>, lines: Vec<DOMString>,

View file

@ -29,12 +29,10 @@ use std::hash::{Hash, Hasher};
use std::rc::Rc; use std::rc::Rc;
use std::default::Default; use std::default::Default;
#[derive(PartialEq, Eq)] #[derive(JSTraceable, PartialEq, Eq, Copy, Clone)]
#[jstraceable]
#[derive(Copy, Clone)]
pub struct TimerId(i32); pub struct TimerId(i32);
#[jstraceable] #[derive(JSTraceable)]
#[privatize] #[privatize]
struct TimerHandle { struct TimerHandle {
handle: TimerId, handle: TimerId,
@ -42,8 +40,7 @@ struct TimerHandle {
control_chan: Option<Sender<TimerControlMsg>>, control_chan: Option<Sender<TimerControlMsg>>,
} }
#[jstraceable] #[derive(JSTraceable, Clone)]
#[derive(Clone)]
pub enum TimerCallback { pub enum TimerCallback {
StringTimerCallback(DOMString), StringTimerCallback(DOMString),
FunctionTimerCallback(Rc<Function>) FunctionTimerCallback(Rc<Function>)
@ -68,7 +65,7 @@ impl TimerHandle {
} }
} }
#[jstraceable] #[derive(JSTraceable)]
#[privatize] #[privatize]
pub struct TimerManager { pub struct TimerManager {
active_timers: DOMRefCell<HashMap<TimerId, TimerHandle>>, active_timers: DOMRefCell<HashMap<TimerId, TimerHandle>>,
@ -85,16 +82,14 @@ impl Drop for TimerManager {
} }
// Enum allowing more descriptive values for the is_interval field // Enum allowing more descriptive values for the is_interval field
#[jstraceable] #[derive(JSTraceable, PartialEq, Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
pub enum IsInterval { pub enum IsInterval {
Interval, Interval,
NonInterval, NonInterval,
} }
// Messages sent control timers from script task // Messages sent control timers from script task
#[jstraceable] #[derive(JSTraceable, PartialEq, Copy, Clone, Debug)]
#[derive(PartialEq, Copy, Clone, Debug)]
pub enum TimerControlMsg { pub enum TimerControlMsg {
Cancel, Cancel,
Suspend, Suspend,
@ -105,7 +100,7 @@ pub enum TimerControlMsg {
// (ie. function value to invoke and all arguments to pass // (ie. function value to invoke and all arguments to pass
// to the function when calling it) // to the function when calling it)
// TODO: Handle rooting during fire_timer when movable GC is turned on // TODO: Handle rooting during fire_timer when movable GC is turned on
#[jstraceable] #[derive(JSTraceable)]
#[privatize] #[privatize]
struct TimerData { struct TimerData {
is_interval: IsInterval, is_interval: IsInterval,