10BC0 add spec link to JS algo · servo/servo@a1f0c91 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1f0c91

Browse files
author
minghuaw
committed
add spec link to JS algo
Signed-off-by: minghuaw <wuminghua7@huawei.com>
1 parent 35e8169 commit a1f0c91

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

components/script/dom/textdecoder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ use crate::dom::globalscope::GlobalScope;
2121
use crate::dom::textdecodercommon::TextDecoderCommon;
2222
use crate::script_runtime::CanGc;
2323

24+
/// <https://encoding.spec.whatwg.org/#textdecoder>
2425
#[dom_struct]
2526
#[allow(non_snake_case)]
2627
pub(crate) struct TextDecoder {
2728
reflector_: Reflector,
29+
30+
/// <https://encoding.spec.whatwg.org/#textdecodercommon>
2831
decoder: TextDecoderCommon,
2932
}
3033

@@ -85,22 +88,22 @@ impl TextDecoderMethods<crate::DomTypeHolder> for TextDecoder {
8588
))
8689
}
8790

88-
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
91+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-encoding>
8992
fn Encoding(&self) -> DOMString {
9093
self.decoder.encoding()
9194
}
9295

93-
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
96+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-fatal>
9497
fn Fatal(&self) -> bool {
9598
self.decoder.fatal()
9699
}
97100

98-
// https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom
101+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom>
99102
fn IgnoreBOM(&self) -> bool {
100103
self.decoder.ignore_bom()
101104
}
102105

