summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/src/templates
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/uniffi-bindgen-gecko-js/src/templates')
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp3
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs10
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs6
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs6
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs2
5 files changed, 16 insertions, 11 deletions
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp
index 5c4ed8c2f5..83aeae8086 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp
@@ -37,7 +37,8 @@ extern "C" {
{%- let pointer_type = ci.pointer_type(object) %}
const static mozilla::uniffi::UniFFIPointerType {{ pointer_type }} {
"{{ "{}::{}"|format(ci.namespace(), object.name()) }}"_ns,
- {{ object.ffi_object_free().rust_name() }}
+ {{ object.ffi_object_clone().rust_name() }},
+ {{ object.ffi_object_free().rust_name() }},
};
{%- endfor %}
{%- endfor %}
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs
index f7716ac6d8..cbcc256eb9 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs
@@ -16,7 +16,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return {{ enum_.nm() }}.{{ variant.name().to_shouty_snake_case() }}
{%- endfor %}
default:
- return new Error("Unknown {{ enum_.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant");
}
}
@@ -27,7 +27,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return;
}
{%- endfor %}
- return new Error("Unknown {{ enum_.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant");
}
static computeSize(value) {
@@ -72,7 +72,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
);
{%- endfor %}
default:
- return new Error("Unknown {{ enum_.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant");
}
}
@@ -86,7 +86,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return;
}
{%- endfor %}
- return new Error("Unknown {{ enum_.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant");
}
static computeSize(value) {
@@ -100,7 +100,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return totalSize;
}
{%- endfor %}
- return new Error("Unknown {{ enum_.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant");
}
static checkType(value) {
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs
index b140d908da..c472f1a27d 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs
@@ -46,7 +46,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
{%- endif %}
{%- endfor %}
default:
- throw new Error("Unknown {{ error.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ error.nm() }} variant");
}
}
static computeSize(value) {
@@ -60,7 +60,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return totalSize;
}
{%- endfor %}
- throw new Error("Unknown {{ error.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ error.nm() }} variant");
}
static write(dataStream, value) {
{%- for variant in error.variants() %}
@@ -72,7 +72,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
return;
}
{%- endfor %}
- throw new Error("Unknown {{ error.nm() }} variant");
+ throw new UniFFITypeError("Unknown {{ error.nm() }} variant");
}
static errorClass = {{ error.nm() }};
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
index e03291089e..204bf752dd 100644
--- 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
@@ -51,7 +51,11 @@ export class {{ ffi_converter }} extends FfiConverter {
}
static lower(value) {
- return value[uniffiObjectPtr];
+ const ptr = value[uniffiObjectPtr];
+ if (!(ptr instanceof UniFFIPointer)) {
+ throw new UniFFITypeError("Object is not a '{{ object.nm() }}' instance");
+ }
+ return ptr;
}
static read(dataStream) {
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs
index 2f54160b9e..638be5bee8 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs
@@ -51,7 +51,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer {
static checkType(value) {
super.checkType(value);
if (!(value instanceof {{ record.nm() }})) {
- throw new TypeError(`Expected '{{ record.nm() }}', found '${typeof value}'`);
+ throw new UniFFITypeError(`Expected '{{ record.nm() }}', found '${typeof value}'`);
}
{%- for field in record.fields() %}
try {