Skip to content
Permalink
Browse files

Auto merge of #23044 - georgeroman:implement_xmlserializer, r=jdm

Implement XMLSerializer interface

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix  #22997

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23044)
<!-- Reviewable:end -->
  • Loading branch information...
bors-servo committed Mar 21, 2019
2 parents e2406d3 + c6433ef commit 4e0b4833186c49c5cd5ca76df324cc365ccb49a9
@@ -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;
@@ -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);
};
@@ -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 @@
"XMLHttpRequest",
"XMLHttpRequestEventTarget",
"XMLHttpRequestUpload",
"XMLSerializer",
"console",
]);
</script>

1 comment on commit 4e0b483

@taskcluster

This comment has been minimized.

Copy link

commented on 4e0b483 Mar 21, 2019

Submitting the task to Taskcluster failed. Details

InterpreterError at template.tasks[0]: object keys must be strings

Please sign in to comment.
You can’t perform that action at this time.