gecko-dev/servo/src/components/script/dom/htmlsourceelement.rs
Josh Matthews 0c3a130356 servo: Merge #2101 - Implement a safe, mostly-sound rooting rooting strategy (from jdm:newroot_rebase); r=Ms2ger
As described in #1764, this strategy uses the following properties:
* DOM members are `JS<T>` types. These cannot be used with being explicitly rooted, but they are required for compiler-derived trace hooks.
* Methods that take DOM type arguments receive `&[mut] JSRef<T>`. These are rooted value references that are cloneable but cannot escape.
* Methods that return DOM values use `Unrooted<T>`. These are values that may or may not be rooted elsewhere, but callers must root them in order to interact with them in any way. One unsoundness hole exists - `Unrooted` values must be rooted ASAP, or there exists the danger that JSAPI calls could be made that could cause the underlying JS value to be GCed.
* All methods are implemented on `JSRef<T>`, enforcing the requirement that all DOM values are rooted for the duration of a method call (with a few exceptions for layout-related code, which cannot root values and therefore interacts with `JS<T>` and `&T` values - this is safe under the assumption that layout code interacts with DOM nodes that are in the tree, therefore rooted, and does not run concurrently with content code)

Source-Repo: https://github.com/servo/servo
Source-Revision: 731e66ff132e41cdc49bc5324c0e15be19c46ec2
2014-05-03 14:25:22 -04:00

76 lines
2.3 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/. */
use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLSourceElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId};
use servo_util::str::DOMString;
#[deriving(Encodable)]
pub struct HTMLSourceElement {
pub htmlelement: HTMLElement
}
impl HTMLSourceElementDerived for EventTarget {
fn is_htmlsourceelement(&self) -> bool {
match self.type_id {
NodeTargetTypeId(ElementNodeTypeId(HTMLSourceElementTypeId)) => true,
_ => false
}
}
}
impl HTMLSourceElement {
pub fn new_inherited(localName: DOMString, document: &JSRef<Document>) -> HTMLSourceElement {
HTMLSourceElement {
htmlelement: HTMLElement::new_inherited(HTMLSourceElementTypeId, localName, document)
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Temporary<HTMLSourceElement> {
let element = HTMLSourceElement::new_inherited(localName, document);
Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap)
}
}
pub trait HTMLSourceElementMethods {
fn Src(&self) -> DOMString;
fn SetSrc(&mut self, _src: DOMString) -> ErrorResult;
fn Type(&self) -> DOMString;
fn SetType(&mut self, _type: DOMString) -> ErrorResult;
fn Media(&self) -> DOMString;
fn SetMedia(&mut self, _media: DOMString) -> ErrorResult;
}
impl<'a> HTMLSourceElementMethods for JSRef<'a, HTMLSourceElement> {
fn Src(&self) -> DOMString {
~""
}
fn SetSrc(&mut self, _src: DOMString) -> ErrorResult {
Ok(())
}
fn Type(&self) -> DOMString {
~""
}
fn SetType(&mut self, _type: DOMString) -> ErrorResult {
Ok(())
}
fn Media(&self) -> DOMString {
~""
}
fn SetMedia(&mut self, _media: DOMString) -> ErrorResult {
Ok(())
}
}