Make Reflector #[must_root], propagate to non-HTMLElements

This commit is contained in:
Manish Goregaokar 2014-09-17 00:51:20 +05:30
parent f0b8391762
commit 30014c3919
40 changed files with 53 additions and 12 deletions

View file

@ -83,6 +83,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
} }
/// Trace the `JSObject` held by `reflector`. /// Trace the `JSObject` held by `reflector`.
#[allow(unrooted_must_root)]
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) { pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
trace_object(tracer, description, reflector.get_jsobject()) trace_object(tracer, description, reflector.get_jsobject())
} }

View file

@ -455,8 +455,9 @@ pub fn reflect_dom_object<T: Reflectable>
} }
/// A struct to store a reference to the reflector of a DOM object. /// A struct to store a reference to the reflector of a DOM object.
#[allow(raw_pointer_deriving)] #[allow(raw_pointer_deriving, unrooted_must_root)]
#[deriving(PartialEq)] #[deriving(PartialEq)]
#[must_root]
pub struct Reflector { pub struct Reflector {
object: Cell<*mut JSObject>, object: Cell<*mut JSObject>,
} }

View file

@ -16,6 +16,7 @@ pub enum BlobType {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Blob { pub struct Blob {
reflector_: Reflector, reflector_: Reflector,
type_: BlobType type_: BlobType

View file

@ -18,6 +18,7 @@ use servo_util::str::DOMString;
use std::cell::RefCell; use std::cell::RefCell;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct CharacterData { pub struct CharacterData {
pub node: Node, pub node: Node,
pub data: Traceable<RefCell<DOMString>>, pub data: Traceable<RefCell<DOMString>>,

View file

@ -17,6 +17,7 @@ use servo_util::str::DOMString;
/// An HTML comment. /// An HTML comment.
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Comment { pub struct Comment {
pub characterdata: CharacterData, pub characterdata: CharacterData,
} }
@ -35,8 +36,8 @@ impl Comment {
} }
pub fn new(text: DOMString, document: &JSRef<Document>) -> Temporary<Comment> { pub fn new(text: DOMString, document: &JSRef<Document>) -> Temporary<Comment> {
let node = Comment::new_inherited(text, document); Node::reflect_node(box Comment::new_inherited(text, document),
Node::reflect_node(box node, document, CommentBinding::Wrap) document, CommentBinding::Wrap)
} }
pub fn Constructor(global: &GlobalRef, data: DOMString) -> Fallible<Temporary<Comment>> { pub fn Constructor(global: &GlobalRef, data: DOMString) -> Fallible<Temporary<Comment>> {

View file

@ -10,6 +10,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Console { pub struct Console {
pub reflector_: Reflector pub reflector_: Reflector
} }

View file

@ -19,6 +19,7 @@ use servo_util::str::DOMString;
use std::cell::Cell; use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct CustomEvent { pub struct CustomEvent {
event: Event, event: Event,
detail: Traceable<Cell<Traceable<JSVal>>>, detail: Traceable<Cell<Traceable<JSVal>>>,

View file

@ -37,6 +37,7 @@ use native::task::NativeTaskBuilder;
use url::Url; use url::Url;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct DedicatedWorkerGlobalScope { pub struct DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope, workerglobalscope: WorkerGlobalScope,
receiver: Untraceable<Receiver<ScriptMsg>>, receiver: Untraceable<Receiver<ScriptMsg>>,

View file

@ -19,6 +19,7 @@ use dom::nodelist::NodeList;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct DocumentFragment { pub struct DocumentFragment {
pub node: Node, pub node: Node,
} }
@ -38,8 +39,8 @@ impl DocumentFragment {
} }
pub fn new(document: &JSRef<Document>) -> Temporary<DocumentFragment> { pub fn new(document: &JSRef<Document>) -> Temporary<DocumentFragment> {
let node = DocumentFragment::new_inherited(document); Node::reflect_node(box DocumentFragment::new_inherited(document),
Node::reflect_node(box node, document, DocumentFragmentBinding::Wrap) document, DocumentFragmentBinding::Wrap)
} }
pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<DocumentFragment>> { pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<DocumentFragment>> {

View file

@ -14,6 +14,7 @@ use servo_util::str::DOMString;
/// The `DOCTYPE` tag. /// The `DOCTYPE` tag.
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct DocumentType { pub struct DocumentType {
pub node: Node, pub node: Node,
pub name: DOMString, pub name: DOMString,
@ -40,7 +41,7 @@ impl DocumentType {
system_id: system_id.unwrap_or("".to_string()) system_id: system_id.unwrap_or("".to_string())
} }
} }
#[allow(unrooted_must_root)]
pub fn new(name: DOMString, pub fn new(name: DOMString,
public_id: Option<DOMString>, public_id: Option<DOMString>,
system_id: Option<DOMString>, system_id: Option<DOMString>,

View file

@ -60,6 +60,7 @@ impl DOMErrorName {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct DOMException { pub struct DOMException {
pub code: DOMErrorName, pub code: DOMErrorName,
pub reflector_: Reflector pub reflector_: Reflector

View file

@ -11,6 +11,7 @@ use dom::window::Window;
use servo_util::geometry::Au; use servo_util::geometry::Au;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct DOMRect { pub struct DOMRect {
reflector_: Reflector, reflector_: Reflector,
top: f32, top: f32,
@ -34,8 +35,8 @@ impl DOMRect {
pub fn new(window: &JSRef<Window>, pub fn new(window: &JSRef<Window>,
top: Au, bottom: Au, top: Au, bottom: Au,
left: Au, right: Au) -> Temporary<DOMRect> { left: Au, right: Au) -> Temporary<DOMRect> {
let rect = DOMRect::new_inherited(top, bottom, left, right); reflect_dom_object(box DOMRect::new_inherited(top, bottom, left, right),
reflect_dom_object(box rect, &Window(*window), DOMRectBinding::Wrap) &Window(*window), DOMRectBinding::Wrap)
} }
} }

View file

@ -42,6 +42,7 @@ use std::cell::{Cell, RefCell};
use std::mem; use std::mem;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Element { pub struct Element {
pub node: Node, pub node: Node,
pub local_name: Atom, pub local_name: Atom,
@ -160,8 +161,8 @@ impl Element {
} }
pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JSRef<Document>) -> Temporary<Element> { pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JSRef<Document>) -> Temporary<Element> {
let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document); Node::reflect_node(box Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document),
Node::reflect_node(box element, document, ElementBinding::Wrap) document, ElementBinding::Wrap)
} }
} }
@ -173,6 +174,7 @@ pub trait RawLayoutElementHelpers {
impl RawLayoutElementHelpers for Element { impl RawLayoutElementHelpers for Element {
#[inline] #[inline]
#[allow(unrooted_must_root)]
unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str)
-> Option<&'static str> { -> Option<&'static str> {
// cast to point to T in RefCell<T> directly // cast to point to T in RefCell<T> directly
@ -188,6 +190,7 @@ impl RawLayoutElementHelpers for Element {
} }
#[inline] #[inline]
#[allow(unrooted_must_root)]
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str)
-> Option<Atom> { -> Option<Atom> {
// cast to point to T in RefCell<T> directly // cast to point to T in RefCell<T> directly
@ -203,6 +206,7 @@ impl RawLayoutElementHelpers for Element {
} }
#[inline] #[inline]
#[allow(unrooted_must_root)]
unsafe fn has_class_for_layout(&self, name: &str) -> bool { unsafe fn has_class_for_layout(&self, name: &str) -> bool {
let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs);
(*attrs).iter().find(|attr: & &JS<Attr>| { (*attrs).iter().find(|attr: & &JS<Attr>| {

View file

@ -35,6 +35,7 @@ pub enum EventTypeId {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Event { pub struct Event {
pub type_id: EventTypeId, pub type_id: EventTypeId,
reflector_: Reflector, reflector_: Reflector,

View file

@ -62,6 +62,7 @@ pub struct EventListenerEntry {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct EventTarget { pub struct EventTarget {
pub type_id: EventTargetTypeId, pub type_id: EventTargetTypeId,
reflector_: Reflector, reflector_: Reflector,

View file

@ -11,6 +11,7 @@ use dom::blob::{Blob, BlobType, FileTypeId};
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct File { pub struct File {
pub blob: Blob, pub blob: Blob,
pub name: DOMString, pub name: DOMString,

View file

@ -22,6 +22,7 @@ use servo_util::namespace;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[allow(unrooted_must_root)]
pub struct HTMLElement { pub struct HTMLElement {
pub element: Element pub element: Element
} }

View file

@ -15,6 +15,7 @@ use servo_util::str::DOMString;
use std::rc::Rc; use std::rc::Rc;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Location { pub struct Location {
reflector_: Reflector, //XXXjdm cycle: window->Location->window reflector_: Reflector, //XXXjdm cycle: window->Location->window
page: Rc<Page>, page: Rc<Page>,

View file

@ -20,6 +20,7 @@ use js::jsapi::JSContext;
use js::jsval::JSVal; use js::jsval::JSVal;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct MessageEvent { pub struct MessageEvent {
event: Event, event: Event,
data: Traceable<JSVal>, data: Traceable<JSVal>,

View file

@ -19,6 +19,7 @@ use servo_util::str::DOMString;
use std::cell::Cell; use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct MouseEvent { pub struct MouseEvent {
pub mouseevent: UIEvent, pub mouseevent: UIEvent,
pub screen_x: Traceable<Cell<i32>>, pub screen_x: Traceable<Cell<i32>>,

View file

@ -11,6 +11,7 @@ use dom::window::Window;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Navigator { pub struct Navigator {
pub reflector_: Reflector //XXXjdm cycle: window->navigator->window pub reflector_: Reflector //XXXjdm cycle: window->navigator->window
} }

View file

@ -68,6 +68,7 @@ use serialize::{Encoder, Encodable};
/// An HTML node. /// An HTML node.
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Node { pub struct Node {
/// The JavaScript reflector for this node. /// The JavaScript reflector for this node.
pub eventtarget: EventTarget, pub eventtarget: EventTarget,

View file

@ -9,6 +9,7 @@ use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct NodeIterator { pub struct NodeIterator {
pub reflector_: Reflector pub reflector_: Reflector
} }

View file

@ -25,7 +25,6 @@ pub struct NodeList {
} }
impl NodeList { impl NodeList {
#[allow(unrooted_must_root)]
pub fn new_inherited(list_type: NodeListType) -> NodeList { pub fn new_inherited(list_type: NodeListType) -> NodeList {
NodeList { NodeList {
list_type: list_type, list_type: list_type,
@ -33,7 +32,6 @@ impl NodeList {
} }
} }
#[allow(unrooted_must_root)]
pub fn new(window: &JSRef<Window>, pub fn new(window: &JSRef<Window>,
list_type: NodeListType) -> Temporary<NodeList> { list_type: NodeListType) -> Temporary<NodeList> {
reflect_dom_object(box NodeList::new_inherited(list_type), reflect_dom_object(box NodeList::new_inherited(list_type),

View file

@ -10,6 +10,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct PerformanceTiming { pub struct PerformanceTiming {
reflector_: Reflector, reflector_: Reflector,
navigationStart: u64, navigationStart: u64,
@ -26,6 +27,7 @@ impl PerformanceTiming {
} }
} }
#[allow(unrooted_must_root)]
pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> { pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(window.navigationStart, let timing = PerformanceTiming::new_inherited(window.navigationStart,
window.navigationStartPrecise); window.navigationStartPrecise);

View file

@ -15,6 +15,7 @@ use servo_util::str::DOMString;
/// An HTML processing instruction node. /// An HTML processing instruction node.
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct ProcessingInstruction { pub struct ProcessingInstruction {
pub characterdata: CharacterData, pub characterdata: CharacterData,
pub target: DOMString, pub target: DOMString,

View file

@ -14,6 +14,7 @@ use dom::event::{Event, ProgressEventTypeId};
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct ProgressEvent { pub struct ProgressEvent {
event: Event, event: Event,
length_computable: bool, length_computable: bool,

View file

@ -12,6 +12,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::document::Document; use dom::document::Document;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Range { pub struct Range {
reflector_: Reflector reflector_: Reflector
} }

View file

@ -10,6 +10,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Screen { pub struct Screen {
reflector_: Reflector, reflector_: Reflector,
} }

View file

@ -17,6 +17,7 @@ use servo_util::str::DOMString;
/// An HTML text node. /// An HTML text node.
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Text { pub struct Text {
pub characterdata: CharacterData, pub characterdata: CharacterData,
} }

View file

@ -9,6 +9,7 @@ use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct TreeWalker { pub struct TreeWalker {
pub reflector_: Reflector pub reflector_: Reflector
} }

View file

@ -18,6 +18,7 @@ use servo_util::str::DOMString;
use std::cell::Cell; use std::cell::Cell;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct UIEvent { pub struct UIEvent {
pub event: Event, pub event: Event,
view: Cell<Option<JS<Window>>>, view: Cell<Option<JS<Window>>>,

View file

@ -22,6 +22,7 @@ use std::fmt::radix;
use std::ascii::OwnedStrAsciiExt; use std::ascii::OwnedStrAsciiExt;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct URLSearchParams { pub struct URLSearchParams {
data: Traceable<RefCell<HashMap<DOMString, Vec<DOMString>>>>, data: Traceable<RefCell<HashMap<DOMString, Vec<DOMString>>>>,
reflector_: Reflector, reflector_: Reflector,

View file

@ -9,6 +9,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window; use dom::window::Window;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct ValidityState { pub struct ValidityState {
reflector_: Reflector, reflector_: Reflector,
state: u8, state: u8,

View file

@ -73,6 +73,7 @@ impl TimerHandle {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct Window { pub struct Window {
eventtarget: EventTarget, eventtarget: EventTarget,
pub script_chan: ScriptChan, pub script_chan: ScriptChan,

View file

@ -30,6 +30,7 @@ pub enum WorkerGlobalScopeId {
} }
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct WorkerGlobalScope { pub struct WorkerGlobalScope {
pub eventtarget: EventTarget, pub eventtarget: EventTarget,
worker_url: Untraceable<Url>, worker_url: Untraceable<Url>,

View file

@ -15,6 +15,7 @@ use servo_util::str::DOMString;
use url::Url; use url::Url;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct WorkerLocation { pub struct WorkerLocation {
reflector_: Reflector, reflector_: Reflector,
url: Untraceable<Url>, url: Untraceable<Url>,

View file

@ -11,6 +11,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct WorkerNavigator { pub struct WorkerNavigator {
reflector_: Reflector, reflector_: Reflector,
} }

View file

@ -12,6 +12,7 @@ use dom::eventtarget::{EventTarget, EventTargetHelpers, XMLHttpRequestTargetType
use dom::xmlhttprequest::XMLHttpRequestId; use dom::xmlhttprequest::XMLHttpRequestId;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct XMLHttpRequestEventTarget { pub struct XMLHttpRequestEventTarget {
pub eventtarget: EventTarget, pub eventtarget: EventTarget,
} }

View file

@ -12,6 +12,7 @@ use dom::xmlhttprequest::{XMLHttpRequestUploadTypeId};
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
#[deriving(Encodable)] #[deriving(Encodable)]
#[must_root]
pub struct XMLHttpRequestUpload { pub struct XMLHttpRequestUpload {
eventtarget: XMLHttpRequestEventTarget eventtarget: XMLHttpRequestEventTarget
} }