Move pending input logic to ServoParser

This commit is contained in:
Anthony Ramine 2016-10-08 15:48:47 +02:00
parent 27f245e6ae
commit e1a1bf46ca
4 changed files with 37 additions and 43 deletions

View file

@ -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::cell::DOMRefCell;
use dom::bindings::reflector::Reflector;
use dom::bindings::js::JS;
use dom::document::Document;
@ -11,6 +12,8 @@ pub struct ServoParser {
reflector: Reflector,
/// The document associated with this parser.
document: JS<Document>,
/// Input chunks received but not yet passed to the parser.
pending_input: DOMRefCell<Vec<String>>,
}
impl ServoParser {
@ -18,10 +21,28 @@ impl ServoParser {
ServoParser {
reflector: Reflector::new(),
document: JS::from_ref(document),
pending_input: DOMRefCell::new(vec![]),
}
}
pub fn document(&self) -> &Document {
&self.document
}
pub fn has_pending_input(&self) -> bool {
!self.pending_input.borrow().is_empty()
}
pub fn push_input_chunk(&self, chunk: String) {
self.pending_input.borrow_mut().push(chunk);
}
pub fn take_next_input_chunk(&self) -> Option<String> {
let mut pending_input = self.pending_input.borrow_mut();
if pending_input.is_empty() {
None
} else {
Some(pending_input.remove(0))
}
}
}