summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /toolkit/components/uniffi-bindgen-gecko-js/src
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-bindgen-gecko-js/src')
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs40
-rw-r--r--toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs4
-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
7 files changed, 35 insertions, 36 deletions
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs
index 685c3c2bf3..7b63e8f3af 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs
@@ -136,31 +136,25 @@ pub impl FfiType {
// Type for the Rust scaffolding code
fn rust_type(&self) -> String {
match self {
- FfiType::UInt8 => "uint8_t",
- FfiType::Int8 => "int8_t",
- FfiType::UInt16 => "uint16_t",
- FfiType::Int16 => "int16_t",
- FfiType::UInt32 => "uint32_t",
- FfiType::Int32 => "int32_t",
- FfiType::UInt64 => "uint64_t",
- FfiType::Int64 => "int64_t",
- FfiType::Float32 => "float",
- FfiType::Float64 => "double",
- FfiType::RustBuffer(_) => "RustBuffer",
- FfiType::RustArcPtr(_) => "void *",
- FfiType::ForeignCallback => "ForeignCallback",
+ FfiType::UInt8 => "uint8_t".to_owned(),
+ FfiType::Int8 => "int8_t".to_owned(),
+ FfiType::UInt16 => "uint16_t".to_owned(),
+ FfiType::Int16 => "int16_t".to_owned(),
+ FfiType::UInt32 => "uint32_t".to_owned(),
+ FfiType::Int32 => "int32_t".to_owned(),
+ FfiType::UInt64 => "uint64_t".to_owned(),
+ FfiType::Int64 => "int64_t".to_owned(),
+ FfiType::Float32 => "float".to_owned(),
+ FfiType::Float64 => "double".to_owned(),
+ FfiType::RustBuffer(_) => "RustBuffer".to_owned(),
+ FfiType::RustArcPtr(_) => "void *".to_owned(),
FfiType::ForeignBytes => unimplemented!("ForeignBytes not supported"),
- FfiType::ForeignExecutorHandle => unimplemented!("ForeignExecutorHandle not supported"),
- FfiType::ForeignExecutorCallback => {
- unimplemented!("ForeignExecutorCallback not supported")
- }
- FfiType::RustFutureHandle
- | FfiType::RustFutureContinuationCallback
- | FfiType::RustFutureContinuationData => {
- unimplemented!("Rust async functions not supported")
- }
+ FfiType::Handle => "uint64_t".to_owned(),
+ FfiType::RustCallStatus => "RustCallStatus".to_owned(),
+ FfiType::Callback(name) | FfiType::Struct(name) => name.to_owned(),
+ FfiType::VoidPointer => "void *".to_owned(),
+ FfiType::Reference(_) => unimplemented!("References not supported"),
}
- .to_owned()
}
}
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs
index efd7b42456..cd9af529a7 100644
--- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs
+++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs
@@ -92,7 +92,8 @@ pub impl Literal {
Literal::Enum(name, typ) => render_enum_literal(typ, name),
Literal::EmptyMap => "{}".to_string(),
Literal::EmptySequence => "[]".to_string(),
- Literal::Null => "null".to_string(),
+ Literal::Some { inner } => inner.render(),
+ Literal::None => "null".to_string(),
}
}
}
@@ -258,7 +259,6 @@ pub impl Type {
| Type::CallbackInterface { name, .. } => format!("Type{name}"),
Type::Timestamp => "Timestamp".into(),
Type::Duration => "Duration".into(),
- Type::ForeignExecutor => "ForeignExecutor".into(),
Type::Optional { inner_type } => format!("Optional{}", inner_type.canonical_name()),
Type::Sequence { inner_type } => format!("Sequence{}", inner_type.canonical_name()),
Type::Map {
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 {