@@ -72,6 +72,8 @@ pub(crate) enum TransformerType {
72
72
transform_obj : Heap < * mut JSObject > ,
73
73
} ,
74
74
/// Algorithms supporting `TextDecoderStream` are implemented in Rust
75
+ ///
76
+ /// <https://encoding.spec.whatwg.org/#textdecodercommon>
75
77
Decoder ( Rc < TextDecoderCommon > ) ,
76
78
}
77
79
@@ -143,6 +145,8 @@ impl TransformStreamDefaultController {
143
145
}
144
146
145
147
/// Setting the JS object after the heap has settled down.
148
+ ///
149
+ /// Note that this has no effect if the transformer type is not `TransformerType::Js`
146
150
pub ( crate ) fn set_transform_obj ( & self , this_object : SafeHandleObject ) {
147
151
if let TransformerType :: Js { transform_obj, .. } = & self . transformer_type {
148
152
transform_obj. set ( * this_object)
@@ -198,12 +202,13 @@ impl TransformStreamDefaultController {
198
202
can_gc : CanGc ,
199
203
) -> Fallible < Rc < Promise > > {
200
204
let result = match & self . transformer_type {
205
+ // <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
201
206
TransformerType :: Js {
202
207
transform,
203
208
transform_obj,
204
209
..
205
210
} => {
206
- // If transformerDict["transform"] exists, set
211
+ // Step 5. If transformerDict["transform"] exists, set
207
212
// transformAlgorithm to an algorithm which takes an argument
208
213
// chunk and returns the result of invoking
209
214
// transformerDict["transform"] with argument list « chunk,
@@ -225,7 +230,7 @@ impl TransformStreamDefaultController {
225
230
p
226
231
} )
227
232
} else {
228
- // Let transformAlgorithm be the following steps, taking a chunk argument:
233
+ // Step 2. Let transformAlgorithm be the following steps, taking a chunk argument:
229
234
// Let result be TransformStreamDefaultControllerEnqueue(controller, chunk).
230
235
// If result is an abrupt completion, return a promise rejected with result.[[Value]].
231
236
if let Err ( error) = self . enqueue ( cx, global, chunk, can_gc) {
@@ -238,9 +243,8 @@ impl TransformStreamDefaultController {
238
243
}
239
244
}
240
245
} ,
246
+ // <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
241
247
TransformerType :: Decoder ( decoder) => {
242
- // <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
243
- //
244
248
// Step 7. Let transformAlgorithm be an algorithm which takes a
245
249
// chunk argument and runs the decode and enqueue a chunk
246
250
// algorithm with this and chunk.
@@ -265,14 +269,17 @@ impl TransformStreamDefaultController {
265
269
can_gc : CanGc ,
266
270
) -> Fallible < Rc < Promise > > {
267
271
let result = match & self . transformer_type {
272
+ // <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
268
273
TransformerType :: Js {
269
274
cancel,
270
275
transform_obj,
271
276
..
272
277
} => {
273
- // If transformerDict["cancel"] exists, set cancelAlgorithm to an algorithm which takes an argument
274
- // reason and returns the result of invoking transformerDict["cancel"] with argument list « reason »
275
- // and callback this value transformer.
278
+ // Step 7. If transformerDict["cancel"] exists, set
279
+ // cancelAlgorithm to an algorithm which takes an argument
280
+ // reason and returns the result of invoking
281
+ // transformerDict["cancel"] with argument list « reason » and
282
+ // callback this value transformer.
276
283
let algo = cancel. borrow ( ) . clone ( ) ;
277
284
if let Some ( cancel) = algo {
278
285
rooted ! ( in( * cx) let this_object = transform_obj. get( ) ) ;
@@ -289,12 +296,13 @@ impl TransformStreamDefaultController {
289
296
p
290
297
} )
291
298
} else {
292
- // Let cancelAlgorithm be an algorithm which returns a promise resolved with undefined.
299
+ // Step 4. Let cancelAlgorithm be an algorithm which returns a promise resolved with undefined.
293
300
Promise :: new_resolved ( global, cx, ( ) , can_gc)
294
301
}
295
302
} ,
303
+ // <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
296
304
TransformerType :: Decoder ( _) => {
297
- // <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
305
+ // `TextDecoderStream` does NOT specify a cancel algorithm.
298
306
//
299
307
// Step 4. Let cancelAlgorithm be an algorithm which returns a promise resolved with undefined.
300
308
Promise :: new_resolved ( global, cx, ( ) , can_gc)
@@ -311,12 +319,13 @@ impl TransformStreamDefaultController {
311
319
can_gc : CanGc ,
312
320
) -> Fallible < Rc < Promise > > {
313
321
let result = match & self . transformer_type {
322
+ // <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
314
323
TransformerType :: Js {
315
324
flush,
316
325
transform_obj,
317
326
..
318
327
} => {
319
- // If transformerDict["flush"] exists, set flushAlgorithm to an
328
+ // Step 6. If transformerDict["flush"] exists, set flushAlgorithm to an
320
329
// algorithm which returns the result of invoking
321
330
// transformerDict["flush"] with argument list « controller »
322
331
// and callback this value transformer.
@@ -336,13 +345,12 @@ impl TransformStreamDefaultController {
336
345
p
337
346
} )
338
347
} else {
339
- // Let flushAlgorithm be an algorithm which returns a promise resolved with undefined.
348
+ // Step 3. Let flushAlgorithm be an algorithm which returns a promise resolved with undefined.
340
349
Promise :: new_resolved ( global, cx, ( ) , can_gc)
341
350
}
342
351
} ,
352
+ // <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
343
353
TransformerType :: Decoder ( decoder) => {
344
- // <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
345
- //
346
354
// Step 8. Let flushAlgorithm be an algorithm which takes no
347
355
// arguments and runs the flush and enqueue algorithm with this.
348
356
flush_and_enqueue ( cx, global, decoder, self , can_gc)
0 commit comments