103-
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
106+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-decode>
104107
fn Decode(
105108
&self,
106109
input: Option<ArrayBufferViewOrArrayBuffer>,

components/script/dom/textdecoderstream.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn decode_and_enqueue_a_chunk(
4646

4747
// Step 2. Push a copy of bufferSource to decoder’s I/O queue.
4848
// Step 3. Let output be the I/O queue of scalar values « end-of-queue ».
49-
// Step 4. Implemented by `TextDecoderCommon::decode`, which uses the same process as
49+
// Step 4. Implemented by `TextDecoderCommon::decode`, which uses the same procedure as
5050
// `TextDecoder`
5151
let output_chunk = decoder.decode(Some(buffer_source), true)?;
5252

@@ -135,7 +135,7 @@ impl TextDecoderStream {
135135

136136
#[allow(non_snake_case)]
137137
impl TextDecoderStreamMethods<crate::DomTypeHolder> for TextDecoderStream {
138-
// https://encoding.spec.whatwg.org/#dom-textdecoderstream
138+
/// <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
139139
fn Constructor(
140140
global: &GlobalScope,
141141
proto: Option<SafeHandleObject>,
@@ -163,27 +163,27 @@ impl TextDecoderStreamMethods<crate::DomTypeHolder> for TextDecoderStream {
163163
)
164164
}
165165

166-
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
166+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-encoding>
167167
fn Encoding(&self) -> DOMString {
168168
self.decoder.encoding()
169169
}
170170

171-
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
171+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-fatal>
172172
fn Fatal(&self) -> bool {
173173
self.decoder.fatal()
174174
}
175175

176-
// https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom
176+
/// <https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom>
177177
fn IgnoreBOM(&self) -> bool {
178178
self.decoder.ignore_bom()
179179
}
180180

181-
// https://streams.spec.whatwg.org/#dom-generictransformstream-readable
181+
/// <https://streams.spec.whatwg.org/#dom-generictransformstream-readable>
182182
fn Readable(&self) -> DomRoot<<crate::DomTypeHolder as DomTypes>::ReadableStream> {
183183
self.transform.get_readable()
184184
}
185185

186-
// https://streams.spec.whatwg.org/#dom-generictransformstream-writable
186+
/// <https://streams.spec.whatwg.org/#dom-generictransformstream-writable>
187187
fn Writable(&self) -> DomRoot<<crate::DomTypeHolder as DomTypes>::WritableStream> {
188188
self.transform.get_writable()
189189
}

components/script/dom/transformstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl TransformStream {
461461
// Step 5. Let transformAlgorithmWrapper be an algorithm that runs these steps given a value chunk:
462462
// Step 6. Let flushAlgorithmWrapper be an algorithm that runs these steps:
463463
// Step 7. Let cancelAlgorithmWrapper be an algorithm that runs these steps given a value reason:
464-
// NOTE: These steps are implemented in `TransformStreamDefaultController`
464+
// NOTE: These steps are implemented in `TransformStreamDefaultController::new`
465465

466466
// Step 8. Let startPromise be a promise resolved with undefined.
467467
let start_promise = Promise::new_resolved(global, cx, (), can_gc);

components/script/dom/transformstreamdefaultcontroller.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub(crate) enum TransformerType {
7272
transform_obj: Heap<*mut JSObject>,
7373
},
7474
/// Algorithms supporting `TextDecoderStream` are implemented in Rust
75+
///
76+
/// <https://encoding.spec.whatwg.org/#textdecodercommon>
7577
Decoder(Rc<TextDecoderCommon>),
7678
}
7779

@@ -143,6 +145,8 @@ impl TransformStreamDefaultController {
143145
}
144146

145147
/// 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`
146150
pub(crate) fn set_transform_obj(&self, this_object: SafeHandleObject) {
147151
if let TransformerType::Js { transform_obj, .. } = &self.transformer_type {
148152
transform_obj.set(*this_object)
@@ -198,12 +202,13 @@ impl TransformStreamDefaultController {
198202
can_gc: CanGc,
199203
) -> Fallible<Rc<Promise>> {
200204
let result = match &self.transformer_type {
205+
// <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
201206
TransformerType::Js {
202207
transform,
203208
transform_obj,
204209
..
205210
} => {
206-
// If transformerDict["transform"] exists, set
211+
// Step 5. If transformerDict["transform"] exists, set
207212
// transformAlgorithm to an algorithm which takes an argument
208213
// chunk and returns the result of invoking
209214
// transformerDict["transform"] with argument list « chunk,
@@ -225,7 +230,7 @@ impl TransformStreamDefaultController {
225230
p
226231
})
227232
} 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:
229234
// Let result be TransformStreamDefaultControllerEnqueue(controller, chunk).
230235
// If result is an abrupt completion, return a promise rejected with result.[[Value]].
231236
if let Err(error) = self.enqueue(cx, global, chunk, can_gc) {
@@ -238,9 +243,8 @@ impl TransformStreamDefaultController {
238243
}
239244
}
240245
},
246+
// <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
241247
TransformerType::Decoder(decoder) => {
242-
// <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
243-
//
244248
// Step 7. Let transformAlgorithm be an algorithm which takes a
245249
// chunk argument and runs the decode and enqueue a chunk
246250
// algorithm with this and chunk.
@@ -265,14 +269,17 @@ impl TransformStreamDefaultController {
265269
can_gc: CanGc,
266270
) -> Fallible<Rc<Promise>> {
267271
let result = match &self.transformer_type {
272+
// <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
268273
TransformerType::Js {
269274
cancel,
270275
transform_obj,
271276
..
272277
} => {
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.
276283
let algo = cancel.borrow().clone();
277284
if let Some(cancel) = algo {
278285
rooted!(in(*cx) let this_object = transform_obj.get());
@@ -289,12 +296,13 @@ impl TransformStreamDefaultController {
289296
p
290297
})
291298
} 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.
293300
Promise::new_resolved(global, cx, (), can_gc)
294301
}
295302
},
303+
// <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
296304
TransformerType::Decoder(_) => {
297-
// <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
305+
// `TextDecoderStream` does NOT specify a cancel algorithm.
298306
//
299307
// Step 4. Let cancelAlgorithm be an algorithm which returns a promise resolved with undefined.
300308
Promise::new_resolved(global, cx, (), can_gc)
@@ -311,12 +319,13 @@ impl TransformStreamDefaultController {
311319
can_gc: CanGc,
312320
) -> Fallible<Rc<Promise>> {
313321
let result = match &self.transformer_type {
322+
// <https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer>
314323
TransformerType::Js {
315324
flush,
316325
transform_obj,
317326
..
318327
} => {
319-
// If transformerDict["flush"] exists, set flushAlgorithm to an
328+
// Step 6. If transformerDict["flush"] exists, set flushAlgorithm to an
320329
// algorithm which returns the result of invoking
321330
// transformerDict["flush"] with argument list « controller »
322331
// and callback this value transformer.
@@ -336,13 +345,12 @@ impl TransformStreamDefaultController {
336345
p
337346
})
338347
} 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.
340349
Promise::new_resolved(global, cx, (), can_gc)
341350
}
342351
},
352+
// <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
343353
TransformerType::Decoder(decoder) => {
344-
// <https://encoding.spec.whatwg.org/#dom-textdecoderstream>
345-
//
346354
// Step 8. Let flushAlgorithm be an algorithm which takes no
347355
// arguments and runs the flush and enqueue algorithm with this.
348356
flush_and_enqueue(cx, global, decoder, self, can_gc)

0 commit comments

Comments
 (0)
0