mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement XMLSerializer interface
This commit is contained in:
parent
e58226814f
commit
c6433efc1d
8 changed files with 76 additions and 67 deletions
|
@ -533,6 +533,7 @@ pub mod xmldocument;
|
|||
pub mod xmlhttprequest;
|
||||
pub mod xmlhttprequesteventtarget;
|
||||
pub mod xmlhttprequestupload;
|
||||
pub mod xmlserializer;
|
||||
pub mod xr;
|
||||
pub mod xrframe;
|
||||
pub mod xrlayer;
|
||||
|
|
13
components/script/dom/webidls/XMLSerializer.webidl
Normal file
13
components/script/dom/webidls/XMLSerializer.webidl
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* 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/. */
|
||||
/*
|
||||
* The origin of this IDL file is
|
||||
* https://w3c.github.io/DOM-Parsing/#the-domparser-interface
|
||||
*/
|
||||
|
||||
[Constructor]
|
||||
interface XMLSerializer {
|
||||
[Throws]
|
||||
DOMString serializeToString(Node root);
|
||||
};
|
60
components/script/dom/xmlserializer.rs
Normal file
60
components/script/dom/xmlserializer.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* 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 crate::dom::bindings::codegen::Bindings::XMLSerializerBinding;
|
||||
use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::node::Node;
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use xml5ever::serialize::{serialize, SerializeOpts, TraversalScope};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct XMLSerializer {
|
||||
reflector_: Reflector,
|
||||
window: Dom<Window>,
|
||||
}
|
||||
|
||||
impl XMLSerializer {
|
||||
fn new_inherited(window: &Window) -> XMLSerializer {
|
||||
XMLSerializer {
|
||||
reflector_: Reflector::new(),
|
||||
window: Dom::from_ref(window),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window) -> DomRoot<XMLSerializer> {
|
||||
reflect_dom_object(
|
||||
Box::new(XMLSerializer::new_inherited(window)),
|
||||
window,
|
||||
XMLSerializerBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn Constructor(window: &Window) -> Fallible<DomRoot<XMLSerializer>> {
|
||||
Ok(XMLSerializer::new(window))
|
||||
}
|
||||
}
|
||||
|
||||
impl XMLSerializerMethods for XMLSerializer {
|
||||
// https://w3c.github.io/DOM-Parsing/#the-xmlserializer-interface
|
||||
fn SerializeToString(&self, root: &Node) -> Fallible<DOMString> {
|
||||
let mut writer = vec![];
|
||||
match serialize(
|
||||
&mut writer,
|
||||
&root,
|
||||
SerializeOpts {
|
||||
traversal_scope: TraversalScope::IncludeNode,
|
||||
},
|
||||
) {
|
||||
Ok(_) => Ok(DOMString::from(String::from_utf8(writer).unwrap())),
|
||||
Err(_) => Err(Error::Type(String::from(
|
||||
"root must be a Node or an Attr object",
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,5 @@
|
|||
[XMLSerializer-serializeToString.html]
|
||||
type: testharness
|
||||
[check XMLSerializer.serializeToString method could parsing xmldoc to string]
|
||||
expected: FAIL
|
||||
|
||||
[check XMLSerializer.serializeToString method could parsing xmldoc to string]
|
||||
expected: FAIL
|
||||
|
||||
[Check if the default namespace is correctly reset.]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -5,39 +5,6 @@
|
|||
[interfaces]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: existence and properties of interface object]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface object name]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: existence and properties of interface prototype object's "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: existence and properties of interface prototype object's @@unscopables property]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: operation serializeToString(Node)]
|
||||
expected: FAIL
|
||||
|
||||
[Stringification of new XMLSerializer()]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: calling serializeToString(Node) on new XMLSerializer() with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer must be primary interface of new XMLSerializer()]
|
||||
expected: FAIL
|
||||
|
||||
[XMLSerializer interface: new XMLSerializer() must inherit property "serializeToString(Node)" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[ShadowRoot interface: attribute innerHTML]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,20 +1,5 @@
|
|||
[xml-serialization.xhtml]
|
||||
type: testharness
|
||||
[Comment: containing --]
|
||||
expected: FAIL
|
||||
|
||||
[Comment: starting with -]
|
||||
expected: FAIL
|
||||
|
||||
[Comment: ending with -]
|
||||
expected: FAIL
|
||||
|
||||
[Comment: containing -->]
|
||||
expected: FAIL
|
||||
|
||||
[DocumentType: empty public and system id]
|
||||
expected: FAIL
|
||||
|
||||
[DocumentType: empty system id]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -33,18 +18,6 @@
|
|||
[DocumentType: 'APOSTROPHE' (U+0027) and 'QUOTATION MARK' (U+0022)]
|
||||
expected: FAIL
|
||||
|
||||
[ProcessingInstruction: empty data]
|
||||
expected: FAIL
|
||||
|
||||
[ProcessingInstruction: non-empty data]
|
||||
expected: FAIL
|
||||
|
||||
[ProcessingInstruction: target contains xml]
|
||||
expected: FAIL
|
||||
|
||||
[ProcessingInstruction: target contains a 'COLON' (U+003A)]
|
||||
expected: FAIL
|
||||
|
||||
[Element: href attributes are not percent-encoded]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -20254,7 +20254,7 @@
|
|||
"testharness"
|
||||
],
|
||||
"mozilla/interfaces.html": [
|
||||
"f8d8ab879f84bf03f89b12d5d010c83c1025265a",
|
||||
"a2b9fd23948319fabc0b5fff550b9565704b6678",
|
||||
"testharness"
|
||||
],
|
||||
"mozilla/interfaces.js": [
|
||||
|
|
|
@ -246,6 +246,7 @@ test_interfaces([
|
|||
"XMLHttpRequest",
|
||||
"XMLHttpRequestEventTarget",
|
||||
"XMLHttpRequestUpload",
|
||||
"XMLSerializer",
|
||||
"console",
|
||||
]);
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue