Skip to content

Commit 6bd5a43

Browse files
committed
test write changes
1 parent 69c5821 commit 6bd5a43

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

markup5ever/input_stream.rs

+24
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,43 @@ use crate::encoding::{Confidence, Decoder};
1111
/// Internally the `InputStream` keeps track of the current
1212
/// [insertion point](https://html.spec.whatwg.org/#insertion-point) by using
1313
/// two seperate buffers.
14+
///
15+
/// ### Insertion Points
16+
/// When `document.write` is called, the following things need to happen:
17+
/// * The provided string must be inserted at the beginning of the input stream
18+
/// * The parser must be invoked, but must not consume more than the provded string
19+
///
20+
/// Of course the second step may uncover more calls to `document.write`, which need
21+
/// to be executed immediately.
22+
///
23+
/// This can be realized with the [push_insertion_point] and [pop_insertion_point] methods.
1424
pub struct InputStream {
25+
insertion_point_stack: RefCell<Vec<BufferQueue>>,
1526
input: BufferQueue,
1627
decoder: RefCell<Decoder>,
1728
}
1829

1930
impl InputStream {
2031
fn new(encoding: &'static Encoding) -> Self {
2132
Self {
33+
insertion_point_stack: Default::default(),
2234
input: Default::default(),
2335
decoder: RefCell::new(Decoder::new(encoding, Confidence::Tentative)),
2436
}
2537
}
2638

39+
pub fn push_insertion_point(&self) {
40+
self.insertion_point_stack.borrow_mut().push(BufferQueue::default());
41+
}
42+
43+
pub fn pop_insertion_point(&self) {
44+
let previous_insertion_area = self.insertion_point_stack.borrow_mut().pop().unwrap();
45+
46+
if !previous_insertion_area.is_empty() {
47+
// The parser for the input to document.write got suspended.
48+
}
49+
}
50+
2751
pub fn append(&self, data: StrTendril) {
2852
self.input.push_back(data);
2953
}

markup5ever/util/buffer_queue.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//!
1919
//! [`BufferQueue`]: struct.BufferQueue.html
2020
21-
use std::{cell::RefCell, collections::VecDeque, fmt, mem};
21+
use std::{cell::{RefCell, RefMut}, collections::VecDeque, fmt, mem};
2222

2323
use tendril::{
2424
fmt::{Bytes, SliceFormat, UTF8},
@@ -128,6 +128,14 @@ where
128128
pub fn clear(&self) {
129129
self.buffers.borrow_mut().clear();
130130
}
131+
132+
pub fn take(&self) -> Self {
133+
let buffers = mem::take(self.buffers.borrow_mut());
134+
135+
Self {
136+
buffers
137+
}
138+
}
131139
}
132140

133141
impl BufferQueue {

0 commit comments

Comments
 (0)