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

Move last chunk received logic to ServoParser

  • Loading branch information
nox committed Oct 11, 2016
commit 881f7f4de7132cbe7f5aec17f535ff501112ac3c
@@ -200,12 +200,15 @@ impl AsyncResponseListener for ParserContext {
debug!("Failed to load page URL {}, error: {:?}", self.url, err);
}

parser.r().as_servo_parser().document()
let parser = parser.r();
let servo_parser = parser.as_servo_parser();

servo_parser.document()
.finish_load(LoadType::PageSource(self.url.clone()));

parser.r().last_chunk_received().set(true);
if !parser.r().is_suspended() {
parser.r().parse_sync();
servo_parser.mark_last_chunk_received();
if !parser.is_suspended() {
parser.parse_sync();
}
}
}
@@ -220,8 +223,6 @@ pub struct ServoHTMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
@@ -268,10 +269,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, Default::default());

let parser = ServoHTMLParser {
servoparser: ServoParser::new_inherited(document),
servoparser: ServoParser::new_inherited(document, false),

This comment has been minimized.

@Ms2ger

Ms2ger Oct 10, 2016

Contributor

The boolean last_chunk_received argument. I'd prefer an isomorphic enum.

tokenizer: DOMRefCell::new(tok),
suspended: Cell::new(false),
last_chunk_received: Cell::new(false),
pipeline: pipeline,
};

@@ -302,10 +302,9 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, tok_opts);

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

@@ -360,7 +359,7 @@ impl ServoHTMLParser {
}
}

if self.last_chunk_received.get() {
if self.upcast().last_chunk_received() {
self.finish();
}
}
@@ -383,10 +382,6 @@ impl ServoHTMLParser {
pub fn is_suspended(&self) -> bool {
self.suspended.get()
}

pub fn last_chunk_received(&self) -> &Cell<bool> {
&self.last_chunk_received
}
}

struct Tracer {
@@ -6,6 +6,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::reflector::Reflector;
use dom::bindings::js::JS;
use dom::document::Document;
use std::cell::Cell;

#[dom_struct]
pub struct ServoParser {
@@ -14,14 +15,17 @@ pub struct ServoParser {
document: JS<Document>,
/// 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) -> Self {
pub fn new_inherited(document: &Document, last_chunk_received: bool) -> Self {
ServoParser {
reflector: Reflector::new(),
document: JS::from_ref(document),
pending_input: DOMRefCell::new(vec![]),
last_chunk_received: Cell::new(last_chunk_received),
}
}

@@ -45,4 +49,12 @@ impl ServoParser {
Some(pending_input.remove(0))

This comment has been minimized.

@Ms2ger

Ms2ger Oct 10, 2016

Contributor

Followup: should use pop() (and probably a queue).

}
}

pub fn last_chunk_received(&self) -> bool {
self.last_chunk_received.get()
}

pub fn mark_last_chunk_received(&self) {
self.last_chunk_received.set(true)
}
}
@@ -38,8 +38,6 @@ pub struct ServoXMLParser {
tokenizer: DOMRefCell<Tokenizer>,
/// True if this parser should avoid passing any further data to the tokenizer.
suspended: Cell<bool>,
/// Whether to expect any further input from the associated network request.
last_chunk_received: Cell<bool>,
/// The pipeline associated with this parse, unavailable if this parse does not
/// correspond to a page load.
pipeline: Option<PipelineId>,
@@ -83,10 +81,9 @@ impl ServoXMLParser {
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());

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

@@ -133,7 +130,7 @@ impl ServoXMLParser {
}
}

if self.last_chunk_received.get() {
if self.upcast().last_chunk_received() {
self.finish();
}
}
@@ -146,10 +143,6 @@ impl ServoXMLParser {
self.tokenizer.borrow_mut().end()
}

pub fn last_chunk_received(&self) -> &Cell<bool> {
&self.last_chunk_received
}

pub fn tokenizer(&self) -> &DOMRefCell<Tokenizer> {
&self.tokenizer
}
@@ -9,7 +9,6 @@ use dom::servohtmlparser::ServoHTMLParser;
use dom::servoparser::ServoParser;
use dom::servoxmlparser::ServoXMLParser;
use dom::window::Window;
use std::cell::Cell;
use std::cell::UnsafeCell;
use std::ptr;

@@ -159,12 +158,5 @@ impl<'a> ParserRef<'a> {
ParserRef::XML(parser) => parser.parse_sync(),
}
}

pub fn last_chunk_received(&self) -> &Cell<bool> {
match *self {
ParserRef::HTML(parser) => parser.last_chunk_received(),
ParserRef::XML(parser) => parser.last_chunk_received(),
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.