2222#include < js/experimental/TypedData.h>
2323#include < jsapi.h> // for JS_NewPlainObject
2424
25- #include " gi/boxed .h"
25+ #include " gi/struct .h"
2626#include " cjs/atoms.h"
2727#include " cjs/byteArray.h"
2828#include " cjs/context-private.h"
@@ -43,35 +43,35 @@ static bool to_string_func(JSContext* cx, unsigned argc, JS::Value* vp) {
4343 return false ;
4444
4545 const char * actual_encoding = encoding ? encoding.get () : " utf-8" ;
46- JS::RootedString str (
47- cx, gjs_decode_from_uint8array ( cx, byte_array, actual_encoding,
48- GjsStringTermination::ZERO_TERMINATED, true )) ;
46+ JS::RootedString str{cx, gjs_decode_from_uint8array (
47+ cx, byte_array, actual_encoding,
48+ GjsStringTermination::ZERO_TERMINATED, true )} ;
4949 if (!str)
5050 return false ;
5151
5252 args.rval ().setString (str);
5353 return true ;
5454}
5555
56- /* Workaround to keep existing code compatible. This function is tacked onto
57- * any Uint8Array instances created in situations where previously a ByteArray
58- * would have been created. It logs a compatibility warning. */
56+ /* Workaround to keep existing code compatible. This function is tacked onto any
57+ * Uint8Array instances created in situations where previously a ByteArray would
58+ * have been created. It logs a compatibility warning. */
5959GJS_JSAPI_RETURN_CONVENTION
6060static bool instance_to_string_func (JSContext* cx, unsigned argc,
6161 JS::Value* vp) {
6262 GJS_GET_THIS (cx, argc, vp, args, this_obj);
6363 JS::UniqueChars encoding;
6464
65- _gjs_warn_deprecated_once_per_callsite (
65+ gjs_warn_deprecated_once_per_callsite (
6666 cx, GjsDeprecationMessageId::ByteArrayInstanceToString);
6767
6868 if (!gjs_parse_call_args (cx, " toString" , args, " |s" , " encoding" , &encoding))
6969 return false ;
7070
7171 const char * actual_encoding = encoding ? encoding.get () : " utf-8" ;
72- JS::RootedString str (
73- cx, gjs_decode_from_uint8array ( cx, this_obj, actual_encoding,
74- GjsStringTermination::ZERO_TERMINATED, true )) ;
72+ JS::RootedString str{cx, gjs_decode_from_uint8array (
73+ cx, this_obj, actual_encoding,
74+ GjsStringTermination::ZERO_TERMINATED, true )} ;
7575 if (!str)
7676 return false ;
7777
@@ -86,7 +86,7 @@ static bool define_legacy_tostring(JSContext* cx, JS::HandleObject array) {
8686 instance_to_string_func, 1 , 0 );
8787}
8888
89- /* fromString() function implementation */
89+ // fromString() function implementation
9090GJS_JSAPI_RETURN_CONVENTION
9191static bool from_string_func (JSContext* cx, unsigned argc, JS::Value* vp) {
9292 JS::CallArgs args = JS::CallArgsFromVp (argc, vp);
@@ -108,38 +108,32 @@ static bool from_string_func(JSContext* cx, unsigned argc, JS::Value* vp) {
108108}
109109
110110GJS_JSAPI_RETURN_CONVENTION
111- static bool
112- from_gbytes_func (JSContext *context,
113- unsigned argc,
114- JS::Value *vp)
115- {
116- JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
117- JS::RootedObject bytes_obj (context);
118- GBytes *gbytes;
119-
120- if (!gjs_parse_call_args (context, " fromGBytes" , argv, " o" ,
121- " bytes" , &bytes_obj))
111+ static bool from_gbytes_func (JSContext* cx, unsigned argc, JS::Value* vp) {
112+ JS::CallArgs args = JS::CallArgsFromVp (argc, vp);
113+ JS::RootedObject bytes_obj{cx};
114+
115+ if (!gjs_parse_call_args (cx, " fromGBytes" , args, " o" , " bytes" , &bytes_obj))
122116 return false ;
123117
124- if (!BoxedBase ::typecheck (context , bytes_obj, G_TYPE_BYTES))
118+ if (!StructBase ::typecheck (cx , bytes_obj, G_TYPE_BYTES))
125119 return false ;
126120
127- gbytes = BoxedBase ::to_c_ptr<GBytes>(context , bytes_obj);
121+ GBytes* gbytes = StructBase ::to_c_ptr<GBytes>(cx , bytes_obj);
128122 if (!gbytes)
129123 return false ;
130124
131125 size_t len;
132126 const void * data = g_bytes_get_data (gbytes, &len);
133127 if (len == 0 ) {
134- JS::RootedObject empty_array (context , JS_NewUint8Array (context , 0 )) ;
135- if (!empty_array || !define_legacy_tostring (context , empty_array))
128+ JS::RootedObject empty_array{cx , JS_NewUint8Array (cx , 0 )} ;
129+ if (!empty_array || !define_legacy_tostring (cx , empty_array))
136130 return false ;
137131
138- argv .rval ().setObject (*empty_array);
132+ args .rval ().setObject (*empty_array);
139133 return true ;
140134 }
141135
142- JS::RootedObject array_buffer{context , JS::NewArrayBuffer (context , len)};
136+ JS::RootedObject array_buffer{cx , JS::NewArrayBuffer (cx , len)};
143137 if (!array_buffer)
144138 return false ;
145139
@@ -152,12 +146,12 @@ from_gbytes_func(JSContext *context,
152146 std::copy_n (static_cast <const uint8_t *>(data), len, storage);
153147 }
154148
155- JS::RootedObject obj (
156- context, JS_NewUint8ArrayWithBuffer (context , array_buffer, 0 , -1 )) ;
157- if (!obj || !define_legacy_tostring (context , obj))
149+ JS::RootedObject obj{cx,
150+ JS_NewUint8ArrayWithBuffer (cx , array_buffer, 0 , -1 )} ;
151+ if (!obj || !define_legacy_tostring (cx , obj))
158152 return false ;
159153
160- argv .rval ().setObject (*obj);
154+ args .rval ().setObject (*obj);
161155 return true ;
162156}
163157
@@ -211,10 +205,8 @@ static JSFunctionSpec gjs_byte_array_module_funcs[] = {
211205 JS_FN (" toString" , to_string_func, 2 , 0 ),
212206 JS_FS_END};
213207
214- bool
215- gjs_define_byte_array_stuff (JSContext *cx,
216- JS::MutableHandleObject module )
217- {
208+ bool gjs_define_byte_array_stuff (JSContext* cx,
209+ JS::MutableHandleObject module ) {
218210 module .set (JS_NewPlainObject (cx));
219211 return JS_DefineFunctions (cx, module , gjs_byte_array_module_funcs);
220212}
0 commit comments