diff options
-rw-r--r-- | components/script/dom/servohtmlparser.rs | 25 | ||||
-rw-r--r-- | components/script/dom/servoparser.rs | 14 | ||||
-rw-r--r-- | components/script/dom/servoxmlparser.rs | 11 | ||||
-rw-r--r-- | components/script/parse/mod.rs | 8 |
4 files changed, 25 insertions, 33 deletions
diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index aa80d387dab..95f6004d225 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -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), 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 { diff --git a/components/script/dom/servoparser.rs b/components/script/dom/servoparser.rs index 1cdef6de642..c5611a6364d 100644 --- a/components/script/dom/servoparser.rs +++ b/components/script/dom/servoparser.rs @@ -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)) } } + + 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) + } } diff --git a/components/script/dom/servoxmlparser.rs b/components/script/dom/servoxmlparser.rs index dd107c8d3c4..4dc9b942b7b 100644 --- a/components/script/dom/servoxmlparser.rs +++ b/components/script/dom/servoxmlparser.rs @@ -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 } diff --git a/components/script/parse/mod.rs b/components/script/parse/mod.rs index 30f6bc158a6..ba05ec839d4 100644 --- a/components/script/parse/mod.rs +++ b/components/script/parse/mod.rs @@ -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(), - } - } } |