Skip to content

Commit

Permalink
Make DOMParser::ParseFromString actually parse the string
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisParis committed Dec 13, 2014
1 parent 40c706b commit e0c5981
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions components/script/dom/domparser.rs
Expand Up @@ -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};
Expand All @@ -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]
Expand Down Expand Up @@ -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))
}
_ => {
Expand Down

5 comments on commit e0c5981

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Ms2ger
at ChrisParis@e0c5981

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ChrisParis/servo/parse = e0c5981 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChrisParis/servo/parse = e0c5981 merged ok, testing candidate = 1be7d7c

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1be7d7c

Please sign in to comment.