Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the parsers into a single interface #13675

Merged
merged 9 commits into from Oct 11, 2016

Introduce ServoParser::pipeline

  • Loading branch information
nox committed Oct 11, 2016
commit 1f23810a341612e5293e37829f68c72491dafb04
@@ -53,9 +53,6 @@ pub struct ServoHTMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
}

impl<'a> Parser for &'a ServoHTMLParser {
@@ -76,7 +73,7 @@ impl<'a> Parser for &'a ServoHTMLParser {

self.upcast().document().set_current_parser(None);

if let Some(pipeline) = self.pipeline {
if let Some(pipeline) = self.upcast().pipeline() {
ScriptThread::parsing_complete(pipeline);
}
}
@@ -99,10 +96,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, Default::default());

let parser = ServoHTMLParser {
servoparser: ServoParser::new_inherited(document, false),
servoparser: ServoParser::new_inherited(document, pipeline, false),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
pipeline: pipeline,
};

reflect_dom_object(box parser, document.window(), ServoHTMLParserBinding::Wrap)
@@ -132,10 +128,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, tok_opts);

let parser = ServoHTMLParser {
servoparser: ServoParser::new_inherited(document, true),
servoparser: ServoParser::new_inherited(document, None, true),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
pipeline: None,
};

reflect_dom_object(box parser, document.window(), ServoHTMLParserBinding::Wrap)
@@ -6,24 +6,33 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::reflector::Reflector;
use dom::bindings::js::JS;
use dom::document::Document;
use msg::constellation_msg::PipelineId;
use std::cell::Cell;

#[dom_struct]
pub struct ServoParser {
reflector: Reflector,
/// The document associated with this parser.
document: JS<Document>,
/// The pipeline associated with this parse, unavailable if this parse
/// does not correspond to a page load.
pipeline: Option<PipelineId>,
/// Input chunks received but not yet passed to the parser.
pending_input: DOMRefCell<Vec<String>>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
}

impl ServoParser {
pub fn new_inherited(document: &Document, last_chunk_received: bool) -> Self {
pub fn new_inherited(
document: &Document,
pipeline: Option<PipelineId>,
last_chunk_received: bool)
-> Self {
ServoParser {
reflector: Reflector::new(),
document: JS::from_ref(document),
pipeline: pipeline,
pending_input: DOMRefCell::new(vec![]),
last_chunk_received: Cell::new(last_chunk_received),
}
@@ -33,6 +42,10 @@ impl ServoParser {
&self.document
}

pub fn pipeline(&self) -> Option<PipelineId> {
self.pipeline
}

pub fn has_pending_input(&self) -> bool {
!self.pending_input.borrow().is_empty()
}
@@ -38,9 +38,6 @@ pub struct ServoXMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
}

impl<'a> Parser for &'a ServoXMLParser {
@@ -61,7 +58,7 @@ impl<'a> Parser for &'a ServoXMLParser {

self.upcast().document().set_current_parser(None);

if let Some(pipeline) = self.pipeline {
if let Some(pipeline) = self.upcast().pipeline() {
ScriptThread::parsing_complete(pipeline);
}
}
@@ -81,10 +78,9 @@ impl ServoXMLParser {
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());

let parser = ServoXMLParser {
servoparser: ServoParser::new_inherited(document, false),
servoparser: ServoParser::new_inherited(document, pipeline, false),
tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
pipeline: pipeline,
};

reflect_dom_object(box parser, document.window(), ServoXMLParserBinding::Wrap)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.