diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-12-13 12:30:45 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-12-13 12:30:45 -0700 |
commit | 1be7d7ccedec170016243bc5924239ef02b0b76f (patch) | |
tree | 417b9c031e8ab7eb50e63c4f233ac0668e9e824d /components/script | |
parent | 98920b1315e7b867b293a56f5eb81784845f4a19 (diff) | |
parent | e0c59818d216d917364f48523ccaf88e258387be (diff) | |
download | servo-1be7d7ccedec170016243bc5924239ef02b0b76f.tar.gz servo-1be7d7ccedec170016243bc5924239ef02b0b76f.zip |
auto merge of #4297 : ChrisParis/servo/parse, r=Ms2ger
Addresses https://github.com/servo/servo/issues/3756. I've tested this code with a new test that I've submitted to https://github.com/w3c/web-platform-tests.
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/domparser.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 663bb239596..fe543162da8 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -2,6 +2,7 @@ * 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 dom::bindings::codegen::Bindings::DocumentBinding::DocumentReadyStateValues; use dom::bindings::codegen::Bindings::DOMParserBinding; use dom::bindings::codegen::Bindings::DOMParserBinding::DOMParserMethods; use dom::bindings::codegen::Bindings::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; @@ -10,8 +11,11 @@ use dom::bindings::global::GlobalRef; use dom::bindings::global; use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; -use dom::document::{Document, HTMLDocument, NonHTMLDocument, NotFromParser}; +use dom::document::{Document, DocumentHelpers, HTMLDocument, NonHTMLDocument}; +use dom::document::{FromParser, NotFromParser}; +use dom::servohtmlparser::ServoHTMLParser; use dom::window::Window; +use parse::Parser; use servo_util::str::DOMString; #[dom_struct] @@ -39,19 +43,27 @@ impl DOMParser { } impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { + // http://domparsing.spec.whatwg.org/#the-domparser-interface fn ParseFromString(self, - _s: DOMString, + s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible<Temporary<Document>> { - let window = self.window.root(); - //FIXME: these should probably be FromParser when we actually parse the string (#3756). + let window = self.window.root().clone(); + let url = Some(window.get_url()); + let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as uint].to_string(); match ty { Text_html => { - Ok(Document::new(*window, None, HTMLDocument, Some("text/html".to_string()), - NotFromParser)) + let document = Document::new(window, url.clone(), HTMLDocument, + Some(content_type), FromParser).root().clone(); + let parser = ServoHTMLParser::new(url.clone(), document).root().clone(); + parser.parse_chunk(s); + parser.finish(); + document.set_ready_state(DocumentReadyStateValues::Complete); + Ok(Temporary::from_rooted(document)) } Text_xml => { - Ok(Document::new(*window, None, NonHTMLDocument, Some("text/xml".to_string()), + //FIXME: this should probably be FromParser when we actually parse the string (#3756). + Ok(Document::new(window, url.clone(), NonHTMLDocument, Some(content_type), NotFromParser)) } _ => { |