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`.
#[allow(unrooted_must_root)]
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
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.
#[allow(raw_pointer_deriving)]
#[allow(raw_pointer_deriving, unrooted_must_root)]
#[deriving(PartialEq)]
#[must_root]
pub struct Reflector {
object: Cell<*mut JSObject>,
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,7 +25,6 @@ pub struct NodeList {
}
impl NodeList {
#[allow(unrooted_must_root)]
pub fn new_inherited(list_type: NodeListType) -> NodeList {
NodeList {
list_type: list_type,
@ -33,7 +32,6 @@ impl NodeList {
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &JSRef<Window>,
list_type: NodeListType) -> Temporary<NodeList> {
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;
#[deriving(Encodable)]
#[must_root]
pub struct PerformanceTiming {
reflector_: Reflector,
navigationStart: u64,
@ -26,6 +27,7 @@ impl PerformanceTiming {
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &JSRef<Window>) -> Temporary<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(window.navigationStart,
window.navigationStartPrecise);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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