summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs')
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs68
1 files changed, 68 insertions, 0 deletions
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs
new file mode 100644
index 0000000000..e03291089e
--- /dev/null
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs
@@ -0,0 +1,68 @@
+{%- let object = ci.get_object_definition(name).unwrap() -%}
+export class {{ object.nm() }} {
+ // Use `init` to instantiate this class.
+ // DO NOT USE THIS CONSTRUCTOR DIRECTLY
+ constructor(opts) {
+ if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
+ throw new UniFFIError("Attempting to construct an object using the JavaScript constructor directly" +
+ "Please use a UDL defined constructor, or the init function for the primary constructor")
+ }
+ if (!opts[constructUniffiObject] instanceof UniFFIPointer) {
+ throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
+ }
+ this[uniffiObjectPtr] = opts[constructUniffiObject];
+ }
+
+ {%- for cons in object.constructors() %}
+ {%- if object.is_constructor_async(config) %}
+ /**
+ * An async constructor for {{ object.nm() }}.
+ *
+ * @returns {Promise<{{ object.nm() }}>}: A promise that resolves
+ * to a newly constructed {{ object.nm() }}
+ */
+ {%- else %}
+ /**
+ * A constructor for {{ object.nm() }}.
+ *
+ * @returns { {{ object.nm() }} }
+ */
+ {%- endif %}
+ static {{ cons.nm() }}({{cons.arg_names()}}) {
+ {%- call js::call_constructor(cons, type_, object.is_constructor_async(config)) -%}
+ }
+ {%- endfor %}
+
+ {%- for meth in object.methods() %}
+
+ {{ meth.nm() }}({{ meth.arg_names() }}) {
+ {%- call js::call_method(meth, type_, object.is_method_async(meth, config)) %}
+ }
+ {%- endfor %}
+
+}
+
+// Export the FFIConverter object to make external types work.
+export class {{ ffi_converter }} extends FfiConverter {
+ static lift(value) {
+ const opts = {};
+ opts[constructUniffiObject] = value;
+ return new {{ object.nm() }}(opts);
+ }
+
+ static lower(value) {
+ return value[uniffiObjectPtr];
+ }
+
+ static read(dataStream) {
+ return this.lift(dataStream.readPointer{{ object.nm() }}());
+ }
+
+ static write(dataStream, value) {
+ dataStream.writePointer{{ object.nm() }}(value[uniffiObjectPtr]);
+ }
+
+ static computeSize(value) {
+ return 8;
+ }
+}