@@ -11,19 +11,43 @@ use crate::encoding::{Confidence, Decoder};
11
11
/// Internally the `InputStream` keeps track of the current
12
12
/// [insertion point](https://html.spec.whatwg.org/#insertion-point) by using
13
13
/// 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.
14
24
pub struct InputStream {
25
+ insertion_point_stack : RefCell < Vec < BufferQueue > > ,
15
26
input : BufferQueue ,
16
27
decoder : RefCell < Decoder > ,
17
28
}
18
29
19
30
impl InputStream {
20
31
fn new ( encoding : & ' static Encoding ) -> Self {
21
32
Self {
33
+ insertion_point_stack : Default :: default ( ) ,
22
34
input : Default :: default ( ) ,
23
35
decoder : RefCell :: new ( Decoder :: new ( encoding, Confidence :: Tentative ) ) ,
24
36
}
25
37
}
26
38
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
+
27
51
pub fn append ( & self , data : StrTendril ) {
28
52
self . input . push_back ( data) ;
29
53
}
0 commit comments