mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
This is mostly stolen from Gecko. As there, we define the unforgeable members on an object stored in the slots of the prototype object. They are then copied onto instance objects when they are instantiated. It should be noted that proxy objects see their unforgeable memebers defined on their expando object. Unforgeable attributes aren't properly inherited in codegen (in a similar fashion as getters and setters as filed in #5875) and require to be redefined in derived interfaces. Fortunately, there are currently no such interfaces. No unforgeable members can be included into the TestBinding interfaces for good measure because they are not compatible with setters. Given the unforgeable holder object has the same prototype as actual instances of the interface, the finalize hook needs to check its slot pointer for nullity before dropping it. The new failing test isn't related to Unforgeable attributes, but to the fact that all Document instances currently have a Location, even if their window isn't in a browsing context.
103 lines
3.9 KiB
Rust
103 lines
3.9 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 document_loader::DocumentLoader;
|
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
|
use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods};
|
|
use dom::bindings::error::Fallible;
|
|
use dom::bindings::global::GlobalRef;
|
|
use dom::bindings::inheritance::Castable;
|
|
use dom::bindings::js::{Root, RootedReference};
|
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
|
use dom::document::{Document, DocumentSource, IsHTMLDocument};
|
|
use dom::location::Location;
|
|
use dom::node::Node;
|
|
use dom::window::Window;
|
|
use js::jsapi::{JSContext, JSObject};
|
|
use url::Url;
|
|
use util::str::DOMString;
|
|
|
|
// https://dom.spec.whatwg.org/#xmldocument
|
|
#[dom_struct]
|
|
pub struct XMLDocument {
|
|
document: Document,
|
|
}
|
|
|
|
impl XMLDocument {
|
|
fn new_inherited(window: &Window,
|
|
url: Option<Url>,
|
|
is_html_document: IsHTMLDocument,
|
|
content_type: Option<DOMString>,
|
|
last_modified: Option<String>,
|
|
source: DocumentSource,
|
|
doc_loader: DocumentLoader) -> XMLDocument {
|
|
XMLDocument {
|
|
document: Document::new_inherited(window,
|
|
url,
|
|
is_html_document,
|
|
content_type,
|
|
last_modified,
|
|
source,
|
|
doc_loader),
|
|
}
|
|
}
|
|
|
|
pub fn new(window: &Window,
|
|
url: Option<Url>,
|
|
doctype: IsHTMLDocument,
|
|
content_type: Option<DOMString>,
|
|
last_modified: Option<String>,
|
|
source: DocumentSource,
|
|
doc_loader: DocumentLoader)
|
|
-> Root<XMLDocument> {
|
|
let doc = reflect_dom_object(
|
|
box XMLDocument::new_inherited(window,
|
|
url,
|
|
doctype,
|
|
content_type,
|
|
last_modified,
|
|
source,
|
|
doc_loader),
|
|
GlobalRef::Window(window),
|
|
XMLDocumentBinding::Wrap);
|
|
{
|
|
let node = doc.upcast::<Node>();
|
|
node.set_owner_doc(&doc.r().document);
|
|
}
|
|
doc
|
|
}
|
|
|
|
pub fn Constructor(global: GlobalRef) -> Fallible<Root<XMLDocument>> {
|
|
let win = global.as_window();
|
|
let doc = win.Document();
|
|
let doc = doc.r();
|
|
let docloader = DocumentLoader::new(&*doc.loader());
|
|
|
|
Ok(XMLDocument::new(win,
|
|
None,
|
|
IsHTMLDocument::NonHTMLDocument,
|
|
None,
|
|
None,
|
|
DocumentSource::NotFromParser,
|
|
docloader))
|
|
}
|
|
}
|
|
|
|
impl XMLDocumentMethods for XMLDocument {
|
|
// https://html.spec.whatwg.org/multipage/#dom-document-location
|
|
fn Location(&self) -> Root<Location> {
|
|
self.document.Location()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
|
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
|
self.document.SupportedPropertyNames()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
|
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) -> *mut JSObject {
|
|
self.document.NamedGetter(_cx, name, found)
|
|
}
|
|
}
|