Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/script/dom/bindings/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ impl<T: Reflectable> JS<T> {
}
}

impl<T: Reflectable> Deref for JS<T> {
type Target = T;

fn deref(&self) -> &T {
// We can only have &JS<T> from a rooted thing, so it's safe to deref
// it to &T.
unsafe { &**self.ptr }
}
}

impl<T: Reflectable> JSTraceable for JS<T> {
fn trace(&self, trc: *mut JSTracer) {
trace_reflector(trc, "", unsafe { (**self.ptr).reflector() });
Expand Down
17 changes: 8 additions & 9 deletions components/script/dom/browsercontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ impl BrowsingContext {
}
}

pub fn active_document(&self) -> Root<Document> {
self.history[self.active_index].document.root()
pub fn active_document(&self) -> &Document {
&*self.history[self.active_index].document
}

pub fn active_window(&self) -> Root<Window> {
let doc = self.active_document();
doc.r().window()
pub fn active_window(&self) -> &Window {
self.active_document().window()
}

pub fn frame_element(&self) -> Option<Root<Element>> {
self.frame_element.as_ref().map(JS::root)
pub fn frame_element(&self) -> Option<&Element> {
self.frame_element.as_ref().map(|element| &**element)
}

pub fn window_proxy(&self) -> *mut JSObject {
Expand All @@ -64,8 +63,8 @@ impl BrowsingContext {

#[allow(unsafe_code)]
pub fn create_window_proxy(&mut self) {
let win = self.active_window();
let win = win.r();
// We inline self.active_window() because we can't borrow *self here.
let win = self.history[self.active_index].document.window();

let WindowProxyHandler(handler) = win.windowproxy_handler();
assert!(!handler.is_null());
Expand Down
219 changes: 86 additions & 133 deletions components/script/dom/document.rs

Large diffs are not rendered by default.

21 changes: 8 additions & 13 deletions components/script/dom/domimplementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl DOMImplementation {
pub fn new(document: &Document) -> Root<DOMImplementation> {
let window = document.window();
reflect_dom_object(box DOMImplementation::new_inherited(document),
GlobalRef::Window(window.r()),
GlobalRef::Window(window),
DOMImplementationBinding::Wrap)
}
}
Expand All @@ -53,20 +53,17 @@ impl DOMImplementationMethods for DOMImplementation {
fn CreateDocumentType(&self, qualified_name: DOMString, pubid: DOMString, sysid: DOMString)
-> Fallible<Root<DocumentType>> {
try!(validate_qualified_name(&qualified_name));
let document = self.document.root();
Ok(DocumentType::new(qualified_name, Some(pubid), Some(sysid), document.r()))
Ok(DocumentType::new(qualified_name, Some(pubid), Some(sysid), &self.document))
}

// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
fn CreateDocument(&self, namespace: Option<DOMString>, qname: DOMString,
maybe_doctype: Option<&DocumentType>) -> Fallible<Root<Document>> {
let doc = self.document.root();
let doc = doc.r();
let win = doc.window();
let loader = DocumentLoader::new(&*doc.loader());
let win = self.document.window();
let loader = DocumentLoader::new(&self.document.loader());

// Step 1.
let doc = Document::new(win.r(), None, IsHTMLDocument::NonHTMLDocument,
let doc = Document::new(win, None, IsHTMLDocument::NonHTMLDocument,
None, None, DocumentSource::NotFromParser, loader);
// Step 2-3.
let maybe_elem = if qname.is_empty() {
Expand Down Expand Up @@ -108,13 +105,11 @@ impl DOMImplementationMethods for DOMImplementation {

// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
fn CreateHTMLDocument(&self, title: Option<DOMString>) -> Root<Document> {
let document = self.document.root();
let document = document.r();
let win = document.window();
let loader = DocumentLoader::new(&*document.loader());
let win = self.document.window();
let loader = DocumentLoader::new(&self.document.loader());

// Step 1-2.
let doc = Document::new(win.r(), None, IsHTMLDocument::HTMLDocument, None, None,
let doc = Document::new(win, None, IsHTMLDocument::HTMLDocument, None, None,
DocumentSource::NotFromParser, loader);

{
Expand Down
9 changes: 4 additions & 5 deletions components/script/dom/domparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ impl DOMParserMethods for DOMParser {
s: DOMString,
ty: DOMParserBinding::SupportedType)
-> Fallible<Root<Document>> {
let window = self.window.root();
let url = window.r().get_url();
let url = self.window.get_url();
let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as usize].to_owned();
let doc = window.r().Document();
let doc = self.window.Document();
let doc = doc.r();
let loader = DocumentLoader::new(&*doc.loader());
match ty {
Text_html => {
let document = Document::new(window.r(), Some(url.clone()),
let document = Document::new(&self.window, Some(url.clone()),
IsHTMLDocument::HTMLDocument,
Some(content_type),
None,
Expand All @@ -69,7 +68,7 @@ impl DOMParserMethods for DOMParser {
}
Text_xml => {
//FIXME: this should probably be FromParser when we actually parse the string (#3756).
Ok(Document::new(window.r(), Some(url.clone()),
Ok(Document::new(&self.window, Some(url.clone()),
IsHTMLDocument::NonHTMLDocument,
Some(content_type),
None,
Expand Down
9 changes: 3 additions & 6 deletions components/script/dom/domstringmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,17 @@ impl DOMStringMap {
impl DOMStringMapMethods for DOMStringMap {
// https://html.spec.whatwg.org/multipage/#dom-domstringmap-removeitem
fn NamedDeleter(&self, name: DOMString) {
let element = self.element.root();
element.r().delete_custom_attr(name)
self.element.delete_custom_attr(name)
}

// https://html.spec.whatwg.org/multipage/#dom-domstringmap-setitem
fn NamedSetter(&self, name: DOMString, value: DOMString) -> ErrorResult {
let element = self.element.root();
element.r().set_custom_attr(name, value)
self.element.set_custom_attr(name, value)
}

// https://html.spec.whatwg.org/multipage/#dom-domstringmap-nameditem
fn NamedGetter(&self, name: DOMString, found: &mut bool) -> DOMString {
let element = self.element.root();
match element.r().get_custom_attr(name) {
match self.element.get_custom_attr(name) {
Some(value) => {
*found = true;
value.clone()
Expand Down
22 changes: 9 additions & 13 deletions components/script/dom/domtokenlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ impl DOMTokenList {
}

fn attribute(&self) -> Option<Root<Attr>> {
let element = self.element.root();
element.r().get_attribute(&ns!(""), &self.local_name)
self.element.get_attribute(&ns!(""), &self.local_name)
}

fn check_token_exceptions(&self, token: &str) -> Fallible<Atom> {
Expand Down Expand Up @@ -87,51 +86,48 @@ impl DOMTokenListMethods for DOMTokenList {

// https://dom.spec.whatwg.org/#dom-domtokenlist-add
fn Add(&self, tokens: Vec<DOMString>) -> ErrorResult {
let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
for token in &tokens {
let token = try!(self.check_token_exceptions(&token));
if !atoms.iter().any(|atom| *atom == token) {
atoms.push(token);
}
}
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms);
self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(())
}

// https://dom.spec.whatwg.org/#dom-domtokenlist-remove
fn Remove(&self, tokens: Vec<DOMString>) -> ErrorResult {
let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
for token in &tokens {
let token = try!(self.check_token_exceptions(&token));
atoms.iter().position(|atom| *atom == token).map(|index| {
atoms.remove(index)
});
}
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms);
self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(())
}

// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
fn Toggle(&self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
let token = try!(self.check_token_exceptions(&token));
match atoms.iter().position(|atom| *atom == token) {
Some(index) => match force {
Some(true) => Ok(true),
_ => {
atoms.remove(index);
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms);
self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(false)
}
},
None => match force {
Some(false) => Ok(false),
_ => {
atoms.push(token);
element.r().set_atomic_tokenlist_attribute(&self.local_name, atoms);
self.element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
Ok(true)
}
}
Expand All @@ -140,7 +136,7 @@ impl DOMTokenListMethods for DOMTokenList {

// https://dom.spec.whatwg.org/#stringification-behavior
fn Stringifier(&self) -> DOMString {
let tokenlist = self.element.root().r().get_tokenlist_attribute(&self.local_name);
let tokenlist = self.element.get_tokenlist_attribute(&self.local_name);
str_join(&tokenlist, "\x20")
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ impl ElementMethods for Element {
node.owner_doc()
};
let window = doc.r().window();
NamedNodeMap::new(window.r(), self)
NamedNodeMap::new(window, self)
})
}

Expand Down
1 change: 0 additions & 1 deletion components/script/dom/htmlimageelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl HTMLImageElement {
let node = NodeCast::from_ref(self);
let document = node.owner_doc();
let window = document.r().window();
let window = window.r();
let image_cache = window.image_cache_task();
match value {
None => {
Expand Down
15 changes: 7 additions & 8 deletions components/script/dom/htmlinputelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static DEFAULT_INPUT_SIZE: u32 = 20;

impl HTMLInputElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
let chan = document.window().r().constellation_chan();
let chan = document.window().constellation_chan();
HTMLInputElement {
htmlelement:
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
Expand Down Expand Up @@ -758,17 +758,16 @@ impl Activatable for HTMLInputElement {
InputType::InputRadio => {
// We want to restore state only if the element had been changed in the first place
if cache.was_mutable {
let old_checked = cache.checked_radio.as_ref().map(|t| t.root());
let name = self.get_radio_group_name();
match old_checked {
Some(ref o) => {
match cache.checked_radio.as_ref().map(|t| &*t) {
Some(o) => {
// Avoiding iterating through the whole tree here, instead
// we can check if the conditions for radio group siblings apply
if name == o.r().get_radio_group_name() && // TODO should be compatibility caseless
self.form_owner() == o.r().form_owner() &&
if name == o.get_radio_group_name() && // TODO should be compatibility caseless
self.form_owner() == o.form_owner() &&
// TODO Both a and b are in the same home subtree
o.r().input_type.get() == InputType::InputRadio {
o.r().SetChecked(true);
o.input_type.get() == InputType::InputRadio {
o.SetChecked(true);
} else {
self.SetChecked(false);
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlscriptelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl HTMLScriptElement {
// Step 10.
let document_from_node_ref = document_from_node(self);
let document_from_node_ref = document_from_node_ref.r();
if self.parser_inserted.get() && self.parser_document.root().r() != document_from_node_ref {
if self.parser_inserted.get() && &*self.parser_document != document_from_node_ref {
return NextParserState::Continue;
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmltextareaelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl HTMLTextAreaElement {
fn new_inherited(localName: DOMString,
prefix: Option<DOMString>,
document: &Document) -> HTMLTextAreaElement {
let chan = document.window().r().constellation_chan();
let chan = document.window().constellation_chan();
HTMLTextAreaElement {
htmlelement:
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
Expand Down
19 changes: 8 additions & 11 deletions components/script/dom/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,31 @@ impl Location {
}

fn get_url(&self) -> Url {
self.window.root().get_url()
self.window.get_url()
}

fn set_url_component(&self, value: USVString,
setter: fn(&mut Url, USVString)) {
let window = self.window.root();
let mut url = window.get_url();
let mut url = self.window.get_url();
setter(&mut url, value);
window.load_url(url);
self.window.load_url(url);
}
}

impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-assign
fn Assign(&self, url: DOMString) {
let window = self.window.root();
// TODO: per spec, we should use the _API base URL_ specified by the
// _entry settings object_.
let base_url = window.get_url();
let base_url = self.window.get_url();
if let Ok(url) = UrlParser::new().base_url(&base_url).parse(&url) {
window.load_url(url);
self.window.load_url(url);
}
}

// https://html.spec.whatwg.org/multipage/#dom-location-reload
fn Reload(&self) {
self.window.root().load_url(self.get_url());
self.window.load_url(self.get_url());
}

// https://url.spec.whatwg.org/#dom-urlutils-hash
Expand Down Expand Up @@ -101,9 +99,8 @@ impl LocationMethods for Location {

// https://url.spec.whatwg.org/#dom-urlutils-href
fn SetHref(&self, value: USVString) -> ErrorResult {
let window = self.window.root();
if let Ok(url) = UrlParser::new().base_url(&window.get_url()).parse(&value.0) {
window.load_url(url);
if let Ok(url) = UrlParser::new().base_url(&self.window.get_url()).parse(&value.0) {
self.window.load_url(url);
};
Ok(())
}
Expand Down
Loading