diff options
Diffstat (limited to 'components/script/dom/xmldocument.rs')
-rw-r--r-- | components/script/dom/xmldocument.rs | 131 |
1 files changed, 70 insertions, 61 deletions
diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 59c6739fb2d..f4908922ec3 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -1,23 +1,25 @@ /* 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/. */ + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use core::nonzero::NonZero; -use document_loader::DocumentLoader; -use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods}; -use dom::bindings::inheritance::Castable; -use dom::bindings::js::Root; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::str::DOMString; -use dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument}; -use dom::location::Location; -use dom::node::Node; -use dom::window::Window; +use crate::document_loader::DocumentLoader; +use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; +use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; +use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument}; +use crate::dom::location::Location; +use crate::dom::node::Node; +use crate::dom::window::Window; +use crate::script_runtime::JSContext; use dom_struct::dom_struct; -use js::jsapi::{JSContext, JSObject}; +use js::jsapi::JSObject; +use mime::Mime; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; +use std::ptr::NonNull; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] @@ -26,56 +28,64 @@ pub struct XMLDocument { } impl XMLDocument { - fn new_inherited(window: &Window, - has_browsing_context: HasBrowsingContext, - url: Option<ServoUrl>, - origin: MutableOrigin, - is_html_document: IsHTMLDocument, - content_type: Option<DOMString>, - last_modified: Option<String>, - activity: DocumentActivity, - source: DocumentSource, - doc_loader: DocumentLoader) -> XMLDocument { + fn new_inherited( + window: &Window, + has_browsing_context: HasBrowsingContext, + url: Option<ServoUrl>, + origin: MutableOrigin, + is_html_document: IsHTMLDocument, + content_type: Option<Mime>, + last_modified: Option<String>, + activity: DocumentActivity, + source: DocumentSource, + doc_loader: DocumentLoader, + ) -> XMLDocument { XMLDocument { - document: Document::new_inherited(window, - has_browsing_context, - url, - origin, - is_html_document, - content_type, - last_modified, - activity, - source, - doc_loader, - None, - None), + document: Document::new_inherited( + window, + has_browsing_context, + url, + origin, + is_html_document, + content_type, + last_modified, + activity, + source, + doc_loader, + None, + None, + Default::default(), + ), } } - pub fn new(window: &Window, - has_browsing_context: HasBrowsingContext, - url: Option<ServoUrl>, - origin: MutableOrigin, - doctype: IsHTMLDocument, - content_type: Option<DOMString>, - last_modified: Option<String>, - activity: DocumentActivity, - source: DocumentSource, - doc_loader: DocumentLoader) - -> Root<XMLDocument> { + pub fn new( + window: &Window, + has_browsing_context: HasBrowsingContext, + url: Option<ServoUrl>, + origin: MutableOrigin, + doctype: IsHTMLDocument, + content_type: Option<Mime>, + last_modified: Option<String>, + activity: DocumentActivity, + source: DocumentSource, + doc_loader: DocumentLoader, + ) -> DomRoot<XMLDocument> { let doc = reflect_dom_object( - box XMLDocument::new_inherited(window, - has_browsing_context, - url, - origin, - doctype, - content_type, - last_modified, - activity, - source, - doc_loader), + Box::new(XMLDocument::new_inherited( + window, + has_browsing_context, + url, + origin, + doctype, + content_type, + last_modified, + activity, + source, + doc_loader, + )), window, - XMLDocumentBinding::Wrap); + ); { let node = doc.upcast::<Node>(); node.set_owner_doc(&doc.document); @@ -86,7 +96,7 @@ impl XMLDocument { impl XMLDocumentMethods for XMLDocument { // https://html.spec.whatwg.org/multipage/#dom-document-location - fn GetLocation(&self) -> Option<Root<Location>> { + fn GetLocation(&self) -> Option<DomRoot<Location>> { self.upcast::<Document>().GetLocation() } @@ -95,9 +105,8 @@ impl XMLDocumentMethods for XMLDocument { self.upcast::<Document>().SupportedPropertyNames() } - #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> { + fn NamedGetter(&self, _cx: JSContext, name: DOMString) -> Option<NonNull<JSObject>> { self.upcast::<Document>().NamedGetter(_cx, name) } } |