12
12
13
13
// A JS class to use as the underlying sink for native writable streams, used
14
14
// for TransformStream.
15
- namespace NativeStreamSink {
16
- namespace Slots {
17
- enum {
18
- Owner, // TransformStream.
19
- Controller, // The WritableStreamDefaultController.
20
- InternalWriter, // Only used to lock the stream if it's consumed internally.
21
- StartPromise, // Used as the return value of `start`, can be undefined.
22
- // Needed to properly implement TransformStream.
23
- WriteAlgorithm,
24
- AbortAlgorithm,
25
- CloseAlgorithm,
26
- // AbortAlgorithm, TODO: implement
27
- Count
28
- };
29
- };
30
-
31
- JSObject *owner (JSObject *self) { return &JS::GetReservedSlot (self, Slots::Owner).toObject (); }
32
-
33
- JS::Value startPromise (JSObject *self) { return JS::GetReservedSlot (self, Slots::StartPromise); }
34
-
35
- WriteAlgorithm *writeAlgorithm (JSObject *self) {
36
- return (WriteAlgorithm *)JS::GetReservedSlot (self, Slots::WriteAlgorithm).toPrivate ();
15
+ namespace builtins {
16
+
17
+ JSObject *NativeStreamSink::owner (JSObject *self) {
18
+ return &JS::GetReservedSlot (self, Slots::Owner).toObject ();
19
+ }
20
+
21
+ JS::Value NativeStreamSink::startPromise (JSObject *self) {
22
+ return JS::GetReservedSlot (self, Slots::StartPromise);
23
+ }
24
+
25
+ NativeStreamSink::WriteAlgorithmImplementation *NativeStreamSink::writeAlgorithm (JSObject *self) {
26
+ return (WriteAlgorithmImplementation *)JS::GetReservedSlot (self, Slots::WriteAlgorithm)
27
+ .toPrivate ();
37
28
}
38
29
39
- AbortAlgorithm *abortAlgorithm (JSObject *self) {
40
- return (AbortAlgorithm *)JS::GetReservedSlot (self, Slots::AbortAlgorithm).toPrivate ();
30
+ NativeStreamSink::AbortAlgorithmImplementation *NativeStreamSink::abortAlgorithm (JSObject *self) {
31
+ return (AbortAlgorithmImplementation *)JS::GetReservedSlot (self, Slots::AbortAlgorithm)
32
+ .toPrivate ();
41
33
}
42
34
43
- CloseAlgorithm *closeAlgorithm (JSObject *self) {
44
- return (CloseAlgorithm *)JS::GetReservedSlot (self, Slots::CloseAlgorithm).toPrivate ();
35
+ NativeStreamSink::CloseAlgorithmImplementation *NativeStreamSink::closeAlgorithm (JSObject *self) {
36
+ return (CloseAlgorithmImplementation *)JS::GetReservedSlot (self, Slots::CloseAlgorithm)
37
+ .toPrivate ();
45
38
}
46
39
47
- JSObject *controller (JSObject *self) {
40
+ JSObject *NativeStreamSink:: controller (JSObject *self) {
48
41
return &JS::GetReservedSlot (self, Slots::Controller).toObject ();
49
42
}
50
43
51
44
/* *
52
45
* Returns the underlying sink for the given controller iff it's an object,
53
46
* nullptr otherwise.
54
47
*/
55
- static JSObject *get_controller_sink (JSContext *cx, JS::HandleObject controller) {
48
+ JSObject *NativeStreamSink:: get_controller_sink (JSContext *cx, JS::HandleObject controller) {
56
49
JS::RootedValue sink (cx, JS::WritableStreamControllerGetUnderlyingSink (cx, controller));
57
50
return sink.isObject () ? &sink.toObject () : nullptr ;
58
51
}
59
52
60
- JSObject *get_stream_sink (JSContext *cx, JS::HandleObject stream) {
53
+ JSObject *NativeStreamSink:: get_stream_sink (JSContext *cx, JS::HandleObject stream) {
61
54
JS::RootedObject controller (cx, JS::WritableStreamGetController (cx, stream));
62
55
return get_controller_sink (cx, controller);
63
56
}
64
57
65
- bool stream_has_native_sink (JSContext *cx, JS::HandleObject stream) {
58
+ bool NativeStreamSink:: stream_has_native_sink (JSContext *cx, JS::HandleObject stream) {
66
59
MOZ_RELEASE_ASSERT (JS::IsWritableStream (stream));
67
60
68
61
JSObject *sink = get_stream_sink (cx, stream);
69
62
return is_instance (sink);
70
63
}
71
64
72
- const unsigned ctor_length = 0 ;
73
-
74
- bool check_receiver (JSContext *cx, JS::HandleValue receiver, const char *method_name);
75
-
76
- bool start (JSContext *cx, unsigned argc, JS::Value *vp) {
65
+ bool NativeStreamSink::start (JSContext *cx, unsigned argc, JS::Value *vp) {
77
66
METHOD_HEADER (1 )
78
67
79
68
MOZ_ASSERT (args[0 ].isObject ());
@@ -93,45 +82,46 @@ bool start(JSContext *cx, unsigned argc, JS::Value *vp) {
93
82
return true ;
94
83
}
95
84
96
- bool write (JSContext *cx, unsigned argc, JS::Value *vp) {
85
+ bool NativeStreamSink:: write (JSContext *cx, unsigned argc, JS::Value *vp) {
97
86
METHOD_HEADER (1 )
98
87
99
88
JS::RootedObject owner (cx, NativeStreamSink::owner (self));
100
89
JS::HandleValue chunk (args[0 ]);
101
90
102
- WriteAlgorithm *write = writeAlgorithm (self);
91
+ WriteAlgorithmImplementation *write = writeAlgorithm (self);
103
92
return write (cx, args, self, owner, chunk);
104
93
}
105
94
106
- bool abort (JSContext *cx, unsigned argc, JS::Value *vp) {
95
+ bool NativeStreamSink:: abort (JSContext *cx, unsigned argc, JS::Value *vp) {
107
96
METHOD_HEADER (1 )
108
97
109
98
JS::RootedObject owner (cx, NativeStreamSink::owner (self));
110
99
JS::HandleValue reason (args[0 ]);
111
100
112
- AbortAlgorithm *abort = abortAlgorithm (self);
101
+ AbortAlgorithmImplementation *abort = abortAlgorithm (self);
113
102
return abort (cx, args, self, owner, reason);
114
103
}
115
104
116
- bool close (JSContext *cx, unsigned argc, JS::Value *vp) {
105
+ bool NativeStreamSink:: close (JSContext *cx, unsigned argc, JS::Value *vp) {
117
106
METHOD_HEADER (0 )
118
107
119
108
JS::RootedObject owner (cx, NativeStreamSink::owner (self));
120
109
121
- CloseAlgorithm *close = closeAlgorithm (self);
110
+ CloseAlgorithmImplementation *close = closeAlgorithm (self);
122
111
return close (cx, args, self, owner);
123
112
}
124
113
125
- const JSFunctionSpec methods[] = {JS_FN (" start" , start, 1 , 0 ), JS_FN (" write" , write, 2 , 0 ),
126
- JS_FN (" abort" , abort, 2 , 0 ), JS_FN (" close" , close, 1 , 0 ),
127
- JS_FS_END};
128
-
129
- const JSPropertySpec properties[] = {JS_PS_END};
114
+ const JSFunctionSpec NativeStreamSink::methods[] = {
115
+ JS_FN (" start" , start, 1 , 0 ), JS_FN (" write" , write, 2 , 0 ), JS_FN (" abort" , abort, 2 , 0 ),
116
+ JS_FN (" close" , close, 1 , 0 ), JS_FS_END};
130
117
131
- CLASS_BOILERPLATE_NO_CTOR ( NativeStreamSink)
118
+ const JSPropertySpec NativeStreamSink::properties[] = {JS_PS_END};
132
119
133
- JSObject *create (JSContext *cx, JS::HandleObject owner, JS::HandleValue startPromise,
134
- WriteAlgorithm *write, CloseAlgorithm *close, AbortAlgorithm *abort) {
120
+ JSObject *NativeStreamSink::create (JSContext *cx, JS::HandleObject owner,
121
+ JS::HandleValue startPromise,
122
+ WriteAlgorithmImplementation *write,
123
+ CloseAlgorithmImplementation *close,
124
+ AbortAlgorithmImplementation *abort) {
135
125
JS::RootedObject sink (cx, JS_NewObjectWithGivenProto (cx, &class_, proto_obj));
136
126
if (!sink)
137
127
return nullptr ;
@@ -143,4 +133,4 @@ JSObject *create(JSContext *cx, JS::HandleObject owner, JS::HandleValue startPro
143
133
JS::SetReservedSlot (sink, Slots::CloseAlgorithm, JS::PrivateValue ((void *)close));
144
134
return sink;
145
135
}
146
- } // namespace NativeStreamSink
136
+ } // namespace builtins
0 commit comments