@@ -35,7 +35,7 @@ pub struct ReadableStreamDefaultController {
35
35
/// All algoritems packed together:
36
36
/// - Close algorithm: A promise-returning algorithm, taking one argument (the cancel reason), which communicates a requested cancelation to the underlying source
37
37
/// - Pull algorithm: A promise-returning algorithm that pulls data from the underlying source
38
- algorithms : ControllerAlgorithms ,
38
+ algorithms : DomRefCell < Option < ControllerAlgorithms > > ,
39
39
/// A boolean flag indicating whether the stream has been closed by its underlying source, but still has chunks in its internal queue that have not yet been read
40
40
close_requested : Cell < bool > ,
41
41
/// A boolean flag set to true if the stream’s mechanisms requested a call to the underlying source's pull algorithm to pull more data, but the pull could not yet be done since a previous call is still executing
@@ -53,17 +53,13 @@ pub struct ReadableStreamDefaultController {
53
53
///
54
54
/// If missing use default value (1) per https://streams.spec.whatwg.org/#make-size-algorithm-from-size-function
55
55
#[ ignore_malloc_size_of = "Rc is hard" ]
56
- strategy_size_algorithm : Rc < QueuingStrategySize > ,
56
+ strategy_size_algorithm : DomRefCell < Option < Rc < QueuingStrategySize > > > ,
57
57
/// The ReadableStream instance controlled
58
58
stream : DomRoot < ReadableStream > ,
59
59
}
60
60
61
61
impl ReadableStreamDefaultController {
62
- fn new_inherited (
63
- algorithms : ControllerAlgorithms ,
64
- size : Rc < QueuingStrategySize > ,
65
- stream : DomRoot < ReadableStream > ,
66
- ) -> Self {
62
+ fn new_inherited ( stream : DomRoot < ReadableStream > ) -> Self {
67
63
Self {
68
64
reflector_ : Reflector :: new ( ) ,
69
65
queue : Default :: default ( ) ,
@@ -72,22 +68,14 @@ impl ReadableStreamDefaultController {
72
68
pulling : Cell :: new ( false ) ,
73
69
started : Cell :: new ( false ) ,
74
70
strategy_highwatermark : Cell :: new ( 0. ) ,
75
- algorithms,
76
- strategy_size_algorithm : size ,
71
+ algorithms : DomRefCell :: new ( None ) ,
72
+ strategy_size_algorithm : DomRefCell :: new ( None ) ,
77
73
stream,
78
74
}
79
75
}
80
76
81
- fn new (
82
- global : & GlobalScope ,
83
- algorithms : ControllerAlgorithms ,
84
- size : Rc < QueuingStrategySize > ,
85
- stream : DomRoot < ReadableStream > ,
86
- ) -> DomRoot < Self > {
87
- reflect_dom_object (
88
- Box :: new ( Self :: new_inherited ( algorithms, size, stream) ) ,
89
- global,
90
- )
77
+ fn new ( global : & GlobalScope , stream : DomRoot < ReadableStream > ) -> DomRoot < Self > {
78
+ reflect_dom_object ( Box :: new ( Self :: new_inherited ( stream) ) , global)
91
79
}
92
80
93
81
/// <https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed>
@@ -175,23 +163,25 @@ pub fn setup_readable_stream_default_controller_from_underlying_source(
175
163
let algorithms = UnderlyingSourceAlgorithms :: new ( underlying_source_dict, underlying_source_obj) ;
176
164
177
165
// Step 1
178
- let controller = ReadableStreamDefaultController :: new (
179
- & * stream. global ( ) ,
180
- ControllerAlgorithms :: UnderlyingSource ( algorithms) ,
181
- size_algorithm,
182
- stream,
183
- ) ;
166
+ let controller = ReadableStreamDefaultController :: new ( & * stream. global ( ) , stream) ;
184
167
185
168
// Step 8
186
- set_up_readable_stream_default_controller ( cx, controller, highwatermark)
169
+ set_up_readable_stream_default_controller (
170
+ cx,
171
+ controller,
172
+ ControllerAlgorithms :: UnderlyingSource ( algorithms) ,
173
+ highwatermark,
174
+ size_algorithm,
175
+ )
187
176
}
188
177
189
178
/// <https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller>
190
179
fn set_up_readable_stream_default_controller (
191
180
cx : SafeJSContext ,
192
- // stream: DomRoot<ReadableStream>,
193
181
mut controller : DomRoot < ReadableStreamDefaultController > ,
182
+ algorithms : ControllerAlgorithms ,
194
183
highwatermark : f64 ,
184
+ size_algorithm : Rc < QueuingStrategySize > ,
195
185
) -> Fallible < ( ) > {
196
186
// Step 1
197
187
assert ! ( controller. stream. controller( ) . is_none( ) ) ;
@@ -204,9 +194,11 @@ fn set_up_readable_stream_default_controller(
204
194
controller. pull_again . set ( false ) ;
205
195
controller. pulling . set ( false ) ;
206
196
// Step 5
207
- // Note sizeAlgorithm is set in ReadableStreamDefaultController::new already.
197
+ * controller . strategy_size_algorithm . borrow_mut ( ) = Some ( size_algorithm ) ;
208
198
controller. strategy_highwatermark . set ( highwatermark) ;
209
- // Step 6 & 7 are done in ReadableStreamDefaultController::new already.
199
+ // Step 6 & 7
200
+ * controller. algorithms . borrow_mut ( ) = Some ( algorithms) ;
201
+ //
210
202
// Step 8
211
203
controller
212
204
. stream
@@ -215,7 +207,7 @@ fn set_up_readable_stream_default_controller(
215
207
) ) ;
216
208
// Step 9
217
209
rooted ! ( in( * cx) let mut start_result = UndefinedValue ( ) ) ;
218
- controller. algorithms . start (
210
+ controller. algorithms . borrow ( ) . as_ref ( ) . unwrap ( ) . start (
219
211
cx,
220
212
ReadableStreamController :: ReadableStreamDefaultController ( controller. clone ( ) ) ,
221
213
start_result. handle_mut ( ) ,
0 commit comments