16
16
* All algorithm names and steps refer to spec algorithms defined at
17
17
* https://streams.spec.whatwg.org/#ts-default-controller-class
18
18
*/
19
- namespace TransformStreamDefaultController {
20
- bool is_instance (JSObject *obj);
21
-
22
- JSObject *stream (JSObject *controller) {
19
+ // A JS class to use as the underlying sink for native writable streams, used
20
+ // for TransformStream.
21
+ namespace builtins {
22
+ JSObject *TransformStreamDefaultController:: stream (JSObject *controller) {
23
23
MOZ_ASSERT (is_instance (controller));
24
24
return &JS::GetReservedSlot (controller, Slots::Stream).toObject ();
25
25
}
26
26
27
- TransformAlgorithm *transformAlgorithm (JSObject *controller) {
27
+ TransformStreamDefaultController::TransformAlgorithmImplementation *
28
+ TransformStreamDefaultController::transformAlgorithm (JSObject *controller) {
28
29
MOZ_ASSERT (is_instance (controller));
29
- return (TransformAlgorithm *)JS::GetReservedSlot (controller, Slots::TransformAlgorithm)
30
+ return (TransformAlgorithmImplementation *)JS::GetReservedSlot (controller,
31
+ Slots::TransformAlgorithm)
30
32
.toPrivate ();
31
33
}
32
34
33
- FlushAlgorithm *flushAlgorithm (JSObject *controller) {
35
+ TransformStreamDefaultController::FlushAlgorithmImplementation *
36
+ TransformStreamDefaultController::flushAlgorithm (JSObject *controller) {
34
37
MOZ_ASSERT (is_instance (controller));
35
- return (FlushAlgorithm *)JS::GetReservedSlot (controller, Slots::FlushAlgorithm).toPrivate ();
38
+ return (FlushAlgorithmImplementation *)JS::GetReservedSlot (controller, Slots::FlushAlgorithm)
39
+ .toPrivate ();
36
40
}
37
41
38
- const unsigned ctor_length = 0 ;
39
-
40
- bool check_receiver (JSContext *cx, JS::HandleValue receiver, const char *method_name);
41
-
42
- bool Enqueue (JSContext *cx, JS::HandleObject controller, JS::HandleValue chunk);
43
- bool Terminate (JSContext *cx, JS::HandleObject controller);
44
-
45
42
/* *
46
43
* https://streams.spec.whatwg.org/#ts-default-controller-desired-size
47
44
*/
48
- bool desiredSize_get (JSContext *cx, unsigned argc, JS::Value *vp) {
45
+ bool TransformStreamDefaultController::desiredSize_get (JSContext *cx, unsigned argc,
46
+ JS::Value *vp) {
49
47
METHOD_HEADER_WITH_NAME (0 , " get desiredSize" )
50
48
51
49
// 1. Let readableController be [this].[stream].[readable].[controller].
52
- JSObject *stream = :: TransformStreamDefaultController::stream (self);
50
+ JSObject *stream = TransformStreamDefaultController::stream (self);
53
51
JSObject *readable = TransformStream::readable (stream);
54
52
double value;
55
53
bool has_value;
@@ -66,13 +64,10 @@ bool desiredSize_get(JSContext *cx, unsigned argc, JS::Value *vp) {
66
64
return true ;
67
65
}
68
66
69
- const JSPropertySpec properties[] = {JS_PSG (" desiredSize" , desiredSize_get, JSPROP_ENUMERATE),
70
- JS_PS_END};
71
-
72
67
/* *
73
68
* https://streams.spec.whatwg.org/#ts-default-controller-enqueue
74
69
*/
75
- bool enqueue_js (JSContext *cx, unsigned argc, JS::Value *vp) {
70
+ bool TransformStreamDefaultController:: enqueue_js (JSContext *cx, unsigned argc, JS::Value *vp) {
76
71
METHOD_HEADER_WITH_NAME (0 , " enqueue" )
77
72
78
73
// 1. Perform TransformStreamDefaultControllerEnqueue([this], chunk).
@@ -87,12 +82,12 @@ bool enqueue_js(JSContext *cx, unsigned argc, JS::Value *vp) {
87
82
/* *
88
83
* https://streams.spec.whatwg.org/#ts-default-controller-error
89
84
*/
90
- bool error_js (JSContext *cx, unsigned argc, JS::Value *vp) {
85
+ bool TransformStreamDefaultController:: error_js (JSContext *cx, unsigned argc, JS::Value *vp) {
91
86
METHOD_HEADER_WITH_NAME (0 , " error" )
92
87
93
88
// 1. Perform TransformStreamDefaultControllerError(this, e).
94
89
// (inlined)
95
- JS::RootedObject stream (cx, :: TransformStreamDefaultController::stream (self));
90
+ JS::RootedObject stream (cx, TransformStreamDefaultController::stream (self));
96
91
97
92
if (!TransformStream::Error (cx, stream, args.get (0 ))) {
98
93
return false ;
@@ -105,7 +100,7 @@ bool error_js(JSContext *cx, unsigned argc, JS::Value *vp) {
105
100
/* *
106
101
* https://streams.spec.whatwg.org/#ts-default-controller-terminate
107
102
*/
108
- bool terminate_js (JSContext *cx, unsigned argc, JS::Value *vp) {
103
+ bool TransformStreamDefaultController:: terminate_js (JSContext *cx, unsigned argc, JS::Value *vp) {
109
104
METHOD_HEADER_WITH_NAME (0 , " terminate" )
110
105
111
106
// 1. Perform TransformStreamDefaultControllerTerminate(this).
@@ -117,14 +112,18 @@ bool terminate_js(JSContext *cx, unsigned argc, JS::Value *vp) {
117
112
return true ;
118
113
}
119
114
120
- const JSFunctionSpec methods[] = {JS_FN (" enqueue" , enqueue_js, 1 , JSPROP_ENUMERATE),
121
- JS_FN (" error" , error_js, 1 , JSPROP_ENUMERATE),
122
- JS_FN (" terminate" , terminate_js, 0 , JSPROP_ENUMERATE), JS_FS_END};
115
+ const JSFunctionSpec TransformStreamDefaultController::methods[] = {
116
+ JS_FN (" enqueue" , enqueue_js, 1 , JSPROP_ENUMERATE),
117
+ JS_FN (" error" , error_js, 1 , JSPROP_ENUMERATE),
118
+ JS_FN (" terminate" , terminate_js, 0 , JSPROP_ENUMERATE), JS_FS_END};
123
119
124
- CLASS_BOILERPLATE_NO_CTOR (TransformStreamDefaultController)
120
+ const JSPropertySpec TransformStreamDefaultController::properties[] = {
121
+ JS_PSG (" desiredSize" , desiredSize_get, JSPROP_ENUMERATE), JS_PS_END};
125
122
126
- JSObject *create (JSContext *cx, JS::HandleObject stream, TransformAlgorithm *transformAlgo,
127
- FlushAlgorithm *flushAlgo) {
123
+ JSObject *TransformStreamDefaultController::create (
124
+ JSContext *cx, JS::HandleObject stream,
125
+ TransformStreamDefaultController::TransformAlgorithmImplementation *transformAlgo,
126
+ TransformStreamDefaultController::FlushAlgorithmImplementation *flushAlgo) {
128
127
JS::RootedObject controller (cx, JS_NewObjectWithGivenProto (cx, &class_, proto_obj));
129
128
if (!controller)
130
129
return nullptr ;
@@ -151,8 +150,9 @@ JSObject *create(JSContext *cx, JS::HandleObject stream, TransformAlgorithm *tra
151
150
return controller;
152
151
}
153
152
154
- void set_transformer (JSObject *controller, JS::Value transformer, JSObject *transformFunction,
155
- JSObject *flushFunction) {
153
+ void TransformStreamDefaultController::set_transformer (JSObject *controller, JS::Value transformer,
154
+ JSObject *transformFunction,
155
+ JSObject *flushFunction) {
156
156
JS::SetReservedSlot (controller, Slots::Transformer, transformer);
157
157
JS::SetReservedSlot (controller, Slots::TransformInput, JS::ObjectOrNullValue (transformFunction));
158
158
JS::SetReservedSlot (controller, Slots::FlushInput, JS::ObjectOrNullValue (flushFunction));
@@ -161,11 +161,12 @@ void set_transformer(JSObject *controller, JS::Value transformer, JSObject *tran
161
161
/* *
162
162
* TransformStreamDefaultControllerEnqueue
163
163
*/
164
- bool Enqueue (JSContext *cx, JS::HandleObject controller, JS::HandleValue chunk) {
164
+ bool TransformStreamDefaultController::Enqueue (JSContext *cx, JS::HandleObject controller,
165
+ JS::HandleValue chunk) {
165
166
MOZ_ASSERT (is_instance (controller));
166
167
167
168
// 1. Let stream be controller.[stream].
168
- JS::RootedObject stream (cx, :: TransformStreamDefaultController::stream (controller));
169
+ JS::RootedObject stream (cx, TransformStreamDefaultController::stream (controller));
169
170
170
171
// 2. Let readableController be stream.[readable].[controller].
171
172
JS::RootedObject readable (cx, TransformStream::readable (stream));
@@ -224,11 +225,11 @@ bool Enqueue(JSContext *cx, JS::HandleObject controller, JS::HandleValue chunk)
224
225
/* *
225
226
* TransformStreamDefaultControllerTerminate
226
227
*/
227
- bool Terminate (JSContext *cx, JS::HandleObject controller) {
228
+ bool TransformStreamDefaultController:: Terminate (JSContext *cx, JS::HandleObject controller) {
228
229
MOZ_ASSERT (is_instance (controller));
229
230
230
231
// 1. Let stream be controller.[stream].
231
- JS::RootedObject stream (cx, :: TransformStreamDefaultController::stream (controller));
232
+ JS::RootedObject stream (cx, TransformStreamDefaultController::stream (controller));
232
233
233
234
// 2. Let readableController be stream.[readable].[controller].
234
235
JS::RootedObject readable (cx, TransformStream::readable (stream));
@@ -275,8 +276,8 @@ bool Terminate(JSContext *cx, JS::HandleObject controller) {
275
276
* of <invoke a callback function> and the conversion step from
276
277
* https://webidl.spec.whatwg.org/#es-promise on the completion value.
277
278
*/
278
- JSObject *InvokePromiseReturningCallback (JSContext *cx, JS::HandleValue receiver,
279
- JS::HandleValue callback, JS::HandleValueArray args) {
279
+ JSObject *TransformStreamDefaultController::InvokePromiseReturningCallback (
280
+ JSContext *cx, JS::HandleValue receiver, JS::HandleValue callback, JS::HandleValueArray args) {
280
281
JS::RootedValue rval (cx);
281
282
if (!JS::Call (cx, receiver, callback, args, &rval)) {
282
283
return PromiseRejectedWithPendingError (cx);
@@ -291,8 +292,8 @@ JSObject *InvokePromiseReturningCallback(JSContext *cx, JS::HandleValue receiver
291
292
*
292
293
* Steps 2.* and 4 of SetUpTransformStreamDefaultControllerFromTransformer.
293
294
*/
294
- JSObject *transform_algorithm_transformer (JSContext *cx, JS::HandleObject controller,
295
- JS::HandleValue chunk) {
295
+ JSObject *TransformStreamDefaultController::transform_algorithm_transformer (
296
+ JSContext *cx, JS::HandleObject controller, JS::HandleValue chunk) {
296
297
MOZ_ASSERT (is_instance (controller));
297
298
298
299
// Step 2. Let transformAlgorithm be the following steps, taking a chunk
@@ -329,7 +330,9 @@ JSObject *transform_algorithm_transformer(JSContext *cx, JS::HandleObject contro
329
330
*
330
331
* Steps 3 and 5 of SetUpTransformStreamDefaultControllerFromTransformer.
331
332
*/
332
- JSObject *flush_algorithm_transformer (JSContext *cx, JS::HandleObject controller) {
333
+ JSObject *
334
+ TransformStreamDefaultController::flush_algorithm_transformer (JSContext *cx,
335
+ JS::HandleObject controller) {
333
336
MOZ_ASSERT (is_instance (controller));
334
337
335
338
// Step 3. Let flushAlgorithm be an algorithm which returns a promise
@@ -352,8 +355,9 @@ JSObject *flush_algorithm_transformer(JSContext *cx, JS::HandleObject controller
352
355
* SetUpTransformStreamDefaultController
353
356
* https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller
354
357
*/
355
- JSObject *SetUp (JSContext *cx, JS::HandleObject stream, TransformAlgorithm *transformAlgo,
356
- FlushAlgorithm *flushAlgo) {
358
+ JSObject *TransformStreamDefaultController::SetUp (JSContext *cx, JS::HandleObject stream,
359
+ TransformAlgorithmImplementation *transformAlgo,
360
+ FlushAlgorithmImplementation *flushAlgo) {
357
361
MOZ_ASSERT (TransformStream::is_instance (stream));
358
362
359
363
// Step 1 of SetUpTransformStreamDefaultControllerFromTransformer and step 1-6
@@ -367,8 +371,11 @@ JSObject *SetUp(JSContext *cx, JS::HandleObject stream, TransformAlgorithm *tran
367
371
* SetUpTransformStreamDefaultControllerFromTransformer
368
372
* https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer
369
373
*/
370
- JSObject *SetUpFromTransformer (JSContext *cx, JS::HandleObject stream, JS::HandleValue transformer,
371
- JS::HandleObject transformFunction, JS::HandleObject flushFunction) {
374
+ JSObject *TransformStreamDefaultController::SetUpFromTransformer (JSContext *cx,
375
+ JS::HandleObject stream,
376
+ JS::HandleValue transformer,
377
+ JS::HandleObject transformFunction,
378
+ JS::HandleObject flushFunction) {
372
379
MOZ_ASSERT (TransformStream::is_instance (stream));
373
380
374
381
// Step 1, moved into SetUpTransformStreamDefaultController.
@@ -390,8 +397,10 @@ JSObject *SetUpFromTransformer(JSContext *cx, JS::HandleObject stream, JS::Handl
390
397
/* *
391
398
* Steps 2.* of TransformStreamDefaultControllerPerformTransform.
392
399
*/
393
- bool transformPromise_catch_handler (JSContext *cx, JS::HandleObject controller,
394
- JS::HandleValue extra, JS::CallArgs args) {
400
+ bool TransformStreamDefaultController::transformPromise_catch_handler (JSContext *cx,
401
+ JS::HandleObject controller,
402
+ JS::HandleValue extra,
403
+ JS::CallArgs args) {
395
404
JS::RootedValue r (cx, args.get (0 ));
396
405
// 1. Perform ! [TransformStreamError](controller.[stream], r).
397
406
JS::RootedObject streamObj (cx, stream (controller));
@@ -407,12 +416,14 @@ bool transformPromise_catch_handler(JSContext *cx, JS::HandleObject controller,
407
416
/* *
408
417
* TransformStreamDefaultControllerPerformTransform
409
418
*/
410
- JSObject *PerformTransform (JSContext *cx, JS::HandleObject controller, JS::HandleValue chunk) {
419
+ JSObject *TransformStreamDefaultController::PerformTransform (JSContext *cx,
420
+ JS::HandleObject controller,
421
+ JS::HandleValue chunk) {
411
422
MOZ_ASSERT (is_instance (controller));
412
423
413
424
// 1. Let transformPromise be the result of performing
414
425
// controller.[transformAlgorithm], passing chunk.
415
- TransformAlgorithm *transformAlgo = transformAlgorithm (controller);
426
+ TransformAlgorithmImplementation *transformAlgo = transformAlgorithm (controller);
416
427
JS::RootedObject transformPromise (cx, transformAlgo (cx, controller, chunk));
417
428
if (!transformPromise) {
418
429
return nullptr ;
@@ -432,7 +443,7 @@ JSObject *PerformTransform(JSContext *cx, JS::HandleObject controller, JS::Handl
432
443
/* *
433
444
* TransformStreamDefaultControllerClearAlgorithms
434
445
*/
435
- void ClearAlgorithms (JSObject *controller) {
446
+ void TransformStreamDefaultController:: ClearAlgorithms (JSObject *controller) {
436
447
MOZ_ASSERT (is_instance (controller));
437
448
438
449
// 1. Set controller.[transformAlgorithm] to undefined.
@@ -443,4 +454,4 @@ void ClearAlgorithms(JSObject *controller) {
443
454
JS::SetReservedSlot (controller, Slots::FlushAlgorithm, JS::PrivateValue (nullptr ));
444
455
JS::SetReservedSlot (controller, Slots::FlushInput, JS::UndefinedValue ());
445
456
}
446
- } // namespace TransformStreamDefaultController
457
+ } // namespace builtins
0 commit comments