summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm')
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm24
1 files changed, 24 insertions, 0 deletions
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm
new file mode 100644
index 0000000000..c2b231c9b4
--- /dev/null
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm
@@ -0,0 +1,24 @@
+class FfiConverterString extends FfiConverter {
+ static lift(buf) {
+ const decoder = new TextDecoder();
+ const utf8Arr = new Uint8Array(buf);
+ return decoder.decode(utf8Arr);
+ }
+ static lower(value) {
+ const encoder = new TextEncoder();
+ return encoder.encode(value).buffer;
+ }
+
+ static write(dataStream, value) {
+ dataStream.writeString(value);
+ }
+
+ static read(dataStream) {
+ return dataStream.readString();
+ }
+
+ static computeSize(value) {
+ const encoder = new TextEncoder();
+ return 4 + encoder.encode(value).length
+ }
+}