/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
components/script/dom/xmldocument.rs
154 строки
5 KB
Narfinger
script: JSContextify document creation (#46089)
29 июн 2026, 18:55
Не верифицирован
29 июн 2026, 18:55
3a6566c
Код
Авторство
О чём код?
/* 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 https://mozilla.org/MPL/2.0/. */ use std::rc::Rc; use std::sync::Arc; use data_url::mime::Mime; use dom_struct::dom_struct; use js::context::{JSContext, NoGC}; use net_traits::image_cache::ImageCache; use net_traits::request::InsecureRequestsPolicy; use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; use script_bindings::reflector::reflect_dom_object_with_cx; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; use crate::document_loader::DocumentLoader; use crate::dom::animations::documenttimeline::DocumentTimeline; use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ DocumentMethods, NamedPropertyValue, }; use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::customelementregistry::CustomElementReactionStack; use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument}; use crate::dom::location::Location; use crate::dom::node::Node; use crate::dom::window::Window; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] pub(crate) struct XMLDocument { document: Document, } impl XMLDocument { #[expect(clippy::too_many_arguments)] 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, inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>, has_trustworthy_ancestor_origin: bool, custom_element_reaction_stack: Rc<CustomElementReactionStack>, timeline: &DocumentTimeline, image_cache: Arc<dyn ImageCache>, ) -> XMLDocument { XMLDocument { document: Document::new_inherited( window, has_browsing_context, url, None, origin, is_html_document, content_type, last_modified, activity, source, doc_loader, None, None, Default::default(), false, false, inherited_insecure_requests_policy, has_trustworthy_ancestor_origin, custom_element_reaction_stack, window.Document().creation_sandboxing_flag_set(), timeline, window.pipeline_id(), image_cache, ), } } #[expect(clippy::too_many_arguments)] pub(crate) fn new( cx: &mut JSContext, 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, inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>, has_trustworthy_ancestor_origin: bool, custom_element_reaction_stack: Rc<CustomElementReactionStack>, image_cache: Arc<dyn ImageCache>, ) -> DomRoot<XMLDocument> { let timeline = DocumentTimeline::new(cx, window); let doc = reflect_dom_object_with_cx( Box::new(XMLDocument::new_inherited( window, has_browsing_context, url, origin, doctype, content_type, last_modified, activity, source, doc_loader, inherited_insecure_requests_policy, has_trustworthy_ancestor_origin, custom_element_reaction_stack, &timeline, image_cache, )), window, cx, ); { let node = doc.upcast::<Node>(); node.set_owner_doc(&doc.document); } doc } } impl XMLDocumentMethods<crate::DomTypeHolder> for XMLDocument { /// <https://html.spec.whatwg.org/multipage/#dom-document-location> fn GetLocation(&self, cx: &mut JSContext) -> Option<DomRoot<Location>> { self.upcast::<Document>().GetLocation(cx) } /// <https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names> fn SupportedPropertyNames(&self, no_gc: &NoGC) -> Vec<DOMString> { self.upcast::<Document>().SupportedPropertyNames(no_gc) } /// <https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter> fn NamedGetter( &self, cx: &mut js::context::JSContext, name: DOMString, ) -> Option<NamedPropertyValue> { self.upcast::<Document>().NamedGetter(cx, name) } }