diff --git a/.cargo/config.in b/.cargo/config.in index 54e3d6cdff05..0dc21164d301 100644 --- a/.cargo/config.in +++ b/.cargo/config.in @@ -12,11 +12,6 @@ git = "https://github.com/rust-minidump/minidump-writer.git" replace-with = "vendored-sources" rev = "75ada456c92a429704691a85e1cb42fef8cafc0d" -[source."https://github.com/mozilla/uniffi-rs.git"] -git = "https://github.com/mozilla/uniffi-rs.git" -replace-with = "vendored-sources" -rev = "bb2039f077a29dba0879372a67e764e6ace8e33f" - [source."https://github.com/mozilla/neqo"] git = "https://github.com/mozilla/neqo" replace-with = "vendored-sources" diff --git a/.clang-format-ignore b/.clang-format-ignore index 315877cf66c3..d6e5e9d0c769 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -63,12 +63,6 @@ widget/gtk/MPRISInterfaceDescription.h xpcom/reflect/xptcall/md/win32/.* xpcom/reflect/xptcall/md/unix/.* -# Askama template code, which isn't valid C++ in its original form -toolkit/components/uniffi-bindgen-gecko-js/src/templates/.* -# Generated from that template code -toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp -toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp - # Generated from ./tools/rewriting/ThirdPartyPaths.txt # awk '{print ""$1".*"}' ./tools/rewriting/ThirdPartyPaths.txt browser/components/translation/cld2/.* diff --git a/.eslintignore b/.eslintignore index abb5c8559fc1..0cc0e1b0f0a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -228,6 +228,3 @@ toolkit/components/backgroundtasks/defaults # Ignore pre-generated webpack and typescript transpiled files for translations browser/extensions/translations/extension/ - -# "scaffolding" used by uniffi which isn't valid JS in its original form. -toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/ diff --git a/Cargo.lock b/Cargo.lock index 025848fd92b8..aedf0219fe26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1549,18 +1549,6 @@ dependencies = [ "serde", ] -[[package]] -name = "extend" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5216e387a76eebaaf11f6d871ec8a4aae0b25f05456ee21f228e024b1b3610" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "fallible-iterator" version = "0.2.0" @@ -2176,11 +2164,6 @@ dependencies = [ "tokio-threadpool", "unic-langid", "unic-langid-ffi", - "uniffi-example-arithmetic", - "uniffi-example-geometry", - "uniffi-example-rondpoint", - "uniffi-example-sprites", - "uniffi-example-todolist", "url", "viaduct", "webext_storage_bridge", @@ -5619,75 +5602,6 @@ dependencies = [ "log", "paste", "static_assertions", - "uniffi_bindgen", -] - -[[package]] -name = "uniffi-bindgen-gecko-js" -version = "0.1.0" -dependencies = [ - "anyhow", - "askama", - "camino", - "clap", - "extend", - "heck", - "serde", - "toml 0.5.9", - "uniffi_bindgen", -] - -[[package]] -name = "uniffi-example-arithmetic" -version = "0.18.0" -source = "git+https://github.com/mozilla/uniffi-rs.git?rev=bb2039f077a29dba0879372a67e764e6ace8e33f#bb2039f077a29dba0879372a67e764e6ace8e33f" -dependencies = [ - "thiserror", - "uniffi", - "uniffi_build", - "uniffi_macros", -] - -[[package]] -name = "uniffi-example-geometry" -version = "0.18.0" -source = "git+https://github.com/mozilla/uniffi-rs.git?rev=bb2039f077a29dba0879372a67e764e6ace8e33f#bb2039f077a29dba0879372a67e764e6ace8e33f" -dependencies = [ - "uniffi", - "uniffi_build", - "uniffi_macros", -] - -[[package]] -name = "uniffi-example-rondpoint" -version = "0.18.0" -source = "git+https://github.com/mozilla/uniffi-rs.git?rev=bb2039f077a29dba0879372a67e764e6ace8e33f#bb2039f077a29dba0879372a67e764e6ace8e33f" -dependencies = [ - "uniffi", - "uniffi_build", - "uniffi_macros", -] - -[[package]] -name = "uniffi-example-sprites" -version = "0.18.0" -source = "git+https://github.com/mozilla/uniffi-rs.git?rev=bb2039f077a29dba0879372a67e764e6ace8e33f#bb2039f077a29dba0879372a67e764e6ace8e33f" -dependencies = [ - "uniffi", - "uniffi_build", - "uniffi_macros", -] - -[[package]] -name = "uniffi-example-todolist" -version = "0.18.0" -source = "git+https://github.com/mozilla/uniffi-rs.git?rev=bb2039f077a29dba0879372a67e764e6ace8e33f#bb2039f077a29dba0879372a67e764e6ace8e33f" -dependencies = [ - "lazy_static", - "thiserror", - "uniffi", - "uniffi_build", - "uniffi_macros", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b229338287fb..767120d7198d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "security/manager/ssl/ipcclientcerts", "security/manager/ssl/osclientcerts", "testing/geckodriver", - "toolkit/components/uniffi-bindgen-gecko-js", "toolkit/crashreporter/rust_minidump_writer_linux", "toolkit/crashreporter/mozwer-rust", "toolkit/library/gtest/rust", @@ -165,16 +164,3 @@ path = "third_party/rust/mio-0.6.23" # https://github.com/mozilla/neqo/pull/1350 [patch."https://github.com/mozilla/neqo"] neqo-common = { path = "third_party/rust/neqo-common" } - -# These are used to test UniFFI functionality. We haven't figured out how we -# want to publish these yet, so they are only accessible via git. This works -# okay, but it means that their dependencies on UniFFI crates will normally -# also be the git versions. Patch them to use the published versions to avoid -# duplicate crates. - -[patch."https://github.com/mozilla/uniffi-rs.git"] -uniffi = "0.19" -uniffi_bindgen = "0.19" -uniffi_build = "0.19" -uniffi_macros = "0.19" -weedle2 = "3.0.0" diff --git a/dom/chrome-webidl/UniFFI.webidl b/dom/chrome-webidl/UniFFI.webidl deleted file mode 100644 index 7840dd6af136..000000000000 --- a/dom/chrome-webidl/UniFFI.webidl +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Interface for making UniFFI scaffolding calls -// -// Gecko uses UniFFI to generate privileged JS bindings for Rust components. -// UniFFI defines a C-ABI FFI layer for calling into Rust, called the -// scaffolding. This interface is a bridge that allows the JS code to make -// scaffolding calls -// -// See https://mozilla.github.io/uniffi-rs/ for details. - -// Opaque type used to represent a pointer from Rust -[ChromeOnly, Exposed=Window] -interface UniFFIPointer {}; - -// Types that can be passed or returned from scaffolding functions -// -// - double is used for all numeric types (including bool, which the JS code -// coerces to an int) -// - ArrayBuffer is used for RustBuffer -// - UniFFIPointer is used for Arc pointers -typedef (double or ArrayBuffer or UniFFIPointer) UniFFIScaffoldingType; - -// The result of a call into UniFFI scaffolding call -enum UniFFIScaffoldingCallCode { - "success", // Successful return - "error", // Rust Err return - "internal-error", // Internal/unexpected error -}; - -dictionary UniFFIScaffoldingCallResult { - required UniFFIScaffoldingCallCode code; - // For success, this will be the return value for non-void returns - // For error, this will be an ArrayBuffer storing the serialized error value - UniFFIScaffoldingType data; - // For internal-error, this will be a utf-8 string describing the error - ByteString internalErrorMessage; -}; - -// Functions to facilitate UniFFI scaffolding calls -// -// These should only be called by the generated code from UniFFI. -[ChromeOnly, Exposed=Window] -namespace UniFFIScaffolding { - [Throws] - Promise callAsync(unsigned long long id, UniFFIScaffoldingType... args); - - [Throws] - UniFFIScaffoldingCallResult callSync(unsigned long long id, UniFFIScaffoldingType... args); - - [Throws] - UniFFIPointer readPointer(unsigned long long id, ArrayBuffer buff, long position); - - [Throws] - void writePointer(unsigned long long id, UniFFIPointer ptr, ArrayBuffer buff, long position); -}; diff --git a/dom/chrome-webidl/moz.build b/dom/chrome-webidl/moz.build index f96396ecd3a7..1cc38b585b09 100644 --- a/dom/chrome-webidl/moz.build +++ b/dom/chrome-webidl/moz.build @@ -81,7 +81,6 @@ WEBIDL_FILES = [ "SessionStoreUtils.webidl", "StructuredCloneHolder.webidl", "TelemetryStopwatch.webidl", - "UniFFI.webidl", "UserInteraction.webidl", "WebExtensionContentScript.webidl", "WebExtensionPolicy.webidl", diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 539a8e299a24..e3ba580f9b12 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -99,12 +99,6 @@ criteria = "safe-to-deploy" delta = "0.4.0 -> 0.5.0" notes = "The repository for this crate belongs in the Mozilla org." -[[audits.extend]] -who = "Ben Dean-Kawamura " -criteria = "safe-to-deploy" -version = "1.1.2" -notes = "Inspected the crate and noted that the impl block comes directly from the proc-macro input. If no new code can be added by this crate, I don't think there can be any issues." - [[audits.flagset]] who = "Ryan Hunt " criteria = "safe-to-deploy" diff --git a/third_party/rust/extend/.cargo-checksum.json b/third_party/rust/extend/.cargo-checksum.json deleted file mode 100644 index 3ef73912755b..000000000000 --- a/third_party/rust/extend/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"CHANGELOG.md":"910cd2057d356b18cd4f21791bc23956734a83b0f58701ec0d0d03405f5c21df","Cargo.toml":"928b8b97607b3589b85a6d4d00fb1cf64b78bee6354c303d8f49fbfa2ca5bdae","LICENSE":"db0efd0bb80126f32214f478434536d07d86a30658fb209d8b543b7261492a2b","README.md":"0872b2b15ec22732a09b121a31cdd8f8cfc80566f671566e4a7fb6b52a742a2e","deny.toml":"60448e9313f1883a7adf30713fcca789c454e77228105926024ce3abe9293100","rustfmt.toml":"9bbb759b3914c49c8060bcdeeb7786f4aec083d30bcfe236bbd48d8388d06103","src/lib.rs":"85bd23c064c78dcd141cb2fecca6fff2ee7e1dfb4cf19b74ab97ef30d51f6f03","tests/compile_fail/double_vis.rs":"524e8bc996f5a45de3d15f0c741d4f3414004e9c636c52de0f011785cc535109","tests/compile_fail/double_vis.stderr":"3748e67e6f41bd5624946ad7cdc4e2b30a9d0b5e76bc27c19ecc9d62da733978","tests/compile_fail/supertraits_are_actually_included.rs":"c03980316c4e71ceb7e80ab7011f00b6f1f8f89906670e9823267a4118f72853","tests/compile_fail/supertraits_are_actually_included.stderr":"835e79bb1bceb48e9db5f0a410c57af51c856e17917ef72f65e3ae2af79d97ec","tests/compile_pass/associated_constants.rs":"f3e56405650ddd31c33e932846553e88fe7181585e0f09a7414d50d521b0f103","tests/compile_pass/async_trait.rs":"9138801d67dbe20ed87fdb3f48bb968f0bfa11fe2d27414d5ea5ea7a6e44bb35","tests/compile_pass/changing_extension_trait_name.rs":"046e7a66151ce05c3515b4bea36be72f83b98f3bdb06fa6f065ad6fc373e19f2","tests/compile_pass/complex_trait_name.rs":"5a8c3588c26df07973739fbb85619d0de480cc8c992611dfc2dbcb9ab3c6e2b6","tests/compile_pass/double_ext_on_same_type.rs":"0e4d16fe9059f0325e4ad1337d53738876633b0533f9a2d4e9714ddada96eb4d","tests/compile_pass/extension_on_complex_types.rs":"88bdf979e1f399d7f9824165730b33884bc9c46347d246f8cc12e0e2039642a1","tests/compile_pass/generics.rs":"367f089e8010d1c98ccc975b03acb6cf03810793e1198105f75c006eafd52bb8","tests/compile_pass/hello_world.rs":"1961cfa634143974f0d64b26f817ac3148375faa5cf5864d63f0127d3af8099e","tests/compile_pass/issue_2.rs":"a14d5e2179b74ff71c5357e8a4f1a9ac228a711196edd40c12719565c8dfaa21","tests/compile_pass/more_than_one_extension.rs":"1d7486e4e9e4095d7e7f42aac878d836f021c49fbe26c31cb13fe6a0415a8558","tests/compile_pass/multiple_config.rs":"dc3b06e4fafbb7236b5bc49f9a5e9693241c07118da8886dd0752b895ff27425","tests/compile_pass/multiple_generic_params.rs":"2ac052ea7b818b6d45ee8070cf6ec18953419473f711375cafbe7283244b5743","tests/compile_pass/pub_impl.rs":"8dfcba21fbbc45efcf85b66fca2d187022569e72d4b10b57047eddda67a1725b","tests/compile_pass/ref_and_ref_mut.rs":"d1086a23809cbd8f87487677073238c3657a8a98fafc63a688eb9d622bf2eb11","tests/compile_pass/sized.rs":"baceaaabcf368b3c72e6d27fea72aadde11d97d9d153c35df5e2d89fb3da4e3e","tests/compile_pass/super_trait.rs":"07448e1fe2b9018125ccaabf7db1e2a244788519bb42117f8e437e48358eb2f0","tests/compile_pass/visibility_config.rs":"64846014a63327661fb250cdb726cce532ed82b1cea5cb83308526bcba22b4be"},"package":"5c5216e387a76eebaaf11f6d871ec8a4aae0b25f05456ee21f228e024b1b3610"} \ No newline at end of file diff --git a/third_party/rust/extend/CHANGELOG.md b/third_party/rust/extend/CHANGELOG.md deleted file mode 100644 index f17149a2eb25..000000000000 --- a/third_party/rust/extend/CHANGELOG.md +++ /dev/null @@ -1,79 +0,0 @@ -# Change Log - -All user visible changes to this project will be documented in this file. -This project adheres to [Semantic Versioning](http://semver.org/), as described -for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md) - -## Unreleased - -None. - -### Breaking changes - -None. - -## 1.1.2 - 2021-09-02 - -- Fix using `pub impl` with `#[async_trait]`. - -## 1.1.1 - 2021-06-12 - -- Fix name collision for extensions on `&T` and `&mut T`. The generated traits - now get different names. - -## 1.1.0 - 2021-06-12 - -- Support setting visibility of the generated trait directly on the `impl` - block. For example: `pub impl i32 { ... }`. -- Add `#[ext_sized]` for adding `Sized` supertrait. - -## 1.0.1 - 2021-02-14 - -- Update maintenance status. - -## 1.0.0 - 2021-01-30 - -- Support extensions on bare functions types (things like `fn(i32) -> bool`). -- Support extensions on trait objects (things like `dyn Send + Sync`). - -## 0.3.0 - 2020-08-31 - -- Add async-trait compatibility. - -### Breaking changes - -- Other attributes put on the `impl` would previously only be included on the generated trait. They're now included on both the trait and the implementation. - -## 0.2.1 - 2020-08-29 - -- Fix documentation link in Cargo.toml. -- Use more correct repository URL in Cargo.toml. - -## 0.2.0 - 2020-08-29 - -- Handle unnamed extensions on the same generic type with different type parameters. For example `Option` and `Option`. Previously we would generate the same name of both hidden traits which wouldn't compile. -- Support associated constants in extension impls. - -### Breaking changes - -- Generated traits are no longer sealed and the `sealed` argument previously supported by `#[ext]` has been removed. Making the traits sealed lead to lots of complexity that we didn't think brought much value. - -## 0.1.1 - 2020-02-22 - -- Add support for specifying supertraits of the generated trait [#4](https://github.com/davidpdrsn/extend/pull/4). - -## 0.1.0 - -- Support adding extensions to the ["never type"](https://doc.rust-lang.org/std/primitive.never.html). - -### Breaking changes - -- Simplify names of traits generates for complex types. - -## 0.0.2 - -- Move "trybuild" to dev-dependency. - -## 0.0.1 - -Initial release. diff --git a/third_party/rust/extend/Cargo.toml b/third_party/rust/extend/Cargo.toml deleted file mode 100644 index dcc2ebae1533..000000000000 --- a/third_party/rust/extend/Cargo.toml +++ /dev/null @@ -1,48 +0,0 @@ -# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies -# -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) - -[package] -edition = "2018" -name = "extend" -version = "1.1.2" -authors = ["David Pedersen "] -description = "Create extensions for types you don't own with extension traits but without the boilerplate." -homepage = "https://github.com/davidpdrsn/extend" -documentation = "https://docs.rs/extend" -readme = "README.md" -keywords = ["extension", "trait"] -categories = ["rust-patterns"] -license = "MIT" -repository = "https://github.com/davidpdrsn/extend.git" - -[lib] -path = "src/lib.rs" -proc-macro = true -[dependencies.proc-macro-error] -version = "1" - -[dependencies.proc-macro2] -version = "1" - -[dependencies.quote] -version = "1" - -[dependencies.syn] -version = "1" -features = ["full", "extra-traits", "visit"] -[dev-dependencies.async-trait] -version = "0.1.40" - -[dev-dependencies.trybuild] -version = "1.0.17" -[badges.maintenance] -status = "passively-maintained" diff --git a/third_party/rust/extend/LICENSE b/third_party/rust/extend/LICENSE deleted file mode 100644 index 0cf5bc730187..000000000000 --- a/third_party/rust/extend/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -MIT License Copyright (c) 2020 David Pedersen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is furnished -to do so, subject to the following conditions: - -The above copyright notice and this permission notice (including the next -paragraph) shall be included in all copies or substantial portions of the -Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS -OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF -OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/third_party/rust/extend/README.md b/third_party/rust/extend/README.md deleted file mode 100644 index ffa19e951a66..000000000000 --- a/third_party/rust/extend/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# extend - -[![Crates.io](https://img.shields.io/crates/v/extend.svg)](https://crates.io/crates/extend) -[![Docs](https://docs.rs/extend/badge.svg)](https://docs.rs/extend) -[![dependency status](https://deps.rs/repo/github/davidpdrsn/extend/status.svg)](https://deps.rs/repo/github/davidpdrsn/extend) -[![Build status](https://github.com/davidpdrsn/extend/workflows/CI/badge.svg)](https://github.com/davidpdrsn/extend/actions) -![maintenance-status](https://img.shields.io/badge/maintenance-passively--maintained-yellowgreen.svg) - -Create extensions for types you don't own with [extension traits] but without the boilerplate. - -Example: - -```rust -use extend::ext; - -#[ext] -impl Vec { - fn sorted(mut self) -> Self { - self.sort(); - self - } -} - -fn main() { - assert_eq!( - vec![1, 2, 3], - vec![2, 3, 1].sorted(), - ); -} -``` - -[extension traits]: https://dev.to/matsimitsu/extending-existing-functionality-in-rust-with-traits-in-rust-3622 diff --git a/third_party/rust/extend/deny.toml b/third_party/rust/extend/deny.toml deleted file mode 100644 index 57816c7a0dc4..000000000000 --- a/third_party/rust/extend/deny.toml +++ /dev/null @@ -1,47 +0,0 @@ -targets = [] - -[advisories] -db-path = "~/.cargo/advisory-db" -db-urls = ["https://github.com/rustsec/advisory-db"] -vulnerability = "deny" -unmaintained = "warn" -yanked = "warn" -notice = "warn" -ignore = [] - -[licenses] -unlicensed = "deny" -allow = [ - "MIT", - "Apache-2.0", -] -deny = [] -copyleft = "warn" -allow-osi-fsf-free = "neither" -default = "deny" -confidence-threshold = 0.8 -exceptions = [] - -[licenses.private] -ignore = false -registries = [] - -[bans] -multiple-versions = "deny" -wildcards = "allow" -highlight = "all" -allow = [] -deny = [] -skip = [] -skip-tree = [] - -[sources] -unknown-registry = "warn" -unknown-git = "warn" -allow-registry = ["https://github.com/rust-lang/crates.io-index"] -allow-git = [] - -[sources.allow-org] -github = [] -gitlab = [] -bitbucket = [] diff --git a/third_party/rust/extend/rustfmt.toml b/third_party/rust/extend/rustfmt.toml deleted file mode 100644 index 7d2cf549dcea..000000000000 --- a/third_party/rust/extend/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -merge_imports = true diff --git a/third_party/rust/extend/src/lib.rs b/third_party/rust/extend/src/lib.rs deleted file mode 100644 index 9b8188a4a071..000000000000 --- a/third_party/rust/extend/src/lib.rs +++ /dev/null @@ -1,620 +0,0 @@ -//! Create extensions for types you don't own with [extension traits] but without the boilerplate. -//! -//! Example: -//! -//! ```rust -//! use extend::ext; -//! -//! #[ext] -//! impl Vec { -//! fn sorted(mut self) -> Self { -//! self.sort(); -//! self -//! } -//! } -//! -//! fn main() { -//! assert_eq!( -//! vec![1, 2, 3], -//! vec![2, 3, 1].sorted(), -//! ); -//! } -//! ``` -//! -//! # How does it work? -//! -//! Under the hood it generates a trait with methods in your `impl` and implements those for the -//! type you specify. The code shown above expands roughly to: -//! -//! ```rust -//! trait VecExt { -//! fn sorted(self) -> Self; -//! } -//! -//! impl VecExt for Vec { -//! fn sorted(mut self) -> Self { -//! self.sort(); -//! self -//! } -//! } -//! ``` -//! -//! # Supported items -//! -//! Extensions can contain methods or associated constants: -//! -//! ```rust -//! use extend::ext; -//! -//! #[ext] -//! impl String { -//! const CONSTANT: &'static str = "FOO"; -//! -//! fn method() { -//! // ... -//! # todo!() -//! } -//! } -//! ``` -//! -//! # Configuration -//! -//! You can configure: -//! -//! - The visibility of the trait. Use `pub impl ...` to generate `pub trait ...`. The default -//! visibility is private. -//! - The name of the generated extension trait. Example: `#[ext(name = MyExt)]`. By default we -//! generate a name based on what you extend. -//! - Which supertraits the generated extension trait should have. Default is no supertraits. -//! Example: `#[ext(supertraits = Default + Clone)]`. -//! -//! More examples: -//! -//! ```rust -//! use extend::ext; -//! -//! #[ext(name = SortedVecExt)] -//! impl Vec { -//! fn sorted(mut self) -> Self { -//! self.sort(); -//! self -//! } -//! } -//! -//! #[ext] -//! pub(crate) impl i32 { -//! fn double(self) -> i32 { -//! self * 2 -//! } -//! } -//! -//! #[ext(name = ResultSafeUnwrapExt)] -//! pub impl Result { -//! fn safe_unwrap(self) -> T { -//! match self { -//! Ok(t) => t, -//! Err(_) => unreachable!(), -//! } -//! } -//! } -//! -//! #[ext(supertraits = Default + Clone)] -//! impl String { -//! fn my_length(self) -> usize { -//! self.len() -//! } -//! } -//! ``` -//! -//! For backwards compatibility you can also declare the visibility as the first argument to `#[ext]`: -//! -//! ``` -//! use extend::ext; -//! -//! #[ext(pub)] -//! impl i32 { -//! fn double(self) -> i32 { -//! self * 2 -//! } -//! } -//! ``` -//! -//! # async-trait compatibility -//! -//! Async extensions are supported via [async-trait](https://crates.io/crates/async-trait). -//! -//! Be aware that you need to add `#[async_trait]` _below_ `#[ext]`. Otherwise the `ext` macro -//! cannot see the `#[async_trait]` attribute and pass it along in the generated code. -//! -//! Example: -//! -//! ``` -//! use extend::ext; -//! use async_trait::async_trait; -//! -//! #[ext] -//! #[async_trait] -//! impl String { -//! async fn read_file() -> String { -//! // ... -//! # todo!() -//! } -//! } -//! ``` -//! -//! # Other attributes -//! -//! Other attributes provided _below_ `#[ext]` will be passed along to both the generated trait and -//! the implementation. See [async-trait compatibility](#async-trait-compatibility) above for an -//! example. -//! -//! [extension traits]: https://dev.to/matsimitsu/extending-existing-functionality-in-rust-with-traits-in-rust-3622 - -#![doc(html_root_url = "https://docs.rs/extend/1.1.2")] -#![allow(clippy::let_and_return)] -#![deny( - unused_variables, - mutable_borrow_reservation_conflict, - dead_code, - unused_must_use, - unused_imports -)] - -use proc_macro2::TokenStream; -use proc_macro_error::*; -use quote::{format_ident, quote, ToTokens}; -use syn::{ - parse::{self, Parse, ParseStream}, - parse_macro_input, parse_quote, - punctuated::Punctuated, - spanned::Spanned, - token::{Add, Semi}, - Ident, ImplItem, ItemImpl, Token, TraitItemConst, TraitItemMethod, Type, TypeArray, TypeBareFn, - TypeGroup, TypeNever, TypeParamBound, TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, - TypeTraitObject, TypeTuple, Visibility, -}; - -#[derive(Debug)] -struct Input { - item_impl: ItemImpl, - vis: Option, -} - -impl Parse for Input { - fn parse(input: ParseStream) -> syn::Result { - let mut attributes = Vec::new(); - if input.peek(syn::Token![#]) { - attributes.extend(syn::Attribute::parse_outer(input)?); - } - - let vis = input - .parse::() - .ok() - .filter(|vis| vis != &Visibility::Inherited); - - let mut item_impl = input.parse::()?; - item_impl.attrs.extend(attributes); - - Ok(Self { item_impl, vis }) - } -} - -/// See crate docs for more info. -#[proc_macro_attribute] -#[proc_macro_error] -#[allow(clippy::unneeded_field_pattern)] -pub fn ext( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let item = parse_macro_input!(item as Input); - let config = parse_macro_input!(attr as Config); - go(item, config) -} - -/// Like [`ext`](macro@crate::ext) but always add `Sized` as a supertrait. -/// -/// This is provided as a convenience for generating extension traits that require `Self: Sized` -/// such as: -/// -/// ``` -/// use extend::ext_sized; -/// -/// #[ext_sized] -/// impl i32 { -/// fn requires_sized(self) -> Option { -/// Some(self) -/// } -/// } -/// ``` -#[proc_macro_attribute] -#[proc_macro_error] -#[allow(clippy::unneeded_field_pattern)] -pub fn ext_sized( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let item = parse_macro_input!(item as Input); - let mut config: Config = parse_macro_input!(attr as Config); - - config.supertraits = if let Some(supertraits) = config.supertraits.take() { - Some(parse_quote!(#supertraits + Sized)) - } else { - Some(parse_quote!(Sized)) - }; - - go(item, config) -} - -fn go(item: Input, mut config: Config) -> proc_macro::TokenStream { - if let Some(vis) = item.vis { - if config.visibility != Visibility::Inherited { - abort!( - config.visibility.span(), - "Cannot set visibility on `#[ext]` and `impl` block" - ); - } - - config.visibility = vis; - } - - let ItemImpl { - attrs, - unsafety, - generics, - trait_, - self_ty, - items, - // What is defaultness? - defaultness: _, - impl_token: _, - brace_token: _, - } = item.item_impl; - - if let Some((_, path, _)) = trait_ { - abort!(path.span(), "Trait impls cannot be used for #[ext]"); - } - - let self_ty = parse_self_ty(&self_ty); - - let ext_trait_name = config - .ext_trait_name - .unwrap_or_else(|| ext_trait_name(&self_ty)); - - let MethodsAndConsts { - trait_methods, - trait_consts, - } = extract_allowed_items(&items); - - let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - - let visibility = &config.visibility; - - let mut all_supertraits = Vec::::new(); - - if let Some(supertraits_from_config) = config.supertraits { - all_supertraits.extend(supertraits_from_config); - } - - let supertraits_quoted = if all_supertraits.is_empty() { - quote! {} - } else { - let supertraits_quoted = punctuated_from_iter::<_, _, Add>(all_supertraits); - quote! { : #supertraits_quoted } - }; - - let code = (quote! { - #[allow(non_camel_case_types)] - #(#attrs)* - #visibility - #unsafety - trait #ext_trait_name #impl_generics #supertraits_quoted #where_clause { - #( - #trait_consts - )* - - #( - #[allow( - patterns_in_fns_without_body, - clippy::inline_fn_without_body, - unused_attributes - )] - #trait_methods - )* - } - - #(#attrs)* - impl #impl_generics #ext_trait_name #ty_generics for #self_ty #where_clause { - #(#items)* - } - }) - .into(); - - code -} - -#[derive(Debug, Clone)] -enum ExtType<'a> { - Array(&'a TypeArray), - Group(&'a TypeGroup), - Never(&'a TypeNever), - Paren(&'a TypeParen), - Path(&'a TypePath), - Ptr(&'a TypePtr), - Reference(&'a TypeReference), - Slice(&'a TypeSlice), - Tuple(&'a TypeTuple), - BareFn(&'a TypeBareFn), - TraitObject(&'a TypeTraitObject), -} - -#[allow(clippy::wildcard_in_or_patterns)] -fn parse_self_ty(self_ty: &Type) -> ExtType { - match self_ty { - Type::Array(inner) => ExtType::Array(inner), - Type::Group(inner) => ExtType::Group(inner), - Type::Never(inner) => ExtType::Never(inner), - Type::Paren(inner) => ExtType::Paren(inner), - Type::Path(inner) => ExtType::Path(inner), - Type::Ptr(inner) => ExtType::Ptr(inner), - Type::Reference(inner) => ExtType::Reference(inner), - Type::Slice(inner) => ExtType::Slice(inner), - Type::Tuple(inner) => ExtType::Tuple(inner), - Type::BareFn(inner) => ExtType::BareFn(inner), - Type::TraitObject(inner) => ExtType::TraitObject(inner), - - Type::ImplTrait(_) | Type::Infer(_) | Type::Macro(_) | Type::Verbatim(_) | _ => abort!( - self_ty.span(), - "#[ext] is not supported for this kind of type" - ), - } -} - -impl<'a> From<&'a Type> for ExtType<'a> { - fn from(inner: &'a Type) -> ExtType<'a> { - parse_self_ty(inner) - } -} - -impl<'a> ToTokens for ExtType<'a> { - fn to_tokens(&self, tokens: &mut TokenStream) { - match self { - ExtType::Array(inner) => inner.to_tokens(tokens), - ExtType::Group(inner) => inner.to_tokens(tokens), - ExtType::Never(inner) => inner.to_tokens(tokens), - ExtType::Paren(inner) => inner.to_tokens(tokens), - ExtType::Path(inner) => inner.to_tokens(tokens), - ExtType::Ptr(inner) => inner.to_tokens(tokens), - ExtType::Reference(inner) => inner.to_tokens(tokens), - ExtType::Slice(inner) => inner.to_tokens(tokens), - ExtType::Tuple(inner) => inner.to_tokens(tokens), - ExtType::BareFn(inner) => inner.to_tokens(tokens), - ExtType::TraitObject(inner) => inner.to_tokens(tokens), - } - } -} - -fn ext_trait_name(self_ty: &ExtType) -> Ident { - fn inner_self_ty(self_ty: &ExtType) -> Ident { - match self_ty { - ExtType::Path(inner) => find_and_combine_idents(inner), - ExtType::Reference(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - if inner.mutability.is_some() { - format_ident!("RefMut{}", name) - } else { - format_ident!("Ref{}", name) - } - } - ExtType::Array(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - format_ident!("ListOf{}", name) - } - ExtType::Group(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - format_ident!("Group{}", name) - } - ExtType::Paren(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - format_ident!("Paren{}", name) - } - ExtType::Ptr(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - format_ident!("PointerTo{}", name) - } - ExtType::Slice(inner) => { - let name = inner_self_ty(&(&*inner.elem).into()); - format_ident!("SliceOf{}", name) - } - ExtType::Tuple(inner) => { - let mut name = format_ident!("TupleOf"); - for elem in &inner.elems { - name = format_ident!("{}{}", name, inner_self_ty(&elem.into())); - } - name - } - ExtType::Never(_) => format_ident!("Never"), - ExtType::BareFn(inner) => { - let mut name = format_ident!("BareFn"); - for input in inner.inputs.iter() { - name = format_ident!("{}{}", name, inner_self_ty(&(&input.ty).into())); - } - match &inner.output { - syn::ReturnType::Default => { - name = format_ident!("{}Unit", name); - } - syn::ReturnType::Type(_, ty) => { - name = format_ident!("{}{}", name, inner_self_ty(&(&**ty).into())); - } - } - name - } - ExtType::TraitObject(inner) => { - let mut name = format_ident!("TraitObject"); - for bound in inner.bounds.iter() { - match bound { - TypeParamBound::Trait(bound) => { - for segment in bound.path.segments.iter() { - name = format_ident!("{}{}", name, segment.ident); - } - } - TypeParamBound::Lifetime(lifetime) => { - name = format_ident!("{}{}", name, lifetime.ident); - } - } - } - name - } - } - } - - format_ident!("{}Ext", inner_self_ty(self_ty)) -} - -fn find_and_combine_idents(type_path: &TypePath) -> Ident { - use syn::visit::{self, Visit}; - - struct IdentVisitor<'a>(Vec<&'a Ident>); - - impl<'a> Visit<'a> for IdentVisitor<'a> { - fn visit_ident(&mut self, i: &'a Ident) { - self.0.push(i); - } - } - - let mut visitor = IdentVisitor(Vec::new()); - visit::visit_type_path(&mut visitor, type_path); - let idents = visitor.0; - - if idents.is_empty() { - abort!(type_path.span(), "Empty type path") - } else { - let start = &idents[0].span(); - let combined_span = idents - .iter() - .map(|i| i.span()) - .fold(*start, |a, b| a.join(b).unwrap_or(a)); - - let combined_name = idents.iter().map(|i| i.to_string()).collect::(); - - Ident::new(&combined_name, combined_span) - } -} - -#[derive(Debug, Default)] -struct MethodsAndConsts { - trait_methods: Vec, - trait_consts: Vec, -} - -#[allow(clippy::wildcard_in_or_patterns)] -fn extract_allowed_items(items: &[ImplItem]) -> MethodsAndConsts { - let mut acc = MethodsAndConsts::default(); - for item in items { - match item { - ImplItem::Method(method) => acc.trait_methods.push(TraitItemMethod { - attrs: method.attrs.clone(), - sig: method.sig.clone(), - default: None, - semi_token: Some(Semi::default()), - }), - ImplItem::Const(const_) => acc.trait_consts.push(TraitItemConst { - attrs: const_.attrs.clone(), - const_token: Default::default(), - ident: const_.ident.clone(), - colon_token: Default::default(), - ty: const_.ty.clone(), - default: None, - semi_token: Default::default(), - }), - ImplItem::Type(_) => abort!( - item.span(), - "Associated types are not allowed in #[ext] impls" - ), - ImplItem::Macro(_) => abort!(item.span(), "Macros are not allowed in #[ext] impls"), - ImplItem::Verbatim(_) | _ => abort!(item.span(), "Not allowed in #[ext] impls"), - } - } - acc -} - -#[derive(Debug)] -struct Config { - ext_trait_name: Option, - visibility: Visibility, - supertraits: Option>, -} - -impl Parse for Config { - fn parse(input: ParseStream) -> parse::Result { - let mut config = Config::default(); - - if let Ok(visibility) = input.parse::() { - config.visibility = visibility; - } - - input.parse::().ok(); - - while !input.is_empty() { - let ident = input.parse::()?; - input.parse::()?; - - match &*ident.to_string() { - "name" => { - config.ext_trait_name = Some(input.parse()?); - } - "supertraits" => { - config.supertraits = - Some(Punctuated::::parse_terminated(input)?); - } - _ => abort!(ident.span(), "Unknown configuration name"), - } - - input.parse::().ok(); - } - - Ok(config) - } -} - -impl Default for Config { - fn default() -> Self { - Self { - ext_trait_name: None, - visibility: Visibility::Inherited, - supertraits: None, - } - } -} - -fn punctuated_from_iter(i: I) -> Punctuated -where - P: Default, - I: IntoIterator, -{ - let mut iter = i.into_iter().peekable(); - let mut acc = Punctuated::default(); - - while let Some(item) = iter.next() { - acc.push_value(item); - - if iter.peek().is_some() { - acc.push_punct(P::default()); - } - } - - acc -} - -#[cfg(test)] -mod test { - #[allow(unused_imports)] - use super::*; - - #[test] - fn test_ui() { - let t = trybuild::TestCases::new(); - t.pass("tests/compile_pass/*.rs"); - t.compile_fail("tests/compile_fail/*.rs"); - } -} diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.rs b/third_party/rust/extend/tests/compile_fail/double_vis.rs deleted file mode 100644 index 4e0e135ad3e1..000000000000 --- a/third_party/rust/extend/tests/compile_fail/double_vis.rs +++ /dev/null @@ -1,14 +0,0 @@ -mod a { - use extend::ext; - - #[ext(pub(super))] - pub impl i32 { - fn foo() -> Foo { - Foo - } - } - - pub struct Foo; -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.stderr b/third_party/rust/extend/tests/compile_fail/double_vis.stderr deleted file mode 100644 index c98b614935d8..000000000000 --- a/third_party/rust/extend/tests/compile_fail/double_vis.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: Cannot set visibility on `#[ext]` and `impl` block - --> $DIR/double_vis.rs:4:11 - | -4 | #[ext(pub(super))] - | ^^^ diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs deleted file mode 100644 index 5fba303138b6..000000000000 --- a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs +++ /dev/null @@ -1,14 +0,0 @@ -use extend::ext; - -trait MyTrait {} - -#[ext(supertraits = MyTrait)] -impl String { - fn my_len(&self) -> usize { - self.len() - } -} - -fn main() { - assert_eq!(String::new().my_len(), 0); -} diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr deleted file mode 100644 index 60059f73fb66..000000000000 --- a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error[E0277]: the trait bound `String: MyTrait` is not satisfied - --> $DIR/supertraits_are_actually_included.rs:6:6 - | -5 | #[ext(supertraits = MyTrait)] - | ------- required by this bound in `StringExt` -6 | impl String { - | ^^^^^^ - | | - | the trait `MyTrait` is not implemented for `String` - | required by a bound in this diff --git a/third_party/rust/extend/tests/compile_pass/associated_constants.rs b/third_party/rust/extend/tests/compile_pass/associated_constants.rs deleted file mode 100644 index 5cb982c6a4b9..000000000000 --- a/third_party/rust/extend/tests/compile_pass/associated_constants.rs +++ /dev/null @@ -1,10 +0,0 @@ -use extend::ext; - -#[ext] -impl Option { - const FOO: usize = 1; -} - -fn main() { - assert_eq!(Option::::FOO, 1); -} diff --git a/third_party/rust/extend/tests/compile_pass/async_trait.rs b/third_party/rust/extend/tests/compile_pass/async_trait.rs deleted file mode 100644 index 067bdc9bb788..000000000000 --- a/third_party/rust/extend/tests/compile_pass/async_trait.rs +++ /dev/null @@ -1,25 +0,0 @@ -use extend::ext; -use async_trait::async_trait; - -#[ext] -#[async_trait] -impl String { - async fn foo() -> usize { - 1 - } -} - -#[ext] -#[async_trait] -pub impl i32 { - async fn bar() -> usize { - 1 - } -} - -async fn foo() { - let _: usize = String::foo().await; - let _: usize = i32::bar().await; -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs b/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs deleted file mode 100644 index fc83b1933946..000000000000 --- a/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs +++ /dev/null @@ -1,10 +0,0 @@ -use extend::ext; - -#[ext(name = Foo)] -impl i32 { - fn foo() {} -} - -fn main() { - ::foo(); -} diff --git a/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs b/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs deleted file mode 100644 index 3457495132f2..000000000000 --- a/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs +++ /dev/null @@ -1,16 +0,0 @@ -mod foo { - use extend::ext; - - #[ext(pub)] - impl (T1, T2, T3) { - fn size(&self) -> usize { - 3 - } - } -} - -fn main() { - use foo::TupleOfT1T2T3Ext; - - assert_eq!(3, (0, 0, 0).size()); -} diff --git a/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs b/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs deleted file mode 100644 index 972d530fa8a6..000000000000 --- a/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs +++ /dev/null @@ -1,17 +0,0 @@ -use extend::ext; - -#[ext] -impl Option { - fn foo() -> usize { - 1 - } -} - -#[ext] -impl Option { - fn bar() -> i32 { - 1 - } -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs b/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs deleted file mode 100644 index 20dfb7ca9090..000000000000 --- a/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs +++ /dev/null @@ -1,58 +0,0 @@ -use extend::ext; - -#[ext] -impl<'a> &'a str { - fn foo(self) {} -} - -#[ext] -impl [T; 3] { - fn foo(self) {} -} - -#[ext] -impl *const i32 { - fn foo(self) {} -} - -#[ext] -impl [T] { - fn foo(&self) {} -} - -#[ext] -impl<'a, T> &'a [T] { - fn foo(self) {} -} - -#[ext] -impl (i32, i64) { - fn foo(self) {} -} - -#[ext] -impl fn(i32) -> bool { - fn foo(self) {} -} - -fn bare_fn(_: i32) -> bool { - false -} - -#[ext] -impl dyn Send + Sync + 'static {} - -fn main() { - "".foo(); - - [1, 2, 3].foo(); - - let ptr: *const i32 = &123; - ptr.foo(); - - &[1, 2, 3].foo(); - - (1i32, 1i64).foo(); - - (bare_fn as fn(i32) -> bool).foo(); -} diff --git a/third_party/rust/extend/tests/compile_pass/generics.rs b/third_party/rust/extend/tests/compile_pass/generics.rs deleted file mode 100644 index 4c56b146772d..000000000000 --- a/third_party/rust/extend/tests/compile_pass/generics.rs +++ /dev/null @@ -1,15 +0,0 @@ -use extend::ext; - -#[ext] -impl<'a, T: Clone> Vec<&'a T> -where - T: 'a + Copy, -{ - fn size(&self) -> usize { - self.len() - } -} - -fn main() { - assert_eq!(3, vec![&1, &2, &3].size()); -} diff --git a/third_party/rust/extend/tests/compile_pass/hello_world.rs b/third_party/rust/extend/tests/compile_pass/hello_world.rs deleted file mode 100644 index 75c61183b4e3..000000000000 --- a/third_party/rust/extend/tests/compile_pass/hello_world.rs +++ /dev/null @@ -1,20 +0,0 @@ -use extend::ext; - -#[ext] -impl i32 { - fn add_one(&self) -> Self { - self + 1 - } - - fn foo() -> MyType { - MyType - } -} - -#[derive(Debug, Eq, PartialEq)] -struct MyType; - -fn main() { - assert_eq!(i32::foo(), MyType); - assert_eq!(1.add_one(), 2); -} diff --git a/third_party/rust/extend/tests/compile_pass/issue_2.rs b/third_party/rust/extend/tests/compile_pass/issue_2.rs deleted file mode 100644 index 76516486ab1f..000000000000 --- a/third_party/rust/extend/tests/compile_pass/issue_2.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![allow(unused_variables)] - -use extend::ext; -use std::iter::FromIterator; - -#[ext] -impl C -where - C: IntoIterator, - K: Eq, - F: Fn(&T) -> K, -{ - fn group_by(self, f: F) -> Out - where - Out: FromIterator<(K, Vec)>, - { - todo!() - } - - fn group_by_and_map_values(self, f: F, g: G) -> Out - where - G: Fn(T) -> T2 + Copy, - Out: FromIterator<(K, Vec)>, - { - todo!() - } - - fn group_by_and_return_groups(self, f: F) -> Vec> { - todo!() - } -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs b/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs deleted file mode 100644 index e5ce539f15f5..000000000000 --- a/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs +++ /dev/null @@ -1,13 +0,0 @@ -use extend::ext; - -#[ext] -impl i32 { - fn foo() {} -} - -#[ext] -impl i64 { - fn bar() {} -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_config.rs b/third_party/rust/extend/tests/compile_pass/multiple_config.rs deleted file mode 100644 index 9ffdad131630..000000000000 --- a/third_party/rust/extend/tests/compile_pass/multiple_config.rs +++ /dev/null @@ -1,13 +0,0 @@ -use extend::ext; - -#[ext(pub(crate), name = Foo)] -impl i32 { - fn foo() {} -} - -#[ext(pub, name = Bar)] -impl i64 { - fn foo() {} -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs b/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs deleted file mode 100644 index 29e4b9ca210d..000000000000 --- a/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs +++ /dev/null @@ -1,11 +0,0 @@ -use extend::ext; -use std::marker::PhantomData; - -struct Foo(PhantomData); - -#[ext] -impl T { - fn some_method(&self, _: Foo) {} -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/pub_impl.rs b/third_party/rust/extend/tests/compile_pass/pub_impl.rs deleted file mode 100644 index f7bff519c017..000000000000 --- a/third_party/rust/extend/tests/compile_pass/pub_impl.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod a { - use extend::ext; - - #[ext] - pub impl i32 { - fn foo() -> Foo { Foo } - } - - pub struct Foo; -} - -fn main() { - use a::i32Ext; - i32::foo(); -} diff --git a/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs b/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs deleted file mode 100644 index 156f62027dee..000000000000 --- a/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs +++ /dev/null @@ -1,13 +0,0 @@ -use extend::ext; - -#[ext] -impl &i32 { - fn foo() {} -} - -#[ext] -impl &mut i32 { - fn bar() {} -} - -fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/sized.rs b/third_party/rust/extend/tests/compile_pass/sized.rs deleted file mode 100644 index dae05f3f527a..000000000000 --- a/third_party/rust/extend/tests/compile_pass/sized.rs +++ /dev/null @@ -1,36 +0,0 @@ -use extend::ext_sized; - -#[ext_sized(name = One)] -impl i32 { - fn requires_sized(self) -> Option { - Some(self) - } -} - -#[ext_sized(name = Two, supertraits = Default)] -impl i32 { - fn with_another_supertrait(self) -> Option { - Some(self) - } -} - -#[ext_sized(name = Three, supertraits = Default + Clone + Copy)] -impl i32 { - fn multiple_supertraits(self) -> Option { - Some(self) - } -} - -#[ext_sized(name = Four, supertraits = Sized)] -impl i32 { - fn already_sized(self) -> Option { - Some(self) - } -} - -fn main() { - 1.requires_sized(); - 1.with_another_supertrait(); - 1.multiple_supertraits(); - 1.already_sized(); -} diff --git a/third_party/rust/extend/tests/compile_pass/super_trait.rs b/third_party/rust/extend/tests/compile_pass/super_trait.rs deleted file mode 100644 index 30b147d24a60..000000000000 --- a/third_party/rust/extend/tests/compile_pass/super_trait.rs +++ /dev/null @@ -1,16 +0,0 @@ -use extend::ext; - -trait MyTrait {} - -impl MyTrait for String {} - -#[ext(supertraits = Default + Clone + MyTrait)] -impl String { - fn my_len(&self) -> usize { - self.len() - } -} - -fn main() { - assert_eq!(String::new().my_len(), 0); -} diff --git a/third_party/rust/extend/tests/compile_pass/visibility_config.rs b/third_party/rust/extend/tests/compile_pass/visibility_config.rs deleted file mode 100644 index bcb8b1957687..000000000000 --- a/third_party/rust/extend/tests/compile_pass/visibility_config.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod a { - use extend::ext; - - #[ext(pub)] - impl i32 { - fn foo() -> Foo { Foo } - } - - pub struct Foo; -} - -fn main() { - use a::i32Ext; - i32::foo(); -} diff --git a/third_party/rust/uniffi-example-arithmetic/.cargo-checksum.json b/third_party/rust/uniffi-example-arithmetic/.cargo-checksum.json deleted file mode 100644 index 78bc74c55fd3..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"90295a750f9c69ee799ac767d56eaee2c3218df7964f11c885b6910a31d07a25","build.rs":"05089b35ac197b5ff83c75872a70df023834141831d0c2051faa35b4c9df55ba","src/arithmetic.udl":"8554c6907ece627645f6b896f71430e5412bf19b0ac6becf63eb9a69868d0f7a","src/lib.rs":"92ebd9fc4d3403ab1960d2d8520c1217971147ea3aebff89228a61fcbb8b2af3","tests/bindings/test_arithmetic.kts":"e0e9347755db4e18f70b1b74c2d5a4aa328373015090ed959b46d65c2a205d92","tests/bindings/test_arithmetic.py":"3e41d69e21e96a6830197c760f3b7bddd754edc0c5515b7bd33b79cccb10f941","tests/bindings/test_arithmetic.rb":"ea0fdce0a4c7b557b427db77521da05240cd6e87d60a128ac2307fab3bbbc76d","tests/bindings/test_arithmetic.swift":"455b87d95fc690af9c35f9e43676e9c855dedddd2fc1c9e1cbaa6a02835c2d4c","tests/test_generated_bindings.rs":"09b0e79c7e769bcf5f3a8b768247a05892d408d48e0295f6737de3c8dab28479","uniffi.toml":"ad149df611a6e3a853a029d90a88a694660f6a4ebe18dcb5f9f503819761dacd"},"package":null} \ No newline at end of file diff --git a/third_party/rust/uniffi-example-arithmetic/Cargo.toml b/third_party/rust/uniffi-example-arithmetic/Cargo.toml deleted file mode 100644 index 6bdabd91dd96..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "uniffi-example-arithmetic" -edition = "2021" -version = "0.18.0" -authors = ["Firefox Sync Team "] -license = "MPL-2.0" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] -name = "arithmetical" - -[dependencies] -uniffi_macros = {path = "../../uniffi_macros"} -uniffi = {path = "../../uniffi", features=["builtin-bindgen"]} -thiserror = "1.0" - -[build-dependencies] -uniffi_build = {path = "../../uniffi_build", features=["builtin-bindgen"]} diff --git a/third_party/rust/uniffi-example-arithmetic/build.rs b/third_party/rust/uniffi-example-arithmetic/build.rs deleted file mode 100644 index b1be1ab9a194..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -fn main() { - uniffi_build::generate_scaffolding("./src/arithmetic.udl").unwrap(); -} diff --git a/third_party/rust/uniffi-example-arithmetic/src/arithmetic.udl b/third_party/rust/uniffi-example-arithmetic/src/arithmetic.udl deleted file mode 100644 index 117df4834aa4..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/src/arithmetic.udl +++ /dev/null @@ -1,16 +0,0 @@ -[Error] -enum ArithmeticError { - "IntegerOverflow", -}; - -namespace arithmetic { - [Throws=ArithmeticError] - u64 add(u64 a, u64 b); - - [Throws=ArithmeticError] - u64 sub(u64 a, u64 b); - - u64 div(u64 dividend, u64 divisor); - - boolean equal(u64 a, u64 b); -}; diff --git a/third_party/rust/uniffi-example-arithmetic/src/lib.rs b/third_party/rust/uniffi-example-arithmetic/src/lib.rs deleted file mode 100644 index d26b90fcbbfd..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#[derive(Debug, thiserror::Error)] -pub enum ArithmeticError { - #[error("Integer overflow on an operation with {a} and {b}")] - IntegerOverflow { a: u64, b: u64 }, -} - -fn add(a: u64, b: u64) -> Result { - a.checked_add(b) - .ok_or(ArithmeticError::IntegerOverflow { a, b }) -} - -fn sub(a: u64, b: u64) -> Result { - a.checked_sub(b) - .ok_or(ArithmeticError::IntegerOverflow { a, b }) -} - -fn div(dividend: u64, divisor: u64) -> u64 { - if divisor == 0 { - panic!("Can't divide by zero"); - } - dividend / divisor -} - -fn equal(a: u64, b: u64) -> bool { - a == b -} - -type Result = std::result::Result; - -uniffi_macros::include_scaffolding!("arithmetic"); diff --git a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.kts b/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.kts deleted file mode 100644 index ef11850ae23f..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.kts +++ /dev/null @@ -1,29 +0,0 @@ -import org.mozilla.uniffi.example.arithmetic.*; - -assert(add(2u, 4u) == 6uL) -assert(add(4u, 8u) == 12uL) - -try { - sub(0u, 2u) - throw RuntimeException("Should have thrown a IntegerOverflow exception!") -} catch (e: ArithmeticException) { - // It's okay! -} - -assert(sub(4u, 2u) == 2uL) -assert(sub(8u, 4u) == 4uL) - -assert(div(8u, 4u) == 2uL) - -try { - div(8u, 0u) - throw RuntimeException("Should have panicked when dividing by zero") -} catch (e: InternalException) { - // It's okay! -} - -assert(equal(2u, 2uL)) -assert(equal(4u, 4uL)) - -assert(!equal(2u, 4uL)) -assert(!equal(4u, 8uL)) diff --git a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.py b/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.py deleted file mode 100644 index 0d4e666fbf77..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.py +++ /dev/null @@ -1,37 +0,0 @@ -from arithmetic import * - -try: - add(18446744073709551615, 1) - assert(not("Should have thrown a IntegerOverflow exception!")) -except ArithmeticError.IntegerOverflow: - # It's okay! - pass - -assert add(2, 4) == 6 -assert add(4, 8) == 12 - -try: - sub(0, 1) - assert(not("Should have thrown a IntegerOverflow exception!")) -except ArithmeticError.IntegerOverflow: - # It's okay! - pass - -assert sub(4, 2) == 2 -assert sub(8, 4) == 4 - -assert div(8, 4) == 2 - -try: - div(8, 0) -except InternalError: - # It's okay! - pass -else: - assert(not("Should have panicked when dividing by zero")) - -assert equal(2, 2) -assert equal(4, 4) - -assert not equal(2, 4) -assert not equal(4, 8) diff --git a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.rb b/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.rb deleted file mode 100644 index 6669eb279f28..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require 'test/unit' -require 'arithmetic' - -include Test::Unit::Assertions - -assert_raise Arithmetic::ArithmeticError::IntegerOverflow do - Arithmetic.add 18_446_744_073_709_551_615, 1 -end - -assert_equal Arithmetic.add(2, 4), 6 -assert_equal Arithmetic.add(4, 8), 12 - -assert_raise Arithmetic::ArithmeticError::IntegerOverflow do - Arithmetic.sub 0, 1 -end - -assert_equal Arithmetic.sub(4, 2), 2 -assert_equal Arithmetic.sub(8, 4), 4 -assert_equal Arithmetic.div(8, 4), 2 - -assert_raise Arithmetic::InternalError do - Arithmetic.div 8, 0 -end - -assert Arithmetic.equal(2, 2) -assert Arithmetic.equal(4, 4) - -assert !Arithmetic.equal(2, 4) -assert !Arithmetic.equal(4, 8) diff --git a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.swift b/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.swift deleted file mode 100644 index a8e34680e4f4..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.swift +++ /dev/null @@ -1,32 +0,0 @@ -import arithmetic - -do { - let _ = try add(a: 18446744073709551615, b: 1) - fatalError("Should have thrown a IntegerOverflow exception!") -} catch ArithmeticError.IntegerOverflow { - // It's okay! -} - -assert(try! add(a: 2, b: 4) == 6, "add work") -assert(try! add(a: 4, b: 8) == 12, "add work") - -do { - let _ = try sub(a: 0, b: 1) - fatalError("Should have thrown a IntegerOverflow exception!") -} catch ArithmeticError.IntegerOverflow { - // It's okay! -} - -assert(try! sub(a: 4, b: 2) == 2, "sub work") -assert(try! sub(a: 8, b: 4) == 4, "sub work") - -assert(div(dividend: 8, divisor: 4) == 2, "div works") - -// We can't test panicking in Swift because we force unwrap the error in -// `div`, which we can't catch. - -assert(equal(a: 2, b: 2), "equal works") -assert(equal(a: 4, b: 4), "equal works") - -assert(!equal(a: 2, b: 4), "non-equal works") -assert(!equal(a: 4, b: 8), "non-equal works") diff --git a/third_party/rust/uniffi-example-arithmetic/tests/test_generated_bindings.rs b/third_party/rust/uniffi-example-arithmetic/tests/test_generated_bindings.rs deleted file mode 100644 index 2997acc6fc12..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/tests/test_generated_bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -uniffi_macros::build_foreign_language_testcases!( - ["src/arithmetic.udl",], - [ - "tests/bindings/test_arithmetic.rb", - "tests/bindings/test_arithmetic.py", - "tests/bindings/test_arithmetic.kts", - "tests/bindings/test_arithmetic.swift", - ] -); diff --git a/third_party/rust/uniffi-example-arithmetic/uniffi.toml b/third_party/rust/uniffi-example-arithmetic/uniffi.toml deleted file mode 100644 index a9fab4c0b4f7..000000000000 --- a/third_party/rust/uniffi-example-arithmetic/uniffi.toml +++ /dev/null @@ -1,12 +0,0 @@ -[bindings.kotlin] -package_name = "org.mozilla.uniffi.example.arithmetic" -cdylib_name = "arithmetical" - -[bindings.python] -cdylib_name = "arithmetical" - -[bindings.ruby] -cdylib_name = "arithmetical" - -[bindings.swift] -cdylib_name = "arithmetical" diff --git a/third_party/rust/uniffi-example-geometry/.cargo-checksum.json b/third_party/rust/uniffi-example-geometry/.cargo-checksum.json deleted file mode 100644 index 5247c6f06cdf..000000000000 --- a/third_party/rust/uniffi-example-geometry/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"15bbf6e8c0d438e7f776dfdcf8da5fefb41e4b5bacafe97d1fcb10389d07ed9b","build.rs":"94ca4e70e538a2159cb77157c227d487973756373c4b27ea5cea05a6698cb60b","src/geometry.udl":"7da7a6ec080c7117ec3c25206e23f9ed436e60b1a26fba34f991547680443550","src/lib.rs":"be9c624f691a8d1ebe3be6dbbcde44033759b8321a3a298453018dd69b9c14c7","tests/bindings/test_geometry.kts":"e537185e3c699df1c0468525700e8a38f9a504b2a663c38442146b951e38e9a7","tests/bindings/test_geometry.py":"3ea483b8a4fbe13aefa6641177ae149f75f734bc32bf0da533b97c1abf3dc317","tests/bindings/test_geometry.rb":"17c2fe8a7b477419a6646983dd88f1b07a0304b58a568c03e9bfa640d5b2df5c","tests/bindings/test_geometry.swift":"a61fec6bfe16020809e20e4da372748c24366767138c5672a0bfff85c4b62d78","tests/test_generated_bindings.rs":"8ba67396105b96cc554f78078c7a8c6e8ce86ecc868d97a069a5f60fd87c1a36","uniffi.toml":"5b28f45d3c2581a52cf886a502f034778a002815b66994e5da2081a5c9f5284b"},"package":null} \ No newline at end of file diff --git a/third_party/rust/uniffi-example-geometry/Cargo.toml b/third_party/rust/uniffi-example-geometry/Cargo.toml deleted file mode 100644 index 4ab89827fbf3..000000000000 --- a/third_party/rust/uniffi-example-geometry/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "uniffi-example-geometry" -edition = "2021" -version = "0.18.0" -authors = ["Firefox Sync Team "] -license = "MPL-2.0" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] -name = "uniffi_geometry" - -[dependencies] -uniffi_macros = {path = "../../uniffi_macros"} -uniffi = {path = "../../uniffi", features=["builtin-bindgen"]} - -[build-dependencies] -uniffi_build = {path = "../../uniffi_build", features=["builtin-bindgen"]} diff --git a/third_party/rust/uniffi-example-geometry/build.rs b/third_party/rust/uniffi-example-geometry/build.rs deleted file mode 100644 index 716ccd4908e4..000000000000 --- a/third_party/rust/uniffi-example-geometry/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -fn main() { - uniffi_build::generate_scaffolding("./src/geometry.udl").unwrap(); -} diff --git a/third_party/rust/uniffi-example-geometry/src/geometry.udl b/third_party/rust/uniffi-example-geometry/src/geometry.udl deleted file mode 100644 index af60d429bfcb..000000000000 --- a/third_party/rust/uniffi-example-geometry/src/geometry.udl +++ /dev/null @@ -1,15 +0,0 @@ - -namespace geometry { - double gradient(Line ln); - Point? intersection(Line ln1, Line ln2); -}; - -dictionary Point { - double coord_x; - double coord_y; -}; - -dictionary Line { - Point start; - Point end; -}; diff --git a/third_party/rust/uniffi-example-geometry/src/lib.rs b/third_party/rust/uniffi-example-geometry/src/lib.rs deleted file mode 100644 index 0e6add54f2ed..000000000000 --- a/third_party/rust/uniffi-example-geometry/src/lib.rs +++ /dev/null @@ -1,47 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp -// Silence, clippy! -const EPSILON: f64 = 0.0001f64; - -#[derive(Debug, Clone)] -pub struct Point { - coord_x: f64, - coord_y: f64, -} - -#[derive(Debug, Clone)] -pub struct Line { - start: Point, - end: Point, -} - -pub fn gradient(ln: Line) -> f64 { - let rise = ln.end.coord_y - ln.start.coord_y; - let run = ln.end.coord_x - ln.start.coord_x; - rise / run -} - -pub fn intersection(ln1: Line, ln2: Line) -> Option { - // TODO: yuck, should be able to take &Line as argument here - // and have rust figure it out with a bunch of annotations... - let g1 = gradient(ln1.clone()); - let z1 = ln1.start.coord_y - g1 * ln1.start.coord_x; - let g2 = gradient(ln2.clone()); - let z2 = ln2.start.coord_y - g2 * ln2.start.coord_x; - // Parallel lines do not intersect. - if (g1 - g2).abs() < EPSILON { - return None; - } - // Otherwise, they intersect at this fancy calculation that - // I found on wikipedia. - let x = (z2 - z1) / (g1 - g2); - Some(Point { - coord_x: x, - coord_y: g1 * x + z1, - }) -} - -include!(concat!(env!("OUT_DIR"), "/geometry.uniffi.rs")); diff --git a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.kts b/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.kts deleted file mode 100644 index 77bb9932ec02..000000000000 --- a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.kts +++ /dev/null @@ -1,10 +0,0 @@ -import uniffi.geometry.*; - -val ln1 = Line(Point(0.0,0.0), Point(1.0,2.0)) -val ln2 = Line(Point(1.0,1.0), Point(2.0,2.0)) - -assert( gradient(ln1) == 2.0 ) -assert( gradient(ln2) == 1.0 ) - -assert( intersection(ln1, ln2) == Point(0.0, 0.0) ) -assert( intersection(ln1, ln1) == null ) diff --git a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.py b/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.py deleted file mode 100644 index a40e2af6ecab..000000000000 --- a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.py +++ /dev/null @@ -1,10 +0,0 @@ -from geometry import * - -ln1 = Line(Point(0,0), Point(1,2)) -ln2 = Line(Point(1,1), Point(2,2)) - -assert gradient(ln1) == 2 -assert gradient(ln2) == 1 - -assert intersection(ln1, ln2) == Point(0, 0) -assert intersection(ln1, ln1) is None diff --git a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.rb b/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.rb deleted file mode 100644 index 8b1280d82398..000000000000 --- a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require 'test/unit' -require 'geometry' - -include Test::Unit::Assertions -include Geometry - -ln1 = Line.new(Point.new(0.0, 0.0), Point.new(1.0, 2.0)) -ln2 = Line.new(Point.new(1.0, 1.0), Point.new(2.0, 2.0)) - -assert_equal Geometry.gradient(ln1), 2 -assert_equal Geometry.gradient(ln2), 1 - -assert_equal Geometry.intersection(ln1, ln2), Point.new(0, 0) -assert Geometry.intersection(ln1, ln1).nil? diff --git a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.swift b/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.swift deleted file mode 100644 index 58bd65607f51..000000000000 --- a/third_party/rust/uniffi-example-geometry/tests/bindings/test_geometry.swift +++ /dev/null @@ -1,10 +0,0 @@ -import geometry - -let ln1 = Line(start: Point(coordX: 0, coordY: 0), end: Point(coordX: 1, coordY: 2)) -let ln2 = Line(start: Point(coordX: 1, coordY: 1), end: Point(coordX: 2, coordY: 2)) - -assert(gradient(ln: ln1) == 2.0) -assert(gradient(ln: ln2) == 1.0) - -assert(intersection(ln1: ln1, ln2: ln2) == Point(coordX: 0, coordY: 0)) -assert(intersection(ln1: ln1, ln2: ln1) == nil) diff --git a/third_party/rust/uniffi-example-geometry/tests/test_generated_bindings.rs b/third_party/rust/uniffi-example-geometry/tests/test_generated_bindings.rs deleted file mode 100644 index 0c712ff7c040..000000000000 --- a/third_party/rust/uniffi-example-geometry/tests/test_generated_bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -uniffi_macros::build_foreign_language_testcases!( - ["src/geometry.udl",], - [ - "tests/bindings/test_geometry.py", - "tests/bindings/test_geometry.rb", - "tests/bindings/test_geometry.kts", - "tests/bindings/test_geometry.swift", - ] -); diff --git a/third_party/rust/uniffi-example-geometry/uniffi.toml b/third_party/rust/uniffi-example-geometry/uniffi.toml deleted file mode 100644 index 969379365aed..000000000000 --- a/third_party/rust/uniffi-example-geometry/uniffi.toml +++ /dev/null @@ -1 +0,0 @@ -[bindings.swift] diff --git a/third_party/rust/uniffi-example-rondpoint/.cargo-checksum.json b/third_party/rust/uniffi-example-rondpoint/.cargo-checksum.json deleted file mode 100644 index bcd26980ee9b..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"e26e9e2826e89bf73aed693d2cea2aa1e2ce3d32cb0f03136cc29352f851295c","build.rs":"c48df8045c6cf73a8f3b8e93af7878f4ce1e7baa11f0688d661405f339df4ba4","src/lib.rs":"70b9ab1fb944d3af1ce53ce097caf52d1ebbf0e18be1e70bf57e5cec96e76502","src/rondpoint.udl":"ca4d8720758608b06ffd5f81bfc73881fbd0693a7a5b21bfe61a4557ea052048","tests/bindings/test_rondpoint.kts":"87b3d507f4260aae4e4711263c13b7158b9a814cb97bf5219d1451f348cd7372","tests/bindings/test_rondpoint.py":"d618274170af767f8a5614a2565ea698b26ea3e1a222d5c110e7b2d00763e73b","tests/bindings/test_rondpoint.rb":"9cc49df311823d6caedbe7b05ff8c4da6329063c2ce16810192aaaa7edcdf5f5","tests/bindings/test_rondpoint.swift":"471cf430be35dcdc19b3166adbc08561e0bd939931edc37da974e0fd16a49331","tests/test_generated_bindings.rs":"5843b2c9d6b86b35ab932349d278d9f281493880a1395e0b7566e297fad36c7d"},"package":null} \ No newline at end of file diff --git a/third_party/rust/uniffi-example-rondpoint/Cargo.toml b/third_party/rust/uniffi-example-rondpoint/Cargo.toml deleted file mode 100644 index d6ec3aa22e82..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "uniffi-example-rondpoint" -edition = "2021" -version = "0.18.0" -authors = ["Firefox Sync Team "] -license = "MPL-2.0" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] -name = "uniffi_rondpoint" - -[dependencies] -uniffi_macros = {path = "../../uniffi_macros"} -uniffi = {path = "../../uniffi", features=["builtin-bindgen"]} - -[build-dependencies] -uniffi_build = {path = "../../uniffi_build", features=["builtin-bindgen"]} diff --git a/third_party/rust/uniffi-example-rondpoint/build.rs b/third_party/rust/uniffi-example-rondpoint/build.rs deleted file mode 100644 index 0feac686ee2a..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -fn main() { - uniffi_build::generate_scaffolding("./src/rondpoint.udl").unwrap(); -} diff --git a/third_party/rust/uniffi-example-rondpoint/src/lib.rs b/third_party/rust/uniffi-example-rondpoint/src/lib.rs deleted file mode 100644 index 856f614e63f0..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/src/lib.rs +++ /dev/null @@ -1,293 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use std::collections::HashMap; - -#[derive(Debug, Clone)] -pub struct Dictionnaire { - un: Enumeration, - deux: bool, - petit_nombre: u8, - gros_nombre: u64, -} - -#[derive(Debug, Clone)] -pub struct DictionnaireNombres { - petit_nombre: u8, - court_nombre: u16, - nombre_simple: u32, - gros_nombre: u64, -} - -#[derive(Debug, Clone)] -pub struct DictionnaireNombresSignes { - petit_nombre: i8, - court_nombre: i16, - nombre_simple: i32, - gros_nombre: i64, -} - -#[derive(Debug, Clone)] -pub enum Enumeration { - Un, - Deux, - Trois, -} - -#[derive(Debug, Clone)] -pub enum EnumerationAvecDonnees { - Zero, - Un { premier: u32 }, - Deux { premier: u32, second: String }, -} - -#[allow(non_camel_case_types)] -#[allow(non_snake_case)] -pub struct minusculeMAJUSCULEDict { - minusculeMAJUSCULEField: bool, -} - -#[allow(non_camel_case_types)] -pub enum minusculeMAJUSCULEEnum { - minusculeMAJUSCULEVariant, -} - -fn copie_enumeration(e: Enumeration) -> Enumeration { - e -} - -fn copie_enumerations(e: Vec) -> Vec { - e -} - -fn copie_carte( - e: HashMap, -) -> HashMap { - e -} - -fn copie_dictionnaire(d: Dictionnaire) -> Dictionnaire { - d -} - -fn switcheroo(b: bool) -> bool { - !b -} - -// Test that values can traverse both ways across the FFI. -// Even if roundtripping works, it's possible we have -// symmetrical errors that cancel each other out. -#[derive(Debug, Clone)] -struct Retourneur; -impl Retourneur { - fn new() -> Self { - Retourneur - } - fn identique_i8(&self, value: i8) -> i8 { - value - } - fn identique_u8(&self, value: u8) -> u8 { - value - } - fn identique_i16(&self, value: i16) -> i16 { - value - } - fn identique_u16(&self, value: u16) -> u16 { - value - } - fn identique_i32(&self, value: i32) -> i32 { - value - } - fn identique_u32(&self, value: u32) -> u32 { - value - } - fn identique_i64(&self, value: i64) -> i64 { - value - } - fn identique_u64(&self, value: u64) -> u64 { - value - } - fn identique_float(&self, value: f32) -> f32 { - value - } - fn identique_double(&self, value: f64) -> f64 { - value - } - fn identique_boolean(&self, value: bool) -> bool { - value - } - fn identique_string(&self, value: String) -> String { - value - } - fn identique_nombres_signes( - &self, - value: DictionnaireNombresSignes, - ) -> DictionnaireNombresSignes { - value - } - fn identique_nombres(&self, value: DictionnaireNombres) -> DictionnaireNombres { - value - } - fn identique_optionneur_dictionnaire( - &self, - value: OptionneurDictionnaire, - ) -> OptionneurDictionnaire { - value - } -} - -#[derive(Debug, Clone)] -struct Stringifier; - -#[allow(dead_code)] -impl Stringifier { - fn new() -> Self { - Stringifier - } - fn to_string_i8(&self, value: i8) -> String { - value.to_string() - } - fn to_string_u8(&self, value: u8) -> String { - value.to_string() - } - fn to_string_i16(&self, value: i16) -> String { - value.to_string() - } - fn to_string_u16(&self, value: u16) -> String { - value.to_string() - } - fn to_string_i32(&self, value: i32) -> String { - value.to_string() - } - fn to_string_u32(&self, value: u32) -> String { - value.to_string() - } - fn to_string_i64(&self, value: i64) -> String { - value.to_string() - } - fn to_string_u64(&self, value: u64) -> String { - value.to_string() - } - fn to_string_float(&self, value: f32) -> String { - value.to_string() - } - fn to_string_double(&self, value: f64) -> String { - value.to_string() - } - fn to_string_boolean(&self, value: bool) -> String { - value.to_string() - } - fn well_known_string(&self, value: String) -> String { - format!("uniffi 💚 {}!", value) - } -} - -#[derive(Debug, Clone)] -struct Optionneur; -impl Optionneur { - fn new() -> Self { - Optionneur - } - fn sinon_string(&self, value: String) -> String { - value - } - fn sinon_null(&self, value: Option) -> Option { - value - } - fn sinon_boolean(&self, value: bool) -> bool { - value - } - fn sinon_sequence(&self, value: Vec) -> Vec { - value - } - - fn sinon_zero(&self, value: Option) -> Option { - value - } - - fn sinon_u8_dec(&self, value: u8) -> u8 { - value - } - fn sinon_i8_dec(&self, value: i8) -> i8 { - value - } - fn sinon_u16_dec(&self, value: u16) -> u16 { - value - } - fn sinon_i16_dec(&self, value: i16) -> i16 { - value - } - fn sinon_u32_dec(&self, value: u32) -> u32 { - value - } - fn sinon_i32_dec(&self, value: i32) -> i32 { - value - } - fn sinon_u64_dec(&self, value: u64) -> u64 { - value - } - fn sinon_i64_dec(&self, value: i64) -> i64 { - value - } - - fn sinon_u8_hex(&self, value: u8) -> u8 { - value - } - fn sinon_i8_hex(&self, value: i8) -> i8 { - value - } - fn sinon_u16_hex(&self, value: u16) -> u16 { - value - } - fn sinon_i16_hex(&self, value: i16) -> i16 { - value - } - fn sinon_u32_hex(&self, value: u32) -> u32 { - value - } - fn sinon_i32_hex(&self, value: i32) -> i32 { - value - } - fn sinon_u64_hex(&self, value: u64) -> u64 { - value - } - fn sinon_i64_hex(&self, value: i64) -> i64 { - value - } - - fn sinon_u32_oct(&self, value: u32) -> u32 { - value - } - - fn sinon_f32(&self, value: f32) -> f32 { - value - } - fn sinon_f64(&self, value: f64) -> f64 { - value - } - - fn sinon_enum(&self, value: Enumeration) -> Enumeration { - value - } -} - -pub struct OptionneurDictionnaire { - i8_var: i8, - u8_var: u8, - i16_var: i16, - u16_var: u16, - i32_var: i32, - u32_var: u32, - i64_var: i64, - u64_var: u64, - float_var: f32, - double_var: f64, - boolean_var: bool, - string_var: String, - list_var: Vec, - enumeration_var: Enumeration, - dictionnaire_var: Option, -} - -include!(concat!(env!("OUT_DIR"), "/rondpoint.uniffi.rs")); diff --git a/third_party/rust/uniffi-example-rondpoint/src/rondpoint.udl b/third_party/rust/uniffi-example-rondpoint/src/rondpoint.udl deleted file mode 100644 index 05b1bfe82570..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/src/rondpoint.udl +++ /dev/null @@ -1,146 +0,0 @@ -namespace rondpoint { - Dictionnaire copie_dictionnaire(Dictionnaire d); - Enumeration copie_enumeration(Enumeration e); - sequence copie_enumerations(sequence e); - record copie_carte(record c); - boolean switcheroo(boolean b); -}; - -dictionary minusculeMAJUSCULEDict { - boolean minusculeMAJUSCULEField; -}; - -enum minusculeMAJUSCULEEnum { - "minusculeMAJUSCULEVariant", -}; - -enum Enumeration { - "Un", - "Deux", - "Trois", -}; - -[Enum] -interface EnumerationAvecDonnees { - Zero(); - Un(u32 premier); - Deux(u32 premier, string second); -}; - -dictionary Dictionnaire { - Enumeration un; - boolean deux; - u8 petit_nombre; - u64 gros_nombre; -}; - -dictionary DictionnaireNombres { - u8 petit_nombre; - u16 court_nombre; - u32 nombre_simple; - u64 gros_nombre; -}; - -dictionary DictionnaireNombresSignes { - i8 petit_nombre; - i16 court_nombre; - i32 nombre_simple; - i64 gros_nombre; -}; - -interface Retourneur { - constructor(); - i8 identique_i8(i8 value); - u8 identique_u8(u8 value); - i16 identique_i16(i16 value); - u16 identique_u16(u16 value); - i32 identique_i32(i32 value); - u32 identique_u32(u32 value); - i64 identique_i64(i64 value); - u64 identique_u64(u64 value); - float identique_float(float value); - double identique_double(double value); - boolean identique_boolean(boolean value); - string identique_string(string value); - - DictionnaireNombresSignes identique_nombres_signes(DictionnaireNombresSignes value); - DictionnaireNombres identique_nombres(DictionnaireNombres value); - OptionneurDictionnaire identique_optionneur_dictionnaire(OptionneurDictionnaire value); -}; - -interface Stringifier { - constructor(); - string well_known_string(string value); - - string to_string_i8(i8 value); - string to_string_u8(u8 value); - string to_string_i16(i16 value); - string to_string_u16(u16 value); - string to_string_i32(i32 value); - string to_string_u32(u32 value); - string to_string_i64(i64 value); - string to_string_u64(u64 value); - string to_string_float(float value); - string to_string_double(double value); - string to_string_boolean(boolean value); -}; - -interface Optionneur { - constructor(); - boolean sinon_boolean(optional boolean value = false); - string sinon_string(optional string value = "default"); - - sequence sinon_sequence(optional sequence value = []); - - // Either sides of nullable. - string? sinon_null(optional string? value = null); - i32? sinon_zero(optional i32? value = 0); - - // Decimal integers, all 42. - u8 sinon_u8_dec(optional u8 value = 42); - i8 sinon_i8_dec(optional i8 value = -42); - u16 sinon_u16_dec(optional u16 value = 42); - i16 sinon_i16_dec(optional i16 value = 42); - u32 sinon_u32_dec(optional u32 value = 42); - i32 sinon_i32_dec(optional i32 value = 42); - u64 sinon_u64_dec(optional u64 value = 42); - i64 sinon_i64_dec(optional i64 value = 42); - - // Hexadecimal, including negatgives. - u8 sinon_u8_hex(optional u8 value = 0xff); - i8 sinon_i8_hex(optional i8 value = -0x7f); - u16 sinon_u16_hex(optional u16 value = 0xffff); - i16 sinon_i16_hex(optional i16 value = 0x7f); - u32 sinon_u32_hex(optional u32 value = 0xffffffff); - i32 sinon_i32_hex(optional i32 value = 0x7fffffff); - u64 sinon_u64_hex(optional u64 value = 0xffffffffffffffff); - i64 sinon_i64_hex(optional i64 value = 0x7fffffffffffffff); - - // Octal, FWIW. - u32 sinon_u32_oct(optional u32 value = 0755); - - // Floats - f32 sinon_f32(optional f32 value = 42.0); - f64 sinon_f64(optional f64 value = 42.1); - - // Enums, which we have to treat as strings in the UDL frontend. - Enumeration sinon_enum(optional Enumeration value = "Trois"); -}; - -dictionary OptionneurDictionnaire { - i8 i8_var = -8; - u8 u8_var = 8; - i16 i16_var = -0x10; - u16 u16_var = 0x10; - i32 i32_var = -32; - u32 u32_var = 32; - i64 i64_var = -64; - u64 u64_var = 64; - float float_var = 4.0; - double double_var = 8.0; - boolean boolean_var = true; - string string_var = "default"; - sequence list_var = []; - Enumeration enumeration_var = "DEUX"; - minusculeMAJUSCULEEnum? dictionnaire_var = null; -}; diff --git a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.kts b/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.kts deleted file mode 100644 index db2a3df97508..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.kts +++ /dev/null @@ -1,250 +0,0 @@ -import uniffi.rondpoint.* - -val dico = Dictionnaire(Enumeration.DEUX, true, 0u, 123456789u) -val copyDico = copieDictionnaire(dico) -assert(dico == copyDico) - -assert(copieEnumeration(Enumeration.DEUX) == Enumeration.DEUX) -assert(copieEnumerations(listOf(Enumeration.UN, Enumeration.DEUX)) == listOf(Enumeration.UN, Enumeration.DEUX)) -assert(copieCarte(mapOf( - "0" to EnumerationAvecDonnees.Zero, - "1" to EnumerationAvecDonnees.Un(1u), - "2" to EnumerationAvecDonnees.Deux(2u, "deux") -)) == mapOf( - "0" to EnumerationAvecDonnees.Zero, - "1" to EnumerationAvecDonnees.Un(1u), - "2" to EnumerationAvecDonnees.Deux(2u, "deux") -)) - -val var1: EnumerationAvecDonnees = EnumerationAvecDonnees.Zero -val var2: EnumerationAvecDonnees = EnumerationAvecDonnees.Un(1u) -val var3: EnumerationAvecDonnees = EnumerationAvecDonnees.Un(2u) -assert(var1 != var2) -assert(var2 != var3) -assert(var1 == EnumerationAvecDonnees.Zero) -assert(var1 != EnumerationAvecDonnees.Un(1u)) -assert(var2 == EnumerationAvecDonnees.Un(1u)) - -assert(switcheroo(false)) - -// Test the roundtrip across the FFI. -// This shows that the values we send come back in exactly the same state as we sent them. -// i.e. it shows that lowering from kotlin and lifting into rust is symmetrical with -// lowering from rust and lifting into kotlin. -val rt = Retourneur() - -fun List.affirmAllerRetour(fn: (T) -> T) { - this.forEach { v -> - assert(fn.invoke(v) == v) { "$fn($v)" } - } -} - -// Booleans -listOf(true, false).affirmAllerRetour(rt::identiqueBoolean) - -// Bytes. -listOf(Byte.MIN_VALUE, Byte.MAX_VALUE).affirmAllerRetour(rt::identiqueI8) -listOf(0x00, 0xFF).map { it.toUByte() }.affirmAllerRetour(rt::identiqueU8) - -// Shorts -listOf(Short.MIN_VALUE, Short.MAX_VALUE).affirmAllerRetour(rt::identiqueI16) -listOf(0x0000, 0xFFFF).map { it.toUShort() }.affirmAllerRetour(rt::identiqueU16) - -// Ints -listOf(0, 1, -1, Int.MIN_VALUE, Int.MAX_VALUE).affirmAllerRetour(rt::identiqueI32) -listOf(0x00000000, 0xFFFFFFFF).map { it.toUInt() }.affirmAllerRetour(rt::identiqueU32) - -// Longs -listOf(0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE).affirmAllerRetour(rt::identiqueI64) -listOf(0u, 1u, ULong.MIN_VALUE, ULong.MAX_VALUE).affirmAllerRetour(rt::identiqueU64) - -// Floats -listOf(0.0F, 0.5F, 0.25F, Float.MIN_VALUE, Float.MAX_VALUE).affirmAllerRetour(rt::identiqueFloat) - -// Doubles -listOf(0.0, 1.0, Double.MIN_VALUE, Double.MAX_VALUE).affirmAllerRetour(rt::identiqueDouble) - -// Strings -listOf("", "abc", "null\u0000byte", "été", "ښي لاس ته لوستلو لوستل", "😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama") - .affirmAllerRetour(rt::identiqueString) - -listOf(-1, 0, 1).map { DictionnaireNombresSignes(it.toByte(), it.toShort(), it.toInt(), it.toLong()) } - .affirmAllerRetour(rt::identiqueNombresSignes) - -listOf(0, 1).map { DictionnaireNombres(it.toUByte(), it.toUShort(), it.toUInt(), it.toULong()) } - .affirmAllerRetour(rt::identiqueNombres) - - -rt.destroy() - -// Test one way across the FFI. -// -// We send one representation of a value to lib.rs, and it transforms it into another, a string. -// lib.rs sends the string back, and then we compare here in kotlin. -// -// This shows that the values are transformed into strings the same way in both kotlin and rust. -// i.e. if we assume that the string return works (we test this assumption elsewhere) -// we show that lowering from kotlin and lifting into rust has values that both kotlin and rust -// both stringify in the same way. i.e. the same values. -// -// If we roundtripping proves the symmetry of our lowering/lifting from here to rust, and lowering/lifting from rust t here, -// and this convinces us that lowering/lifting from here to rust is correct, then -// together, we've shown the correctness of the return leg. -val st = Stringifier() - -typealias StringyEquals = (observed: String, expected: T) -> Boolean -fun List.affirmEnchaine( - fn: (T) -> String, - equals: StringyEquals = { obs, exp -> obs == exp.toString() } -) { - this.forEach { exp -> - val obs = fn.invoke(exp) - assert(equals(obs, exp)) { "$fn($exp): observed=$obs, expected=$exp" } - } -} - -// Test the efficacy of the string transport from rust. If this fails, but everything else -// works, then things are very weird. -val wellKnown = st.wellKnownString("kotlin") -assert("uniffi 💚 kotlin!" == wellKnown) { "wellKnownString 'uniffi 💚 kotlin!' == '$wellKnown'" } - -// Booleans -listOf(true, false).affirmEnchaine(st::toStringBoolean) - -// Bytes. -listOf(Byte.MIN_VALUE, Byte.MAX_VALUE).affirmEnchaine(st::toStringI8) -listOf(UByte.MIN_VALUE, UByte.MAX_VALUE).affirmEnchaine(st::toStringU8) - -// Shorts -listOf(Short.MIN_VALUE, Short.MAX_VALUE).affirmEnchaine(st::toStringI16) -listOf(UShort.MIN_VALUE, UShort.MAX_VALUE).affirmEnchaine(st::toStringU16) - -// Ints -listOf(0, 1, -1, Int.MIN_VALUE, Int.MAX_VALUE).affirmEnchaine(st::toStringI32) -listOf(0u, 1u, UInt.MIN_VALUE, UInt.MAX_VALUE).affirmEnchaine(st::toStringU32) - -// Longs -listOf(0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE).affirmEnchaine(st::toStringI64) -listOf(0u, 1u, ULong.MIN_VALUE, ULong.MAX_VALUE).affirmEnchaine(st::toStringU64) - -// Floats -// MIN_VAUE is 1.4E-45. Accuracy and formatting get weird at small sizes. -listOf(0.0F, 1.0F, -1.0F, Float.MIN_VALUE, Float.MAX_VALUE).affirmEnchaine(st::toStringFloat) { s, n -> s.toFloat() == n } - -// Doubles -// MIN_VALUE is 4.9E-324. Accuracy and formatting get weird at small sizes. -listOf(0.0, 1.0, -1.0, Double.MIN_VALUE, Double.MAX_VALUE).affirmEnchaine(st::toStringDouble) { s, n -> s.toDouble() == n } - -st.destroy() - -// Prove to ourselves that default arguments are being used. -// Step 1: call the methods without arguments, and check against the UDL. -val op = Optionneur() - -assert(op.sinonString() == "default") - -assert(op.sinonBoolean() == false) - -assert(op.sinonSequence() == listOf()) - -// optionals -assert(op.sinonNull() == null) -assert(op.sinonZero() == 0) - -// decimal integers -assert(op.sinonI8Dec() == (-42).toByte()) -assert(op.sinonU8Dec() == 42.toUByte()) -assert(op.sinonI16Dec() == 42.toShort()) -assert(op.sinonU16Dec() == 42.toUShort()) -assert(op.sinonI32Dec() == 42) -assert(op.sinonU32Dec() == 42.toUInt()) -assert(op.sinonI64Dec() == 42L) -assert(op.sinonU64Dec() == 42uL) - -// hexadecimal integers -assert(op.sinonI8Hex() == (-0x7f).toByte()) -assert(op.sinonU8Hex() == 0xff.toUByte()) -assert(op.sinonI16Hex() == 0x7f.toShort()) -assert(op.sinonU16Hex() == 0xffff.toUShort()) -assert(op.sinonI32Hex() == 0x7fffffff) -assert(op.sinonU32Hex() == 0xffffffff.toUInt()) -assert(op.sinonI64Hex() == 0x7fffffffffffffffL) -assert(op.sinonU64Hex() == 0xffffffffffffffffuL) - -// octal integers -assert(op.sinonU32Oct() == 493u) // 0o755 - -// floats -assert(op.sinonF32() == 42.0f) -assert(op.sinonF64() == 42.1) - -// enums -assert(op.sinonEnum() == Enumeration.TROIS) - -// Step 2. Convince ourselves that if we pass something else, then that changes the output. -// We have shown something coming out of the sinon methods, but without eyeballing the Rust -// we can't be sure that the arguments will change the return value. -listOf("foo", "bar").affirmAllerRetour(op::sinonString) -listOf(true, false).affirmAllerRetour(op::sinonBoolean) -listOf(listOf("a", "b"), listOf()).affirmAllerRetour(op::sinonSequence) - -// optionals -listOf("0", "1").affirmAllerRetour(op::sinonNull) -listOf(0, 1).affirmAllerRetour(op::sinonZero) - -// integers -listOf(0, 1).map { it.toUByte() }.affirmAllerRetour(op::sinonU8Dec) -listOf(0, 1).map { it.toByte() }.affirmAllerRetour(op::sinonI8Dec) -listOf(0, 1).map { it.toUShort() }.affirmAllerRetour(op::sinonU16Dec) -listOf(0, 1).map { it.toShort() }.affirmAllerRetour(op::sinonI16Dec) -listOf(0, 1).map { it.toUInt() }.affirmAllerRetour(op::sinonU32Dec) -listOf(0, 1).map { it.toInt() }.affirmAllerRetour(op::sinonI32Dec) -listOf(0, 1).map { it.toULong() }.affirmAllerRetour(op::sinonU64Dec) -listOf(0, 1).map { it.toLong() }.affirmAllerRetour(op::sinonI64Dec) - -listOf(0, 1).map { it.toUByte() }.affirmAllerRetour(op::sinonU8Hex) -listOf(0, 1).map { it.toByte() }.affirmAllerRetour(op::sinonI8Hex) -listOf(0, 1).map { it.toUShort() }.affirmAllerRetour(op::sinonU16Hex) -listOf(0, 1).map { it.toShort() }.affirmAllerRetour(op::sinonI16Hex) -listOf(0, 1).map { it.toUInt() }.affirmAllerRetour(op::sinonU32Hex) -listOf(0, 1).map { it.toInt() }.affirmAllerRetour(op::sinonI32Hex) -listOf(0, 1).map { it.toULong() }.affirmAllerRetour(op::sinonU64Hex) -listOf(0, 1).map { it.toLong() }.affirmAllerRetour(op::sinonI64Hex) - -listOf(0, 1).map { it.toUInt() }.affirmAllerRetour(op::sinonU32Oct) - -// floats -listOf(0.0f, 1.0f).affirmAllerRetour(op::sinonF32) -listOf(0.0, 1.0).affirmAllerRetour(op::sinonF64) - -// enums -Enumeration.values().toList().affirmAllerRetour(op::sinonEnum) - -op.destroy() - -// Testing defaulting properties in record types. -val defaultes = OptionneurDictionnaire() -val explicite = OptionneurDictionnaire( - i8Var = -8, - u8Var = 8u, - i16Var = -16, - u16Var = 0x10u, - i32Var = -32, - u32Var = 32u, - i64Var = -64L, - u64Var = 64uL, - floatVar = 4.0f, - doubleVar = 8.0, - booleanVar = true, - stringVar = "default", - listVar = listOf(), - enumerationVar = Enumeration.DEUX, - dictionnaireVar = null -) -assert(defaultes == explicite) - -// …and makes sure they travel across and back the FFI. -val rt2 = Retourneur() -listOf(defaultes).affirmAllerRetour(rt2::identiqueOptionneurDictionnaire) - -rt2.destroy() diff --git a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py b/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py deleted file mode 100644 index ecfcc1e527d6..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py +++ /dev/null @@ -1,146 +0,0 @@ -import sys -import ctypes -from rondpoint import * - -dico = Dictionnaire(Enumeration.DEUX, True, 0, 123456789) -copyDico = copie_dictionnaire(dico) -assert dico == copyDico - -assert copie_enumeration(Enumeration.DEUX) == Enumeration.DEUX -assert copie_enumerations([Enumeration.UN, Enumeration.DEUX]) == [Enumeration.UN, Enumeration.DEUX] -assert copie_carte({ - "0": EnumerationAvecDonnees.ZERO(), - "1": EnumerationAvecDonnees.UN(1), - "2": EnumerationAvecDonnees.DEUX(2, "deux"), -}) == { - "0": EnumerationAvecDonnees.ZERO(), - "1": EnumerationAvecDonnees.UN(1), - "2": EnumerationAvecDonnees.DEUX(2, "deux"), -} - -assert switcheroo(False) is True - -assert EnumerationAvecDonnees.ZERO() != EnumerationAvecDonnees.UN(1) -assert EnumerationAvecDonnees.UN(1) == EnumerationAvecDonnees.UN(1) -assert EnumerationAvecDonnees.UN(1) != EnumerationAvecDonnees.UN(2) - -# Test the roundtrip across the FFI. -# This shows that the values we send come back in exactly the same state as we sent them. -# i.e. it shows that lowering from python and lifting into rust is symmetrical with -# lowering from rust and lifting into python. -rt = Retourneur() - -def affirmAllerRetour(vals, identique): - for v in vals: - id_v = identique(v) - assert id_v == v, f"Round-trip failure: {v} => {id_v}" - -MIN_I8 = -1 * 2**7 -MAX_I8 = 2**7 - 1 -MIN_I16 = -1 * 2**15 -MAX_I16 = 2**15 - 1 -MIN_I32 = -1 * 2**31 -MAX_I32 = 2**31 - 1 -MIN_I64 = -1 * 2**31 -MAX_I64 = 2**31 - 1 - -# Python floats are always doubles, so won't round-trip through f32 correctly. -# This truncates them appropriately. -F32_ONE_THIRD = ctypes.c_float(1.0 / 3).value - -# Booleans -affirmAllerRetour([True, False], rt.identique_boolean) - -# Bytes. -affirmAllerRetour([MIN_I8, -1, 0, 1, MAX_I8], rt.identique_i8) -affirmAllerRetour([0x00, 0x12, 0xFF], rt.identique_u8) - -# Shorts -affirmAllerRetour([MIN_I16, -1, 0, 1, MAX_I16], rt.identique_i16) -affirmAllerRetour([0x0000, 0x1234, 0xFFFF], rt.identique_u16) - -# Ints -affirmAllerRetour([MIN_I32, -1, 0, 1, MAX_I32], rt.identique_i32) -affirmAllerRetour([0x00000000, 0x12345678, 0xFFFFFFFF], rt.identique_u32) - -# Longs -affirmAllerRetour([MIN_I64, -1, 0, 1, MAX_I64], rt.identique_i64) -affirmAllerRetour([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], rt.identique_u64) - -# Floats -affirmAllerRetour([0.0, 0.5, 0.25, 1.0, F32_ONE_THIRD], rt.identique_float) - -# Doubles -affirmAllerRetour( - [0.0, 0.5, 0.25, 1.0, 1.0 / 3, sys.float_info.max, sys.float_info.min], - rt.identique_double -) - -# Strings -affirmAllerRetour( - ["", "abc", "été", "ښي لاس ته لوستلو لوستل", "😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama"], - rt.identique_string -) - -# Test one way across the FFI. -# -# We send one representation of a value to lib.rs, and it transforms it into another, a string. -# lib.rs sends the string back, and then we compare here in python. -# -# This shows that the values are transformed into strings the same way in both python and rust. -# i.e. if we assume that the string return works (we test this assumption elsewhere) -# we show that lowering from python and lifting into rust has values that both python and rust -# both stringify in the same way. i.e. the same values. -# -# If we roundtripping proves the symmetry of our lowering/lifting from here to rust, and lowering/lifting from rust to here, -# and this convinces us that lowering/lifting from here to rust is correct, then -# together, we've shown the correctness of the return leg. -st = Stringifier() - -def affirmEnchaine(vals, toString, rustyStringify=lambda v: str(v).lower()): - for v in vals: - str_v = toString(v) - assert rustyStringify(v) == str_v, f"String compare error {v} => {str_v}" - -# Test the efficacy of the string transport from rust. If this fails, but everything else -# works, then things are very weird. -wellKnown = st.well_known_string("python") -assert "uniffi 💚 python!" == wellKnown - -# Booleans -affirmEnchaine([True, False], st.to_string_boolean) - -# Bytes. -affirmEnchaine([MIN_I8, -1, 0, 1, MAX_I8], st.to_string_i8) -affirmEnchaine([0x00, 0x12, 0xFF], st.to_string_u8) - -# Shorts -affirmEnchaine([MIN_I16, -1, 0, 1, MAX_I16], st.to_string_i16) -affirmEnchaine([0x0000, 0x1234, 0xFFFF], st.to_string_u16) - -# Ints -affirmEnchaine([MIN_I32, -1, 0, 1, MAX_I32], st.to_string_i32) -affirmEnchaine([0x00000000, 0x12345678, 0xFFFFFFFF], st.to_string_u32) - -# Longs -affirmEnchaine([MIN_I64, -1, 0, 1, MAX_I64], st.to_string_i64) -affirmEnchaine([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], st.to_string_u64) - -# Floats -def rustyFloatToStr(v): - """Stringify a float in the same way that rust seems to.""" - # Rust doesn't include the decimal part of whole enumber floats when stringifying. - if int(v) == v: - return str(int(v)) - return str(v) - -affirmEnchaine([0.0, 0.5, 0.25, 1.0], st.to_string_float, rustyFloatToStr) -assert st.to_string_float(F32_ONE_THIRD) == "0.33333334" # annoyingly different string repr - -# Doubles -# TODO: float_info.max/float_info.min don't stringify-roundtrip properly yet, TBD. -affirmEnchaine( - [0.0, 0.5, 0.25, 1.0, 1.0 / 3], - st.to_string_double, - rustyFloatToStr, -) diff --git a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.rb b/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.rb deleted file mode 100644 index 0121f6e0f91a..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.rb +++ /dev/null @@ -1,142 +0,0 @@ -# frozen_string_literal: true - -require 'test/unit' -require 'rondpoint' - -include Test::Unit::Assertions -include Rondpoint - -dico = Dictionnaire.new Enumeration::DEUX, true, 0, 123_456_789 - -assert_equal dico, Rondpoint.copie_dictionnaire(dico) - -assert_equal Rondpoint.copie_enumeration(Enumeration::DEUX), Enumeration::DEUX - -assert_equal Rondpoint.copie_enumerations([ - Enumeration::UN, - Enumeration::DEUX - ]), [Enumeration::UN, Enumeration::DEUX] - -assert_equal Rondpoint.copie_carte({ - '0' => EnumerationAvecDonnees::ZERO.new, - '1' => EnumerationAvecDonnees::UN.new(1), - '2' => EnumerationAvecDonnees::DEUX.new(2, 'deux') - }), { - '0' => EnumerationAvecDonnees::ZERO.new, - '1' => EnumerationAvecDonnees::UN.new(1), - '2' => EnumerationAvecDonnees::DEUX.new(2, 'deux') - } - -assert Rondpoint.switcheroo(false) - -assert_not_equal EnumerationAvecDonnees::ZERO.new, EnumerationAvecDonnees::UN.new(1) -assert_equal EnumerationAvecDonnees::UN.new(1), EnumerationAvecDonnees::UN.new(1) -assert_not_equal EnumerationAvecDonnees::UN.new(1), EnumerationAvecDonnees::UN.new(2) - -# Test the roundtrip across the FFI. -# This shows that the values we send come back in exactly the same state as we sent them. -# i.e. it shows that lowering from ruby and lifting into rust is symmetrical with -# lowering from rust and lifting into ruby. -RT = Retourneur.new - -def affirm_aller_retour(vals, fn_name) - vals.each do |v| - id_v = RT.public_send fn_name, v - - assert_equal id_v, v, "Round-trip failure: #{v} => #{id_v}" - end -end - -MIN_I8 = -1 * 2**7 -MAX_I8 = 2**7 - 1 -MIN_I16 = -1 * 2**15 -MAX_I16 = 2**15 - 1 -MIN_I32 = -1 * 2**31 -MAX_I32 = 2**31 - 1 -MIN_I64 = -1 * 2**31 -MAX_I64 = 2**31 - 1 - -# Ruby floats are always doubles, so won't round-trip through f32 correctly. -# This truncates them appropriately. -F32_ONE_THIRD = [1.0 / 3].pack('f').unpack('f')[0] - -# Booleans -affirm_aller_retour([true, false], :identique_boolean) - -# Bytes. -affirm_aller_retour([MIN_I8, -1, 0, 1, MAX_I8], :identique_i8) -affirm_aller_retour([0x00, 0x12, 0xFF], :identique_u8) - -# Shorts -affirm_aller_retour([MIN_I16, -1, 0, 1, MAX_I16], :identique_i16) -affirm_aller_retour([0x0000, 0x1234, 0xFFFF], :identique_u16) - -# Ints -affirm_aller_retour([MIN_I32, -1, 0, 1, MAX_I32], :identique_i32) -affirm_aller_retour([0x00000000, 0x12345678, 0xFFFFFFFF], :identique_u32) - -# Longs -affirm_aller_retour([MIN_I64, -1, 0, 1, MAX_I64], :identique_i64) -affirm_aller_retour([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], :identique_u64) - -# Floats -affirm_aller_retour([0.0, 0.5, 0.25, 1.0, F32_ONE_THIRD], :identique_float) - -# Doubles -affirm_aller_retour( - [0.0, 0.5, 0.25, 1.0, 1.0 / 3, Float::MAX, Float::MIN], - :identique_double -) - -# Strings -affirm_aller_retour( - ['', 'abc', 'été', 'ښي لاس ته لوستلو لوستل', - '😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama'], - :identique_string -) - -# Test one way across the FFI. -# -# We send one representation of a value to lib.rs, and it transforms it into another, a string. -# lib.rs sends the string back, and then we compare here in ruby. -# -# This shows that the values are transformed into strings the same way in both ruby and rust. -# i.e. if we assume that the string return works (we test this assumption elsewhere) -# we show that lowering from ruby and lifting into rust has values that both ruby and rust -# both stringify in the same way. i.e. the same values. -# -# If we roundtripping proves the symmetry of our lowering/lifting from here to rust, and lowering/lifting from rust to here, -# and this convinces us that lowering/lifting from here to rust is correct, then -# together, we've shown the correctness of the return leg. -ST = Stringifier.new - -def affirm_enchaine(vals, fn_name) - vals.each do |v| - str_v = ST.public_send fn_name, v - - assert_equal v.to_s, str_v, "String compare error #{v} => #{str_v}" - end -end - -# Test the efficacy of the string transport from rust. If this fails, but everything else -# works, then things are very weird. -assert_equal ST.well_known_string('ruby'), 'uniffi 💚 ruby!' - -# Booleans -affirm_enchaine([true, false], :to_string_boolean) - -# Bytes. -affirm_enchaine([MIN_I8, -1, 0, 1, MAX_I8], :to_string_i8) -affirm_enchaine([0x00, 0x12, 0xFF], :to_string_u8) - -# Shorts -affirm_enchaine([MIN_I16, -1, 0, 1, MAX_I16], :to_string_i16) -affirm_enchaine([0x0000, 0x1234, 0xFFFF], :to_string_u16) - -# Ints -affirm_enchaine([MIN_I32, -1, 0, 1, MAX_I32], :to_string_i32) -affirm_enchaine([0x00000000, 0x12345678, 0xFFFFFFFF], :to_string_u32) - -# Longs -affirm_enchaine([MIN_I64, -1, 0, 1, MAX_I64], :to_string_i64) -affirm_enchaine([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], :to_string_u64) diff --git a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.swift b/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.swift deleted file mode 100644 index 756f1b8a441e..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.swift +++ /dev/null @@ -1,232 +0,0 @@ -import rondpoint - -let dico = Dictionnaire(un: .deux, deux: false, petitNombre: 0, grosNombre: 123456789) -let copyDico = copieDictionnaire(d: dico) -assert(dico == copyDico) - -assert(copieEnumeration(e: .deux) == .deux) -assert(copieEnumerations(e: [.un, .deux]) == [.un, .deux]) -assert(copieCarte(c: - ["0": .zero, - "1": .un(premier: 1), - "2": .deux(premier: 2, second: "deux") -]) == [ - "0": .zero, - "1": .un(premier: 1), - "2": .deux(premier: 2, second: "deux") -]) - -assert(EnumerationAvecDonnees.zero != EnumerationAvecDonnees.un(premier: 1)) -assert(EnumerationAvecDonnees.un(premier: 1) == EnumerationAvecDonnees.un(premier: 1)) -assert(EnumerationAvecDonnees.un(premier: 1) != EnumerationAvecDonnees.un(premier: 2)) - - -assert(switcheroo(b: false)) - -// Test the roundtrip across the FFI. -// This shows that the values we send come back in exactly the same state as we sent them. -// i.e. it shows that lowering from swift and lifting into rust is symmetrical with -// lowering from rust and lifting into swift. -let rt = Retourneur() - -// Booleans -[true, false].affirmAllerRetour(rt.identiqueBoolean) - -// Bytes. -[.min, .max].affirmAllerRetour(rt.identiqueI8) -[0x00, 0xFF].map { $0 as UInt8 }.affirmAllerRetour(rt.identiqueU8) - -// Shorts -[.min, .max].affirmAllerRetour(rt.identiqueI16) -[0x0000, 0xFFFF].map { $0 as UInt16 }.affirmAllerRetour(rt.identiqueU16) - -// Ints -[0, 1, -1, .min, .max].affirmAllerRetour(rt.identiqueI32) -[0x00000000, 0xFFFFFFFF].map { $0 as UInt32 }.affirmAllerRetour(rt.identiqueU32) - -// Longs -[.zero, 1, -1, .min, .max].affirmAllerRetour(rt.identiqueI64) -[.zero, 1, .min, .max].affirmAllerRetour(rt.identiqueU64) - -// Floats -[.zero, 1, 0.25, .leastNonzeroMagnitude, .greatestFiniteMagnitude].affirmAllerRetour(rt.identiqueFloat) - -// Doubles -[0.0, 1.0, .leastNonzeroMagnitude, .greatestFiniteMagnitude].affirmAllerRetour(rt.identiqueDouble) - -// Strings -["", "abc", "null\0byte", "été", "ښي لاس ته لوستلو لوستل", "😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama"] - .affirmAllerRetour(rt.identiqueString) - -// Test one way across the FFI. -// -// We send one representation of a value to lib.rs, and it transforms it into another, a string. -// lib.rs sends the string back, and then we compare here in swift. -// -// This shows that the values are transformed into strings the same way in both swift and rust. -// i.e. if we assume that the string return works (we test this assumption elsewhere) -// we show that lowering from swift and lifting into rust has values that both swift and rust -// both stringify in the same way. i.e. the same values. -// -// If we roundtripping proves the symmetry of our lowering/lifting from here to rust, and lowering/lifting from rust t here, -// and this convinces us that lowering/lifting from here to rust is correct, then -// together, we've shown the correctness of the return leg. -let st = Stringifier() - -// Test the effigacy of the string transport from rust. If this fails, but everything else -// works, then things are very weird. -let wellKnown = st.wellKnownString(value: "swift") -assert("uniffi 💚 swift!" == wellKnown, "wellKnownString 'uniffi 💚 swift!' == '\(wellKnown)'") - -// Booleans -[true, false].affirmEnchaine(st.toStringBoolean) - -// Bytes. -[.min, .max].affirmEnchaine(st.toStringI8) -[.min, .max].affirmEnchaine(st.toStringU8) - -// Shorts -[.min, .max].affirmEnchaine(st.toStringI16) -[.min, .max].affirmEnchaine(st.toStringU16) - -// Ints -[0, 1, -1, .min, .max].affirmEnchaine(st.toStringI32) -[0, 1, .min, .max].affirmEnchaine(st.toStringU32) - -// Longs -[.zero, 1, -1, .min, .max].affirmEnchaine(st.toStringI64) -[.zero, 1, .min, .max].affirmEnchaine(st.toStringU64) - -// Floats -[.zero, 1, -1, .leastNonzeroMagnitude, .greatestFiniteMagnitude].affirmEnchaine(st.toStringFloat) { Float.init($0) == $1 } - -// Doubles -[.zero, 1, -1, .leastNonzeroMagnitude, .greatestFiniteMagnitude].affirmEnchaine(st.toStringDouble) { Double.init($0) == $1 } - -// Some extension functions for testing the results of roundtripping and stringifying -extension Array where Element: Equatable { - static func defaultEquals(_ observed: String, expected: Element) -> Bool { - let exp = "\(expected)" - return observed == exp - } - - func affirmEnchaine(_ fn: (Element) -> String, equals: (String, Element) -> Bool = defaultEquals) { - self.forEach { v in - let obs = fn(v) - assert(equals(obs, v), "toString_\(type(of:v))(\(v)): observed=\(obs), expected=\(v)") - } - } - - func affirmAllerRetour(_ fn: (Element) -> Element) { - self.forEach { v in - assert(fn(v) == v, "identique_\(type(of:v))(\(v))") - } - } -} - -// Prove to ourselves that default arguments are being used. -// Step 1: call the methods without arguments, and check against the UDL. -let op = Optionneur() - -assert(op.sinonString() == "default") - -assert(op.sinonBoolean() == false) - -assert(op.sinonSequence() == []) - -// optionals -assert(op.sinonNull() == nil) -assert(op.sinonZero() == 0) - -// decimal integers -assert(op.sinonU8Dec() == UInt8(42)) -assert(op.sinonI8Dec() == Int8(-42)) -assert(op.sinonU16Dec() == UInt16(42)) -assert(op.sinonI16Dec() == Int16(42)) -assert(op.sinonU32Dec() == UInt32(42)) -assert(op.sinonI32Dec() == Int32(42)) -assert(op.sinonU64Dec() == UInt64(42)) -assert(op.sinonI64Dec() == Int64(42)) - -// hexadecimal integers -assert(op.sinonU8Hex() == UInt8(0xff)) -assert(op.sinonI8Hex() == Int8(-0x7f)) -assert(op.sinonU16Hex() == UInt16(0xffff)) -assert(op.sinonI16Hex() == Int16(0x7f)) -assert(op.sinonU32Hex() == UInt32(0xffffffff)) -assert(op.sinonI32Hex() == Int32(0x7fffffff)) -assert(op.sinonU64Hex() == UInt64(0xffffffffffffffff)) -assert(op.sinonI64Hex() == Int64(0x7fffffffffffffff)) - -// octal integers -assert(op.sinonU32Oct() == UInt32(0o755)) - -// floats -assert(op.sinonF32() == 42.0) -assert(op.sinonF64() == Double(42.1)) - -// enums -assert(op.sinonEnum() == .trois) - -// Step 2. Convince ourselves that if we pass something else, then that changes the output. -// We have shown something coming out of the sinon methods, but without eyeballing the Rust -// we can't be sure that the arguments will change the return value. -["foo", "bar"].affirmAllerRetour(op.sinonString) -[true, false].affirmAllerRetour(op.sinonBoolean) -[["a", "b"], []].affirmAllerRetour(op.sinonSequence) - -// optionals -["0", "1"].affirmAllerRetour(op.sinonNull) -[0, 1].affirmAllerRetour(op.sinonZero) - -// integers -[0, 1].affirmAllerRetour(op.sinonU8Dec) -[0, 1].affirmAllerRetour(op.sinonI8Dec) -[0, 1].affirmAllerRetour(op.sinonU16Dec) -[0, 1].affirmAllerRetour(op.sinonI16Dec) -[0, 1].affirmAllerRetour(op.sinonU32Dec) -[0, 1].affirmAllerRetour(op.sinonI32Dec) -[0, 1].affirmAllerRetour(op.sinonU64Dec) -[0, 1].affirmAllerRetour(op.sinonI64Dec) - -[0, 1].affirmAllerRetour(op.sinonU8Hex) -[0, 1].affirmAllerRetour(op.sinonI8Hex) -[0, 1].affirmAllerRetour(op.sinonU16Hex) -[0, 1].affirmAllerRetour(op.sinonI16Hex) -[0, 1].affirmAllerRetour(op.sinonU32Hex) -[0, 1].affirmAllerRetour(op.sinonI32Hex) -[0, 1].affirmAllerRetour(op.sinonU64Hex) -[0, 1].affirmAllerRetour(op.sinonI64Hex) - -[0, 1].affirmAllerRetour(op.sinonU32Oct) - -// floats -[0.0, 1.0].affirmAllerRetour(op.sinonF32) -[0.0, 1.0].affirmAllerRetour(op.sinonF64) - -// enums -[.un, .deux, .trois].affirmAllerRetour(op.sinonEnum) - -// Testing defaulting properties in record types. -let defaultes = OptionneurDictionnaire() -let explicite = OptionneurDictionnaire( - i8Var: Int8(-8), - u8Var: UInt8(8), - i16Var: Int16(-16), - u16Var: UInt16(0x10), - i32Var: -32, - u32Var: UInt32(32), - i64Var: Int64(-64), - u64Var: UInt64(64), - floatVar: Float(4.0), - doubleVar: Double(8.0), - booleanVar: true, - stringVar: "default", - listVar: [], - enumerationVar: .deux, - dictionnaireVar: nil -) - -// …and makes sure they travel across and back the FFI. -assert(defaultes == explicite) -[defaultes].affirmAllerRetour(rt.identiqueOptionneurDictionnaire) diff --git a/third_party/rust/uniffi-example-rondpoint/tests/test_generated_bindings.rs b/third_party/rust/uniffi-example-rondpoint/tests/test_generated_bindings.rs deleted file mode 100644 index ddf705708c0b..000000000000 --- a/third_party/rust/uniffi-example-rondpoint/tests/test_generated_bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -uniffi_macros::build_foreign_language_testcases!( - ["src/rondpoint.udl",], - [ - "tests/bindings/test_rondpoint.kts", - "tests/bindings/test_rondpoint.swift", - "tests/bindings/test_rondpoint.py", - "tests/bindings/test_rondpoint.rb", - ] -); diff --git a/third_party/rust/uniffi-example-sprites/.cargo-checksum.json b/third_party/rust/uniffi-example-sprites/.cargo-checksum.json deleted file mode 100644 index ee54d4851c89..000000000000 --- a/third_party/rust/uniffi-example-sprites/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"b288fc6b1e909cffdb5171a247f268884a2483d9f97f1a24a679681fb418bd8d","build.rs":"d36e4ff477007611d216e60998d6d8a51b33895bb95159e3d7732e2b8cbc1783","src/lib.rs":"79ae1ea584942b25c108a26df79a781a63d66f8fb37c4dacfc04d180752effcb","src/sprites.udl":"bfd35f04ba0549301189dfb8fc45b0f39bad00956c324f33be0e845fb7ff78aa","tests/bindings/test_sprites.kts":"06ed115325f37ce59ed6f33e2d651cd2aa352fddcc644580f62a6da6ca075844","tests/bindings/test_sprites.py":"2e6ce838cfb387586257703c3500062438e840dd7ae57d185cdc244dc0745b8f","tests/bindings/test_sprites.rb":"6289a1833c7c8f4583ee4f0488d680de2ee46cfb203095a9b66d7234e2f07d53","tests/bindings/test_sprites.swift":"b2c0a6f4d5edfd7de7c2ba77b838865ffda153a6f364f273456175192d3e6e00","tests/test_generated_bindings.rs":"920c532011c8a6c20bdb1f39c50ef7a2803729a62a1bd425d81e40300958778a"},"package":null} \ No newline at end of file diff --git a/third_party/rust/uniffi-example-sprites/Cargo.toml b/third_party/rust/uniffi-example-sprites/Cargo.toml deleted file mode 100644 index 78522095c3f6..000000000000 --- a/third_party/rust/uniffi-example-sprites/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "uniffi-example-sprites" -edition = "2021" -version = "0.18.0" -authors = ["Firefox Sync Team "] -license = "MPL-2.0" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] -name = "uniffi_sprites" - -[dependencies] -uniffi_macros = {path = "../../uniffi_macros"} -uniffi = {path = "../../uniffi", features=["builtin-bindgen"]} - -[build-dependencies] -uniffi_build = {path = "../../uniffi_build", features=["builtin-bindgen"]} diff --git a/third_party/rust/uniffi-example-sprites/build.rs b/third_party/rust/uniffi-example-sprites/build.rs deleted file mode 100644 index b3c6311be589..000000000000 --- a/third_party/rust/uniffi-example-sprites/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -fn main() { - uniffi_build::generate_scaffolding("./src/sprites.udl").unwrap(); -} diff --git a/third_party/rust/uniffi-example-sprites/src/lib.rs b/third_party/rust/uniffi-example-sprites/src/lib.rs deleted file mode 100644 index 6417cc0a06b2..000000000000 --- a/third_party/rust/uniffi-example-sprites/src/lib.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use std::sync::RwLock; - -// A point in two-dimensional space. -#[derive(Debug, Clone)] -pub struct Point { - x: f64, - y: f64, -} - -// A magnitude and direction in two-dimensional space. -// For simplicity we represent this as a point relative to the origin. -#[derive(Debug, Clone)] -pub struct Vector { - dx: f64, - dy: f64, -} - -// Move from the given Point, according to the given Vector. -pub fn translate(p: &Point, v: Vector) -> Point { - Point { - x: p.x + v.dx, - y: p.y + v.dy, - } -} - -// An entity in our imaginary world, which occupies a position in space -// and which can move about over time. -#[derive(Debug)] -pub struct Sprite { - // We must use interior mutability for managing mutable state, hence the `RwLock`. - current_position: RwLock, -} - -impl Sprite { - fn new(initial_position: Option) -> Sprite { - Sprite { - current_position: RwLock::new(initial_position.unwrap_or(Point { x: 0.0, y: 0.0 })), - } - } - - fn new_relative_to(reference: Point, direction: Vector) -> Sprite { - Sprite { - current_position: RwLock::new(translate(&reference, direction)), - } - } - - fn get_position(&self) -> Point { - self.current_position.read().unwrap().clone() - } - - fn move_to(&self, position: Point) { - *self.current_position.write().unwrap() = position; - } - - fn move_by(&self, direction: Vector) { - let mut current_position = self.current_position.write().unwrap(); - *current_position = translate(&*current_position, direction) - } -} - -include!(concat!(env!("OUT_DIR"), "/sprites.uniffi.rs")); diff --git a/third_party/rust/uniffi-example-sprites/src/sprites.udl b/third_party/rust/uniffi-example-sprites/src/sprites.udl deleted file mode 100644 index 6781c6cee5fe..000000000000 --- a/third_party/rust/uniffi-example-sprites/src/sprites.udl +++ /dev/null @@ -1,22 +0,0 @@ - -namespace sprites { - Point translate([ByRef] Point position, Vector direction); -}; - -dictionary Point { - double x; - double y; -}; - -dictionary Vector { - double dx; - double dy; -}; - -interface Sprite { - constructor(Point? initial_position); - [Name=new_relative_to] constructor(Point reference, Vector direction); - Point get_position(); - void move_to(Point position); - void move_by(Vector direction); -}; diff --git a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.kts b/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.kts deleted file mode 100644 index 42451f28ddc8..000000000000 --- a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.kts +++ /dev/null @@ -1,25 +0,0 @@ -import uniffi.sprites.*; - -val sempty = Sprite(null) -assert( sempty.getPosition() == Point(0.0, 0.0) ) - -val s = Sprite(Point(0.0, 1.0)) -assert( s.getPosition() == Point(0.0, 1.0) ) - -s.moveTo(Point(1.0, 2.0)) -assert( s.getPosition() == Point(1.0, 2.0) ) - -s.moveBy(Vector(-4.0, 2.0)) -assert( s.getPosition() == Point(-3.0, 4.0) ) - -s.destroy() -try { - s.moveBy(Vector(0.0, 0.0)) - assert(false) { "Should not be able to call anything after `destroy`" } -} catch(e: IllegalStateException) { - assert(true) -} - -val srel = Sprite.newRelativeTo(Point(0.0, 1.0), Vector(1.0, 1.5)) -assert( srel.getPosition() == Point(1.0, 2.5) ) - diff --git a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.py b/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.py deleted file mode 100644 index 5142c2fc42e9..000000000000 --- a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.py +++ /dev/null @@ -1,17 +0,0 @@ -from sprites import * - -sempty = Sprite(None) -assert sempty.get_position() == Point(0, 0) - -s = Sprite(Point(0, 1)) -assert s.get_position() == Point(0, 1) - -s.move_to(Point(1, 2)) -assert s.get_position() == Point(1, 2) - -s.move_by(Vector(-4, 2)) -assert s.get_position() == Point(-3, 4) - -srel = Sprite.new_relative_to(Point(0, 1), Vector(1, 1.5)) -assert srel.get_position() == Point(1, 2.5) - diff --git a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.rb b/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.rb deleted file mode 100644 index 9d79b57026f9..000000000000 --- a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'test/unit' -require 'sprites' - -include Test::Unit::Assertions -include Sprites - -sempty = Sprite.new(nil) -assert_equal sempty.get_position, Point.new(0, 0) - -s = Sprite.new(Point.new(0, 1)) -assert_equal s.get_position, Point.new(0, 1) - -s.move_to(Point.new(1, 2)) -assert_equal s.get_position, Point.new(1, 2) - -s.move_by(Vector.new(-4, 2)) -assert_equal s.get_position, Point.new(-3, 4) - -srel = Sprite.new_relative_to(Point.new(0, 1), Vector.new(1, 1.5)) -assert_equal srel.get_position, Point.new(1, 2.5) diff --git a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.swift b/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.swift deleted file mode 100644 index d5428ac6790f..000000000000 --- a/third_party/rust/uniffi-example-sprites/tests/bindings/test_sprites.swift +++ /dev/null @@ -1,16 +0,0 @@ -import sprites - -let sempty = Sprite(initialPosition: nil) -assert( sempty.getPosition() == Point(x: 0, y: 0)) - -let s = Sprite(initialPosition: Point(x: 0, y: 1)) -assert( s.getPosition() == Point(x: 0, y: 1)) - -s.moveTo(position: Point(x: 1.0, y: 2.0)) -assert( s.getPosition() == Point(x: 1, y: 2)) - -s.moveBy(direction: Vector(dx: -4, dy: 2)) -assert( s.getPosition() == Point(x: -3, y: 4)) - -let srel = Sprite.newRelativeTo(reference: Point(x: 0.0, y: 1.0), direction: Vector(dx: 1, dy: 1.5)) -assert( srel.getPosition() == Point(x: 1.0, y: 2.5) ) diff --git a/third_party/rust/uniffi-example-sprites/tests/test_generated_bindings.rs b/third_party/rust/uniffi-example-sprites/tests/test_generated_bindings.rs deleted file mode 100644 index 7a4d2cf0e93d..000000000000 --- a/third_party/rust/uniffi-example-sprites/tests/test_generated_bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -uniffi_macros::build_foreign_language_testcases!( - ["src/sprites.udl",], - [ - "tests/bindings/test_sprites.py", - "tests/bindings/test_sprites.rb", - "tests/bindings/test_sprites.kts", - "tests/bindings/test_sprites.swift", - ] -); diff --git a/third_party/rust/uniffi-example-todolist/.cargo-checksum.json b/third_party/rust/uniffi-example-todolist/.cargo-checksum.json deleted file mode 100644 index 8f8dd538bfcb..000000000000 --- a/third_party/rust/uniffi-example-todolist/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{"Cargo.toml":"4f4fc40bccf4ca5b105ea2abdbcdc6758ba7271d7d4ceb1e8ed45e3de227c2a6","build.rs":"ca26833c671cfe14a8275c276c197ab228cb1639b34cae31bb3805221ecc1245","src/lib.rs":"6a38904924681aed26b74876ad0480fedf8e8b2640cd2b04531a55aba8fc5592","src/todolist.udl":"1f8a24049c2340b9184e95facfc191ecdcb91541729ae7f20b4625d67685f13c","tests/bindings/test_todolist.kts":"f3d29b48e0193563fc4f131d91ea697f758174dcdb80ea554f233949e575bf55","tests/bindings/test_todolist.py":"f7430af9347df0daa954d38bc2203ce400affbb9a53fced4bb67a6796afa0664","tests/bindings/test_todolist.rb":"6524b5271a9cc0e2d78ca9f86ccb6973889926688a0843b4505a4f62d48f6dcb","tests/bindings/test_todolist.swift":"d1911b85fe0c8c0b42e5421b5af5d7359c9a65bba477d23560eb4b0f52e80662","tests/test_generated_bindings.rs":"25108de454213659c3eacd643a24c49099757a6b6da501fdb50874f574bd30c5"},"package":null} \ No newline at end of file diff --git a/third_party/rust/uniffi-example-todolist/Cargo.toml b/third_party/rust/uniffi-example-todolist/Cargo.toml deleted file mode 100644 index d1a1df82a344..000000000000 --- a/third_party/rust/uniffi-example-todolist/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "uniffi-example-todolist" -edition = "2021" -version = "0.18.0" -authors = ["Firefox Sync Team "] -license = "MPL-2.0" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] -name = "uniffi_todolist" - -[dependencies] -uniffi_macros = {path = "../../uniffi_macros"} -uniffi = {path = "../../uniffi", features=["builtin-bindgen"]} -thiserror = "1.0" -lazy_static = "1.4" - -[build-dependencies] -uniffi_build = {path = "../../uniffi_build", features=["builtin-bindgen"]} diff --git a/third_party/rust/uniffi-example-todolist/build.rs b/third_party/rust/uniffi-example-todolist/build.rs deleted file mode 100644 index ebd0a79e41c7..000000000000 --- a/third_party/rust/uniffi-example-todolist/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -fn main() { - uniffi_build::generate_scaffolding("./src/todolist.udl").unwrap(); -} diff --git a/third_party/rust/uniffi-example-todolist/src/lib.rs b/third_party/rust/uniffi-example-todolist/src/lib.rs deleted file mode 100644 index fff8145402bb..000000000000 --- a/third_party/rust/uniffi-example-todolist/src/lib.rs +++ /dev/null @@ -1,150 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use std::sync::{Arc, RwLock}; - -#[derive(Debug, Clone)] -pub struct TodoEntry { - text: String, -} - -lazy_static::lazy_static! { - // There is a single "default" TodoList that can be shared - // by all consumers of this component. Depending on requirements, - // a real app might like to use a `Weak<>` rather than an `Arc<>` - // here to reduce the risk of circular references. - static ref DEFAULT_LIST: RwLock>> = RwLock::new(None); -} - -#[derive(Debug, thiserror::Error)] -pub enum TodoError { - #[error("The todo does not exist!")] - TodoDoesNotExist, - #[error("The todolist is empty!")] - EmptyTodoList, - #[error("That todo already exists!")] - DuplicateTodo, - #[error("Empty String error!: {0}")] - EmptyString(String), - #[error("I am a delegated Error: {0}")] - DeligatedError(#[from] std::io::Error), -} - -/// Get a reference to the global default TodoList, if set. -/// -fn get_default_list() -> Option> { - DEFAULT_LIST.read().unwrap().clone() -} - -/// Set the global default TodoList. -/// -/// This will silently drop any previously set value. -/// -fn set_default_list(list: Arc) { - *DEFAULT_LIST.write().unwrap() = Some(list); -} - -/// Create a new TodoEntry from the given string. -/// -fn create_entry_with>(item: S) -> Result { - let text = item.into(); - if text.is_empty() { - return Err(TodoError::EmptyString( - "Cannot add empty string as entry".to_string(), - )); - } - Ok(TodoEntry { text }) -} - -type Result = std::result::Result; - -// A simple Todolist. -// UniFFI requires that we use interior mutability for managing mutable state, so we wrap our `Vec` in a RwLock. -// (A Mutex would also work, but a RwLock is more appropriate for this use-case, so we use it). -#[derive(Debug)] -pub struct TodoList { - items: RwLock>, -} - -impl TodoList { - fn new() -> Self { - Self { - items: RwLock::new(Vec::new()), - } - } - - fn add_item>(&self, item: S) -> Result<()> { - let item = item.into(); - if item.is_empty() { - return Err(TodoError::EmptyString( - "Cannot add empty string as item".to_string(), - )); - } - let mut items = self.items.write().unwrap(); - if items.contains(&item) { - return Err(TodoError::DuplicateTodo); - } - items.push(item); - Ok(()) - } - - fn get_last(&self) -> Result { - let items = self.items.read().unwrap(); - items.last().cloned().ok_or(TodoError::EmptyTodoList) - } - - fn get_first(&self) -> Result { - let items = self.items.read().unwrap(); - items.first().cloned().ok_or(TodoError::EmptyTodoList) - } - - fn add_entries(&self, entries: Vec) { - let mut items = self.items.write().unwrap(); - items.extend(entries.into_iter().map(|e| e.text)) - } - - fn add_entry(&self, entry: TodoEntry) -> Result<()> { - self.add_item(entry.text) - } - - fn add_items>(&self, items: Vec) { - let mut my_items = self.items.write().unwrap(); - my_items.extend(items.into_iter().map(Into::into)) - } - - fn get_items(&self) -> Vec { - let items = self.items.read().unwrap(); - items.clone() - } - - fn get_entries(&self) -> Vec { - let items = self.items.read().unwrap(); - items - .iter() - .map(|text| TodoEntry { text: text.clone() }) - .collect() - } - - fn get_last_entry(&self) -> Result { - let text = self.get_last()?; - Ok(TodoEntry { text }) - } - - fn clear_item>(&self, item: S) -> Result<()> { - let item = item.into(); - let mut items = self.items.write().unwrap(); - let idx = items - .iter() - .position(|s| s == &item) - .ok_or(TodoError::TodoDoesNotExist)?; - items.remove(idx); - Ok(()) - } - - fn make_default(self: Arc) { - set_default_list(self); - } -} - -include!(concat!(env!("OUT_DIR"), "/todolist.uniffi.rs")); diff --git a/third_party/rust/uniffi-example-todolist/src/todolist.udl b/third_party/rust/uniffi-example-todolist/src/todolist.udl deleted file mode 100644 index 5c923314cd6a..000000000000 --- a/third_party/rust/uniffi-example-todolist/src/todolist.udl +++ /dev/null @@ -1,38 +0,0 @@ -namespace todolist { - TodoList? get_default_list(); - undefined set_default_list(TodoList list); - - [Throws=TodoError] - TodoEntry create_entry_with(string todo); -}; - -dictionary TodoEntry { - string text; -}; - -[Error] -enum TodoError { - "TodoDoesNotExist", "EmptyTodoList", "DuplicateTodo", "EmptyString", "DeligatedError" -}; - -interface TodoList { - constructor(); - [Throws=TodoError] - void add_item(string todo); - [Throws=TodoError] - void add_entry(TodoEntry entry); - sequence get_entries(); - sequence get_items(); - void add_entries(sequence entries); - void add_items(sequence items); - [Throws=TodoError] - TodoEntry get_last_entry(); - [Throws=TodoError] - string get_last(); - [Throws=TodoError] - string get_first(); - [Throws=TodoError] - void clear_item(string todo); - [Self=ByArc] - undefined make_default(); -}; diff --git a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.kts b/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.kts deleted file mode 100644 index bb2b292224d0..000000000000 --- a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.kts +++ /dev/null @@ -1,83 +0,0 @@ -import uniffi.todolist.* - -val todo = TodoList() - -// This throws an exception: -try { - todo.getLast() - throw RuntimeException("Should have thrown a TodoError!") -} catch (e: TodoException.EmptyTodoList) { - // It's okay, we don't have any items yet! -} - -try { - createEntryWith("") - throw RuntimeException("Should have thrown a TodoError!") -} catch (e: TodoException) { - // It's okay, the string was empty! - assert(e is TodoException.EmptyString) - assert(e !is TodoException.EmptyTodoList) -} - -todo.addItem("Write strings support") - -assert(todo.getLast() == "Write strings support") - -todo.addItem("Write tests for strings support") - -assert(todo.getLast() == "Write tests for strings support") - -val entry = createEntryWith("Write bindings for strings as record members") - -todo.addEntry(entry) -assert(todo.getLast() == "Write bindings for strings as record members") -assert(todo.getLastEntry().text == "Write bindings for strings as record members") - -todo.addItem("Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") -assert(todo.getLast() == "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") - -val entry2 = TodoEntry("Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") -todo.addEntry(entry2) -assert(todo.getLastEntry().text == "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") - -assert(todo.getEntries().size == 5) - -todo.addEntries(listOf(TodoEntry("foo"), TodoEntry("bar"))) -assert(todo.getEntries().size == 7) -assert(todo.getLastEntry().text == "bar") - -todo.addItems(listOf("bobo", "fofo")) -assert(todo.getItems().size == 9) -assert(todo.getItems()[7] == "bobo") - -assert(getDefaultList() == null) - -// Note that each individual object instance needs to be explicitly destroyed, -// either by using the `.use` helper or explicitly calling its `.destroy` method. -// Failure to do so will leak the underlying Rust object. -TodoList().use { todo2 -> - setDefaultList(todo) - getDefaultList()!!.use { default -> - assert(todo.getEntries() == default.getEntries()) - assert(todo2.getEntries() != default.getEntries()) - } - - todo2.makeDefault() - getDefaultList()!!.use { default -> - assert(todo.getEntries() != default.getEntries()) - assert(todo2.getEntries() == default.getEntries()) - } - - todo.addItem("Test liveness after being demoted from default") - assert(todo.getLast() == "Test liveness after being demoted from default") - - todo2.addItem("Test shared state through local vs default reference") - getDefaultList()!!.use { default -> - assert(default.getLast() == "Test shared state through local vs default reference") - } -} - -// Ensure the kotlin version of deinit doesn't crash, and is idempotent. -todo.destroy() -todo.destroy() - diff --git a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.py b/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.py deleted file mode 100644 index 017e999fb287..000000000000 --- a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.py +++ /dev/null @@ -1,44 +0,0 @@ -from todolist import * - -todo = TodoList() - -entry = TodoEntry("Write bindings for strings in records") - -todo.add_item("Write python bindings") - -assert(todo.get_last() == "Write python bindings") - -todo.add_item("Write tests for bindings") - -assert(todo.get_last() == "Write tests for bindings") - -todo.add_entry(entry) - -assert(todo.get_last() == "Write bindings for strings in records") -assert(todo.get_last_entry().text == "Write bindings for strings in records") - -todo.add_item("Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") -assert(todo.get_last() == "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") - -entry2 = TodoEntry("Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") -todo.add_entry(entry2) -assert(todo.get_last_entry().text == "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") - -todo2 = TodoList() -assert(todo != todo2) -assert(todo is not todo2) - -assert(get_default_list() is None) - -set_default_list(todo) -assert(todo.get_items() == get_default_list().get_items()) - -todo2.make_default() -assert(todo2.get_items() == get_default_list().get_items()) - -todo.add_item("Test liveness after being demoted from default") -assert(todo.get_last() == "Test liveness after being demoted from default") - -todo2.add_item("Test shared state through local vs default reference") -assert(get_default_list().get_last() == "Test shared state through local vs default reference") - diff --git a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.rb b/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.rb deleted file mode 100644 index d9e04f92e7b7..000000000000 --- a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'test/unit' -require 'todolist' - -include Test::Unit::Assertions -include Todolist - -todo = TodoList.new -entry = TodoEntry.new 'Write bindings for strings in records' - -todo.add_item('Write ruby bindings') - -assert_equal todo.get_last, 'Write ruby bindings' - -todo.add_item('Write tests for bindings') - -assert_equal todo.get_last, 'Write tests for bindings' - -todo.add_entry(entry) - -assert_equal todo.get_last, 'Write bindings for strings in records' -assert_equal todo.get_last_entry.text, 'Write bindings for strings in records' - -todo.add_item("Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") -assert_equal todo.get_last, "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣" - -entry2 = TodoEntry.new("Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") -todo.add_entry(entry2) -assert_equal todo.get_last_entry.text, "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣" - -todo2 = TodoList.new -assert todo2.get_items != todo.get_items - -assert Todolist.get_default_list == nil - -Todolist.set_default_list todo -assert todo.get_items == Todolist.get_default_list.get_items - -todo2.make_default -assert todo2.get_items == Todolist.get_default_list.get_items - -todo.add_item "Test liveness after being demoted from default" -assert todo.get_last == "Test liveness after being demoted from default" - -todo2.add_item "Test shared state through local vs default reference" -assert Todolist.get_default_list.get_last == "Test shared state through local vs default reference" \ No newline at end of file diff --git a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.swift b/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.swift deleted file mode 100644 index 6ce72cadb225..000000000000 --- a/third_party/rust/uniffi-example-todolist/tests/bindings/test_todolist.swift +++ /dev/null @@ -1,69 +0,0 @@ -import todolist - - -let todo = TodoList() -do { - let _ = try todo.getLast() - fatalError("Should have thrown an EmptyTodoList error!") -} catch TodoError.EmptyTodoList{ - //It's okay! There are not todos! -} -try! todo.addItem(todo: "Write swift bindings") -assert( try! todo.getLast() == "Write swift bindings") - -try! todo.addItem(todo: "Write tests for bindings") -assert(try! todo.getLast() == "Write tests for bindings") - -let entry = TodoEntry(text: "Write bindings for strings as record members") -try! todo.addEntry(entry: entry) -assert(try! todo.getLast() == "Write bindings for strings as record members") - -try! todo.addItem(todo: "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") -assert(try! todo.getLast() == "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣") - -do { - let _ = try createEntryWith(todo: "") - fatalError("Should have thrown an EmptyString error!") -} catch TodoError.EmptyString { - // It's okay! It was an empty string -} - -let entry2 = TodoEntry(text: "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣") -try! todo.addEntry(entry: entry2) -assert(try! todo.getLastEntry() == entry2) - -assert(todo.getEntries().count == 5) - -todo.addEntries(entries: [TodoEntry(text: "foo"), TodoEntry(text: "bar")]) -assert(todo.getEntries().count == 7) -assert(todo.getItems().count == 7) -assert(try! todo.getLast() == "bar") - -todo.addItems(items: ["bobo", "fofo"]) -assert(todo.getItems().count == 9) -assert(todo.getItems()[7] == "bobo") - -// Ensure deinit doesn't crash. -for _ in 0..<10 { - let list = TodoList() - try! list.addItem(todo: "todo") -} - -let todo2 = TodoList() - -assert(getDefaultList() == nil) - -setDefaultList(list: todo) -assert(todo.getItems() == getDefaultList()!.getItems()) -assert(todo2.getItems() != getDefaultList()!.getItems()) - -todo2.makeDefault() -assert(todo.getItems() != getDefaultList()!.getItems()) -assert(todo2.getItems() == getDefaultList()!.getItems()) - -try! todo.addItem(todo: "Test liveness after being demoted from default") -assert(try! todo.getLast() == "Test liveness after being demoted from default") - -try! todo2.addItem(todo: "Test shared state through local vs default reference") -assert(try! getDefaultList()!.getLast() == "Test shared state through local vs default reference") - diff --git a/third_party/rust/uniffi-example-todolist/tests/test_generated_bindings.rs b/third_party/rust/uniffi-example-todolist/tests/test_generated_bindings.rs deleted file mode 100644 index f92baef50b88..000000000000 --- a/third_party/rust/uniffi-example-todolist/tests/test_generated_bindings.rs +++ /dev/null @@ -1,9 +0,0 @@ -uniffi_macros::build_foreign_language_testcases!( - ["src/todolist.udl",], - [ - "tests/bindings/test_todolist.kts", - "tests/bindings/test_todolist.swift", - "tests/bindings/test_todolist.rb", - "tests/bindings/test_todolist.py" - ] -); diff --git a/toolkit/components/moz.build b/toolkit/components/moz.build index 1c23f8672a80..438a1067169c 100644 --- a/toolkit/components/moz.build +++ b/toolkit/components/moz.build @@ -75,7 +75,6 @@ DIRS += [ "timermanager", "tooltiptext", "typeaheadfind", - "uniffi-js", "utils", "url-classifier", "urlformatter", diff --git a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml b/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml deleted file mode 100644 index ec96b2dcb84d..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "uniffi-bindgen-gecko-js" -version = "0.1.0" -edition = "2018" - -[[bin]] -name = "uniffi-bindgen-gecko-js" -path = "src/main.rs" - -[dependencies] -anyhow = "1" -askama = { version = "0.11", default-features = false, features = ["config"] } -clap = { version = "3.1", features = ["std", "derive"] } -extend = "1.1" -heck = "0.4" -uniffi_bindgen = "0.19" -serde = "1" -toml = "0.5" -camino = "1.0.8" diff --git a/toolkit/components/uniffi-bindgen-gecko-js/askama.toml b/toolkit/components/uniffi-bindgen-gecko-js/askama.toml deleted file mode 100644 index 066e3c468ce1..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/askama.toml +++ /dev/null @@ -1,2 +0,0 @@ -[general] -dirs = ["src/templates"] diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/ci_list.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/ci_list.rs deleted file mode 100644 index 46750979147b..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/ci_list.rs +++ /dev/null @@ -1,139 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -//! Manage the universe of ComponentInterfaces -//! -//! uniffi-bindgen-gecko-js is unique because it generates bindings over a set of UDL files rather -//! than just one. This is because we want to generate the WebIDL statically rather than generate -//! it. To accomplish that, each WebIDL function inputs an opaque integer id that identifies which -//! version of it should run, for example `CallSync` inputs a function id. Operating on all UDL -//! files at once simplifies the task of ensuring those ids are to be unique and consistent between -//! the JS and c++ code. -//! -//! This module manages the list of ComponentInterface and the object ids. - -use crate::render::cpp::ComponentInterfaceCppExt; -use anyhow::{bail, Context, Result}; -use camino::Utf8PathBuf; -use std::collections::{BTreeSet, HashMap, HashSet}; -use uniffi_bindgen::interface::{ComponentInterface, FFIFunction, Object}; - -pub struct ComponentInterfaceUniverse { - ci_list: Vec, - fixture_ci_list: Vec, -} - -impl ComponentInterfaceUniverse { - pub fn new(udl_files: Vec, fixture_udl_files: Vec) -> Result { - let ci_list = udl_files - .into_iter() - .map(parse_udl_file) - .collect::>>()?; - let fixture_ci_list = fixture_udl_files - .into_iter() - .map(parse_udl_file) - .collect::>>()?; - Self::check_udl_namespaces_unique(&ci_list, &fixture_ci_list)?; - Ok(Self { - ci_list, - fixture_ci_list, - }) - } - - fn check_udl_namespaces_unique( - ci_list: &Vec, - fixture_ci_list: &Vec, - ) -> Result<()> { - let mut set = HashSet::new(); - for ci in ci_list.iter().chain(fixture_ci_list.iter()) { - if !set.insert(ci.namespace()) { - bail!("UDL files have duplicate namespace: {}", ci.namespace()); - } - } - Ok(()) - } - - pub fn ci_list(&self) -> &Vec { - &self.ci_list - } - - pub fn fixture_ci_list(&self) -> &Vec { - &self.fixture_ci_list - } - - pub fn iter_all(&self) -> impl Iterator { - self.ci_list.iter().chain(self.fixture_ci_list.iter()) - } -} - -fn parse_udl_file(udl_file: Utf8PathBuf) -> Result { - let udl = std::fs::read_to_string(&udl_file).context("Error reading UDL file")?; - ComponentInterface::from_webidl(&udl).context("Failed to parse UDL") -} - -pub struct FunctionIds<'a> { - // Map (CI namespace, func name) -> Ids - map: HashMap<(&'a str, &'a str), usize>, -} - -impl<'a> FunctionIds<'a> { - pub fn new(cis: &'a ComponentInterfaceUniverse) -> Self { - Self { - map: cis - .iter_all() - .flat_map(|ci| { - ci.exposed_functions() - .into_iter() - .map(move |f| (ci.namespace(), f.name())) - }) - .enumerate() - .map(|(i, (namespace, name))| ((namespace, name), i)) - // Sort using BTreeSet to guarantee the IDs remain stable across runs - .collect::>() - .into_iter() - .collect(), - } - } - - pub fn get(&self, ci: &ComponentInterface, func: &FFIFunction) -> usize { - return *self.map.get(&(ci.namespace(), func.name())).unwrap(); - } - - pub fn name(&self, ci: &ComponentInterface, func: &FFIFunction) -> String { - format!("{}:{}", ci.namespace(), func.name()) - } -} - -pub struct ObjectIds<'a> { - // Map (CI namespace, object name) -> Ids - map: HashMap<(&'a str, &'a str), usize>, -} - -impl<'a> ObjectIds<'a> { - pub fn new(cis: &'a ComponentInterfaceUniverse) -> Self { - Self { - map: cis - .iter_all() - .flat_map(|ci| { - ci.object_definitions() - .iter() - .map(move |o| (ci.namespace(), o.name())) - }) - .enumerate() - .map(|(i, (namespace, name))| ((namespace, name), i)) - // Sort using BTreeSet to guarantee the IDs remain stable across runs - .collect::>() - .into_iter() - .collect(), - } - } - - pub fn get(&self, ci: &ComponentInterface, obj: &Object) -> usize { - return *self.map.get(&(ci.namespace(), obj.name())).unwrap(); - } - - pub fn name(&self, ci: &ComponentInterface, obj: &Object) -> String { - format!("{}:{}", ci.namespace(), obj.name()) - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs deleted file mode 100644 index 1a06e77fee04..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/lib.rs +++ /dev/null @@ -1,123 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use anyhow::{Context, Result}; -use askama::Template; -use camino::Utf8PathBuf; -use clap::Parser; -use heck::ToTitleCase; -use std::fs::File; -use std::io::Write; - -mod ci_list; -mod render; - -pub use ci_list::{ComponentInterfaceUniverse, FunctionIds, ObjectIds}; -pub use render::cpp::CPPScaffoldingTemplate; -pub use render::js::JSBindingsTemplate; -use uniffi_bindgen::ComponentInterface; - -#[derive(Debug, Parser)] -#[clap(name = "uniffi-bindgen-gecko-js")] -#[clap(version = clap::crate_version!())] -#[clap(about = "JS bindings generator for Rust")] -#[clap(propagate_version = true)] -struct CliArgs { - // This is a really convoluted set of arguments, but we're only expecting to be called by - // `mach_commands.py` - #[clap(long, value_name = "FILE")] - js_dir: Utf8PathBuf, - - #[clap(long, value_name = "FILE")] - fixture_js_dir: Utf8PathBuf, - - #[clap(long, value_name = "FILE")] - cpp_path: Utf8PathBuf, - - #[clap(long, value_name = "FILE")] - fixture_cpp_path: Utf8PathBuf, - - #[clap(long, multiple_values = true, value_name = "FILES")] - udl_files: Vec, - - #[clap(long, multiple_values = true, value_name = "FILES")] - fixture_udl_files: Vec, -} - -fn render(out_path: Utf8PathBuf, template: impl Template) -> Result<()> { - println!("rendering {}", out_path); - let contents = template.render()?; - let mut f = - File::create(&out_path).context(format!("Failed to create {:?}", out_path.file_name()))?; - write!(f, "{}\n", contents).context(format!("Failed to write to {}", out_path)) -} - -fn render_cpp( - path: Utf8PathBuf, - prefix: &str, - ci_list: &Vec, - function_ids: &FunctionIds, - object_ids: &ObjectIds, -) -> Result<()> { - render( - path, - CPPScaffoldingTemplate { - prefix, - ci_list, - function_ids: &function_ids, - object_ids: &object_ids, - }, - ) -} - -fn render_js( - out_dir: Utf8PathBuf, - ci_list: &Vec, - function_ids: &FunctionIds, - object_ids: &ObjectIds, -) -> Result<()> { - for ci in ci_list { - let path = out_dir.join(format!("{}.jsm", ci.namespace().to_title_case())); - render( - path, - JSBindingsTemplate { - ci, - function_ids: &function_ids, - object_ids: &object_ids, - }, - )?; - } - Ok(()) -} - -pub fn run_main() -> Result<()> { - let args = CliArgs::parse(); - let cis = ComponentInterfaceUniverse::new(args.udl_files, args.fixture_udl_files)?; - let function_ids = FunctionIds::new(&cis); - let object_ids = ObjectIds::new(&cis); - - render_cpp( - args.cpp_path, - "UniFFI", - cis.ci_list(), - &function_ids, - &object_ids, - )?; - render_cpp( - args.fixture_cpp_path, - "UniFFIFixtures", - cis.fixture_ci_list(), - &function_ids, - &object_ids, - )?; - render_js(args.js_dir, cis.ci_list(), &function_ids, &object_ids)?; - render_js( - args.fixture_js_dir, - cis.fixture_ci_list(), - &function_ids, - &object_ids, - )?; - - Ok(()) -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/main.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/main.rs deleted file mode 100644 index eefe72ba662f..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use anyhow::Result; - -fn main() -> Result<()> { - uniffi_bindgen_gecko_js::run_main() -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs deleted file mode 100644 index b99fcf344f65..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs +++ /dev/null @@ -1,154 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use crate::{FunctionIds, ObjectIds}; -use askama::Template; -use extend::ext; -use heck::ToUpperCamelCase; -use std::collections::HashSet; -use std::iter; -use uniffi_bindgen::interface::{ComponentInterface, FFIArgument, FFIFunction, FFIType, Object}; - -#[derive(Template)] -#[template(path = "UniFFIScaffolding.cpp", escape = "none")] -pub struct CPPScaffoldingTemplate<'a> { - // Prefix for each function name in. This is related to how we handle the test fixtures. For - // each function defined in the UniFFI namespace in UniFFI.webidl we: - // - Generate a function in to handle it using the real UDL files - // - Generate a different function in for handle it using the fixture UDL files - // - Have a hand-written stub function that always calls the first function and only calls - // the second function in if MOZ_UNIFFI_FIXTURES is defined. - pub prefix: &'a str, - pub ci_list: &'a Vec, - pub function_ids: &'a FunctionIds<'a>, - pub object_ids: &'a ObjectIds<'a>, -} - -// Define extension traits with methods used in our template code - -#[ext(name=ComponentInterfaceCppExt)] -pub impl ComponentInterface { - // C++ pointer type name. This needs to be a valid C++ type name and unique across all UDL - // files. - fn pointer_type(&self, object: &Object) -> String { - self._pointer_type(object.name()) - } - - fn _pointer_type(&self, name: &str) -> String { - format!( - "k{}{}PointerType", - self.namespace().to_upper_camel_case(), - name.to_upper_camel_case() - ) - } - - // Iterate over all functions to expose via the UniFFIScaffolding class - // - // This is basically all the user functions, except we don't expose the free methods for - // objects. Freeing is handled by the UniFFIPointer class. - // - // Note: this function should return `impl Iterator<&FFIFunction>`, but that's not currently - // allowed for traits. - fn exposed_functions(&self) -> Vec<&FFIFunction> { - let excluded: HashSet<_> = self - .object_definitions() - .iter() - .map(|o| o.ffi_object_free().name()) - .collect(); - self.iter_user_ffi_function_definitions() - .filter(move |f| !excluded.contains(f.name())) - .collect() - } - - // ScaffoldingConverter class - // - // This is used to convert types between the JS code and Rust - fn scaffolding_converter(&self, ffi_type: &FFIType) -> String { - match ffi_type { - FFIType::RustArcPtr(name) => { - format!("ScaffoldingObjectConverter<&{}>", self._pointer_type(name),) - } - _ => format!("ScaffoldingConverter<{}>", ffi_type.rust_type()), - } - } - - // ScaffoldingCallHandler class - fn scaffolding_call_handler(&self, func: &FFIFunction) -> String { - let return_param = match func.return_type() { - Some(return_type) => self.scaffolding_converter(return_type), - None => "ScaffoldingConverter".to_string(), - }; - let all_params = iter::once(return_param) - .chain( - func.arguments() - .into_iter() - .map(|a| self.scaffolding_converter(&a.type_())), - ) - .collect::>() - .join(", "); - return format!("ScaffoldingCallHandler<{}>", all_params); - } -} - -#[ext(name=FFIFunctionCppExt)] -pub impl FFIFunction { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } - - fn rust_name(&self) -> String { - self.name().to_string() - } - - fn rust_return_type(&self) -> String { - match self.return_type() { - Some(t) => t.rust_type(), - None => "void".to_owned(), - } - } - - fn rust_arg_list(&self) -> String { - let mut parts: Vec = self.arguments().iter().map(|a| a.rust_type()).collect(); - parts.push("RustCallStatus*".to_owned()); - parts.join(", ") - } -} - -#[ext(name=FFITypeCppExt)] -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::ForeignBytes => unimplemented!("ForeignBytes not supported"), - FFIType::ForeignCallback => unimplemented!("ForeignCallback not supported"), - } - .to_owned() - } -} - -#[ext(name=FFIArgumentCppExt)] -pub impl FFIArgument { - fn rust_type(&self) -> String { - self.type_().rust_type() - } -} - -#[ext(name=ObjectCppExt)] -pub impl Object { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs deleted file mode 100644 index 5a42bafbf419..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs +++ /dev/null @@ -1,232 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use super::shared::*; -use crate::{FunctionIds, ObjectIds}; -use askama::Template; -use extend::ext; -use heck::{ToLowerCamelCase, ToShoutySnakeCase, ToUpperCamelCase}; -use uniffi_bindgen::interface::{ - Argument, ComponentInterface, Constructor, Enum, Error, Field, Function, Literal, Method, - Object, Radix, Record, Type, -}; - -fn arg_names(args: &[&Argument]) -> String { - args.iter() - .map(|arg| { - if let Some(default_value) = arg.default_value() { - format!("{} = {}", arg.nm(), default_value.render()) - } else { - arg.nm() - } - }) - .collect::>() - .join(",") -} - -fn render_enum_literal(typ: &Type, variant_name: &str) -> String { - if let Type::Enum(enum_name) = typ { - // TODO: This does not support complex enum literals yet. - return format!( - "{}.{}", - enum_name.to_upper_camel_case(), - variant_name.to_shouty_snake_case() - ); - } else { - panic!("Rendering an enum literal on a type that is not an enum") - } -} -#[derive(Template)] -#[template(path = "js/wrapper.jsm", escape = "none")] -pub struct JSBindingsTemplate<'a> { - pub ci: &'a ComponentInterface, - pub function_ids: &'a FunctionIds<'a>, - pub object_ids: &'a ObjectIds<'a>, -} - -// Define extension traits with methods used in our template code - -#[ext(name=LiteralJSExt)] -pub impl Literal { - fn render(&self) -> String { - match self { - Literal::Boolean(inner) => inner.to_string(), - Literal::String(inner) => format!("\"{}\"", inner), - Literal::UInt(num, radix, _) => format!("{}", radix.render_num(num)), - Literal::Int(num, radix, _) => format!("{}", radix.render_num(num)), - Literal::Float(num, _) => num.clone(), - Literal::Enum(name, typ) => render_enum_literal(typ, name), - Literal::EmptyMap => "{}".to_string(), - Literal::EmptySequence => "[]".to_string(), - Literal::Null => "null".to_string(), - } - } -} - -#[ext(name=RadixJSExt)] -pub impl Radix { - fn render_num( - &self, - num: impl std::fmt::Display + std::fmt::LowerHex + std::fmt::Octal, - ) -> String { - match self { - Radix::Decimal => format!("{}", num), - Radix::Hexadecimal => format!("{:#x}", num), - Radix::Octal => format!("{:#o}", num), - } - } -} - -#[ext(name=RecordJSExt)] -pub impl Record { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } - - fn constructor_field_list(&self) -> String { - self.fields() - .iter() - .map(|field| { - if let Some(default_value) = field.default_value() { - format!("{} = {}", field.nm(), default_value.render()) - } else { - field.nm() - } - }) - .collect::>() - .join(",") - } -} - -#[ext(name=FieldJSExt)] -pub impl Field { - fn nm(&self) -> String { - self.name().to_lower_camel_case() - } - - fn write_datastream_fn(&self) -> String { - self.type_().write_datastream_fn() - } - - fn read_datastream_fn(&self) -> String { - self.type_().read_datastream_fn() - } - - fn ffi_converter(&self) -> String { - self.type_().ffi_converter() - } - - fn check_type(&self) -> String { - format!( - "{}.checkType(\"{}\", {})", - self.type_().ffi_converter(), - self.nm(), - self.nm() - ) - } -} - -#[ext(name=ArgumentJSExt)] -pub impl Argument { - fn lower_fn_name(&self) -> String { - format!("{}.lower", self.type_().ffi_converter()) - } - - fn nm(&self) -> String { - self.name().to_lower_camel_case() - } - - fn check_type(&self) -> String { - format!( - "{}.checkType(\"{}\", {})", - self.type_().ffi_converter(), - self.nm(), - self.nm() - ) - } -} - -#[ext(name=TypeJSExt)] -pub impl Type { - // Render an expression to check if two instances of this type are equal - fn equals(&self, first: &str, second: &str) -> String { - match self { - Type::Record(_) => format!("{}.equals({})", first, second), - _ => format!("{} == {}", first, second), - } - } - - fn write_datastream_fn(&self) -> String { - format!("{}.write", self.ffi_converter()) - } - - fn read_datastream_fn(&self) -> String { - format!("{}.read", self.ffi_converter()) - } - - fn ffi_converter(&self) -> String { - format!( - "FfiConverter{}", - self.canonical_name().to_upper_camel_case() - ) - } -} - -#[ext(name=EnumJSExt)] -pub impl Enum { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } -} - -#[ext(name=FunctionJSExt)] -pub impl Function { - fn arg_names(&self) -> String { - arg_names(self.arguments().as_slice()) - } - - fn nm(&self) -> String { - self.name().to_lower_camel_case() - } -} - -#[ext(name=ErrorJSExt)] -pub impl Error { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } -} - -#[ext(name=ObjectJSExt)] -pub impl Object { - fn nm(&self) -> String { - self.name().to_upper_camel_case() - } -} - -#[ext(name=ConstructorJSExt)] -pub impl Constructor { - fn nm(&self) -> String { - if self.is_primary_constructor() { - "init".to_string() - } else { - self.name().to_lower_camel_case() - } - } - - fn arg_names(&self) -> String { - arg_names(&self.arguments().as_slice()) - } -} - -#[ext(name=MethodJSExt)] -pub impl Method { - fn arg_names(&self) -> String { - arg_names(self.arguments().as_slice()) - } - - fn nm(&self) -> String { - self.name().to_lower_camel_case() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/mod.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/mod.rs deleted file mode 100644 index f9ceeb9872b9..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -pub mod cpp; -pub mod js; -pub mod shared; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/shared.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/shared.rs deleted file mode 100644 index 3f1631762531..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/shared.rs +++ /dev/null @@ -1,39 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/// Extension traits that are shared across multiple render targets -use extend::ext; -use uniffi_bindgen::interface::{Constructor, FFIFunction, Function, Method}; - -#[ext] -pub impl FFIFunction { - fn is_async(&self) -> bool { - // TODO check `uniffi.toml` or some other configuration to figure this out - true - } -} - -#[ext] -pub impl Function { - fn is_async(&self) -> bool { - // TODO check `uniffi.toml` or some other configuration to figure this out - true - } -} - -#[ext] -pub impl Constructor { - fn is_async(&self) -> bool { - // TODO check `uniffi.toml` or some other configuration to figure this out - true - } -} - -#[ext] -pub impl Method { - fn is_async(&self) -> bool { - // TODO check `uniffi.toml` or some other configuration to figure this out - true - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp deleted file mode 100644 index 862564c261bb..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// Generated by uniffi-bindgen-gecko-js. DO NOT EDIT. - -#include "nsString.h" -#include "nsPrintfCString.h" -#include "mozilla/Maybe.h" -#include "mozilla/dom/UniFFIScaffolding.h" -#include "mozilla/dom/ScaffoldingCall.h" - -namespace mozilla::uniffi { - -using dom::ArrayBuffer; -using dom::GlobalObject; -using dom::RootedDictionary; -using dom::Promise; -using dom::ScaffoldingType; -using dom::Sequence; -using dom::UniFFIPointer; -using dom::UniFFIScaffoldingCallResult; - -// Define scaffolding functions from UniFFI -extern "C" { - {%- for ci in ci_list %} - {%- for func in ci.iter_user_ffi_function_definitions() %} - {{ func.rust_return_type() }} {{ func.rust_name() }}({{ func.rust_arg_list() }}); - {%- endfor %} - {%- endfor %} -} - -// Define pointer types -{%- for ci in ci_list %} -{%- for object in ci.object_definitions() %} -{%- 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() }} -}; - -{%- endfor %} -{%- endfor %} - -Maybe> {{ prefix }}CallAsync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, ErrorResult& aError) { - switch (aId) { - {%- for ci in ci_list %} - {%- for func in ci.exposed_functions() %} - case {{ function_ids.get(ci, func) }}: { // {{ function_ids.name(ci, func) }} - using CallHandler = {{ ci.scaffolding_call_handler(func) }}; - return Some(CallHandler::CallAsync({{ func.rust_name() }}, aGlobal, aArgs, "{{ func.name() }}: "_ns, aError)); - } - {%- endfor %} - {%- endfor %} - } - return Nothing(); -} - -bool {{ prefix }}CallSync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, RootedDictionary& aReturnValue, ErrorResult& aError) { - switch (aId) { - {%- for ci in ci_list %} - {%- for func in ci.exposed_functions() %} - case {{ function_ids.get(ci, func) }}: { // {{ function_ids.name(ci, func) }} - using CallHandler = {{ ci.scaffolding_call_handler(func) }}; - CallHandler::CallSync({{ func.rust_name() }}, aGlobal, aArgs, aReturnValue, "{{ func.name() }}: "_ns, aError); - return true; - } - {%- endfor %} - {%- endfor %} - } - return false; -} - -Maybe> {{ prefix }}ReadPointer(const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - {%- for ci in ci_list %} - {%- for object in ci.object_definitions() %} - case {{ object_ids.get(ci, object) }}: { // {{ object_ids.name(ci, object) }} - type = &{{ ci.pointer_type(object) }}; - break; - } - {%- endfor %} - {%- endfor %} - default: - return Nothing(); - } - return Some(UniFFIPointer::Read(aArrayBuff, aPosition, type, aError)); -} - -bool {{ prefix }}WritePointer(const GlobalObject& aGlobal, uint64_t aId, const UniFFIPointer& aPtr, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - {%- for ci in ci_list %} - {%- for object in ci.object_definitions() %} - case {{ object_ids.get(ci, object) }}: { // {{ object_ids.name(ci, object) }} - type = &{{ ci.pointer_type(object) }}; - break; - } - {%- endfor %} - {%- endfor %} - default: - return false; - } - aPtr.Write(aArrayBuff, aPosition, type, aError); - return true; -} - -} // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Boolean.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Boolean.jsm deleted file mode 100644 index 0ba24e8c9076..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Boolean.jsm +++ /dev/null @@ -1,21 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static computeSize() { - return 1; - } - static lift(value) { - return value == 1; - } - static lower(value) { - if (value) { - return 1; - } else { - return 0; - } - } - static write(dataStream, value) { - dataStream.writeUint8(this.lower(value)) - } - static read(dataStream) { - return this.lift(dataStream.readUint8()) - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.jsm deleted file mode 100644 index 69de63555b1d..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.jsm +++ /dev/null @@ -1,103 +0,0 @@ -{%- let enum_ = ci.get_enum_definition(name).unwrap() %} - -{%- if enum_.is_flat() %} - -const {{ enum_.nm() }} = { - {%- for variant in enum_.variants() %} - {{ variant.name().to_shouty_snake_case() }}: {{loop.index}}, - {%- endfor %} -}; - -Object.freeze({{ enum_.nm() }}); -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static read(dataStream) { - switch (dataStream.readInt32()) { - {%- for variant in enum_.variants() %} - case {{ loop.index }}: - return {{ enum_.nm() }}.{{ variant.name().to_shouty_snake_case() }} - {%- endfor %} - default: - return new Error("Unknown {{ enum_.nm() }} variant"); - } - } - - static write(dataStream, value) { - {%- for variant in enum_.variants() %} - if (value === {{ enum_.nm() }}.{{ variant.name().to_shouty_snake_case() }}) { - dataStream.writeInt32({{ loop.index }}); - return; - } - {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); - } - - static computeSize(value) { - return 4; - } -} - -{%- else %} - -class {{ enum_.nm() }} {} -{%- for variant in enum_.variants() %} -{{enum_.nm()}}.{{variant.name().to_upper_camel_case() }} = class extends {{ enum_.nm() }}{ - constructor( - {% for field in variant.fields() -%} - {{ field.nm() }}{%- if loop.last %}{%- else %}, {%- endif %} - {% endfor -%} - ) { - super(); - {%- for field in variant.fields() %} - this.{{field.nm()}} = {{ field.nm() }}; - {%- endfor %} - } -} -{%- endfor %} - -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static read(dataStream) { - switch (dataStream.readInt32()) { - {%- for variant in enum_.variants() %} - case {{ loop.index }}: - return new {{ enum_.nm() }}.{{ variant.name().to_upper_camel_case() }}( - {%- for field in variant.fields() %} - {{ field.ffi_converter() }}.read(dataStream){%- if loop.last %}{% else %}, {%- endif %} - {%- endfor %} - ); - {%- endfor %} - default: - return new Error("Unknown {{ enum_.nm() }} variant"); - } - } - - static write(dataStream, value) { - {%- for variant in enum_.variants() %} - if (value instanceof {{enum_.nm()}}.{{ variant.name().to_upper_camel_case() }}) { - dataStream.writeInt32({{ loop.index }}); - {%- for field in variant.fields() %} - {{ field.ffi_converter() }}.write(dataStream, value.{{ field.nm() }}); - {%- endfor %} - return; - } - {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); - } - - static computeSize(value) { - // Size of the Int indicating the variant - let totalSize = 4; - {%- for variant in enum_.variants() %} - if (value instanceof {{enum_.nm()}}.{{ variant.name().to_upper_camel_case() }}) { - {%- for field in variant.fields() %} - totalSize += {{ field.ffi_converter() }}.computeSize(value.{{ field.nm() }}); - {%- endfor %} - return totalSize; - } - {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); - } -} - -{%- endif %} - -EXPORTED_SYMBOLS.push("{{ enum_.nm() }}"); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.jsm deleted file mode 100644 index ee20a885112e..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.jsm +++ /dev/null @@ -1,51 +0,0 @@ -{%- let error = ci.get_error_definition(name).unwrap() %} -{%- let string_type = Type::String %} -{%- let string_ffi_converter = string_type.ffi_converter() %} - -class {{ error.nm() }} extends Error {} -EXPORTED_SYMBOLS.push("{{ error.nm() }}"); - -{% for variant in error.variants() %} -class {{ variant.name().to_upper_camel_case() }} extends {{ error.nm() }} { - {% if error.is_flat() %} - constructor(message, ...params) { - super(...params); - this.message = message; - } - {%- else %} - constructor( - {% for field in variant.fields() -%} - {{field.nm()}}, - {% endfor -%} - ...params - ) { - super(...params); - {%- for field in variant.fields() %} - this.{{field.nm()}} = {{ field.nm() }}; - {%- endfor %} - } - {%- endif %} -} -EXPORTED_SYMBOLS.push("{{ variant.name().to_upper_camel_case() }}"); -{%-endfor %} - -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static read(dataStream) { - switch (dataStream.readInt32()) { - {%- for variant in error.variants() %} - case {{ loop.index }}: - {%- if error.is_flat() %} - return new {{ variant.name().to_upper_camel_case() }}({{ string_ffi_converter }}.read(dataStream)); - {%- else %} - return new {{ variant.name().to_upper_camel_case() }}( - {%- for field in variant.fields() %} - {{ field.ffi_converter() }}.read(dataStream){%- if loop.last %}{% else %}, {%- endif %} - {%- endfor %} - ); - {%- endif %} - {%- endfor %} - default: - return new Error("Unknown {{ error.nm() }} variant"); - } - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float32.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float32.jsm deleted file mode 100644 index be1ce942e74b..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float32.jsm +++ /dev/null @@ -1,17 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static computeSize() { - return 4; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeFloat32(value) - } - static read(dataStream) { - return dataStream.readFloat32() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float64.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float64.jsm deleted file mode 100644 index 039634624a4c..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Float64.jsm +++ /dev/null @@ -1,17 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static computeSize() { - return 8; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeFloat64(value) - } - static read(dataStream) { - return dataStream.readFloat64() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Helpers.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Helpers.jsm deleted file mode 100644 index 70a15ef65f1a..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Helpers.jsm +++ /dev/null @@ -1,229 +0,0 @@ -// Write/Read data to/from an ArrayBuffer -class ArrayBufferDataStream { - constructor(arrayBuffer) { - this.dataView = new DataView(arrayBuffer); - this.pos = 0; - } - - readUint8() { - let rv = this.dataView.getUint8(this.pos); - this.pos += 1; - return rv; - } - - writeUint8(value) { - this.dataView.setUint8(this.pos, value); - this.pos += 1; - } - - readUint16() { - let rv = this.dataView.getUint16(this.pos); - this.pos += 2; - return rv; - } - - writeUint16(value) { - this.dataView.setUint16(this.pos, value); - this.pos += 2; - } - - readUint32() { - let rv = this.dataView.getUint32(this.pos); - this.pos += 4; - return rv; - } - - writeUint32(value) { - this.dataView.setUint32(this.pos, value); - this.pos += 4; - } - - readUint64() { - let rv = this.dataView.getBigUint64(this.pos); - this.pos += 8; - return Number(rv); - } - - writeUint64(value) { - this.dataView.setBigUint64(this.pos, BigInt(value)); - this.pos += 8; - } - - - readInt8() { - let rv = this.dataView.getInt8(this.pos); - this.pos += 1; - return rv; - } - - writeInt8(value) { - this.dataView.setInt8(this.pos, value); - this.pos += 1; - } - - readInt16() { - let rv = this.dataView.getInt16(this.pos); - this.pos += 2; - return rv; - } - - writeInt16(value) { - this.dataView.setInt16(this.pos, value); - this.pos += 2; - } - - readInt32() { - let rv = this.dataView.getInt32(this.pos); - this.pos += 4; - return rv; - } - - writeInt32(value) { - this.dataView.setInt32(this.pos, value); - this.pos += 4; - } - - readInt64() { - let rv = this.dataView.getBigInt64(this.pos); - this.pos += 8; - return Number(rv); - } - - writeInt64(value) { - this.dataView.setBigInt64(this.pos, BigInt(value)); - this.pos += 8; - } - - - readFloat32() { - let rv = this.dataView.getFloat32(this.pos); - this.pos += 4; - return rv; - } - - writeFloat32(value) { - this.dataView.setFloat32(this.pos, value); - this.pos += 4; - } - - readFloat64() { - let rv = this.dataView.getFloat64(this.pos); - this.pos += 8; - return rv; - } - - writeFloat64(value) { - this.dataView.setFloat64(this.pos, value); - this.pos += 8; - } - - - writeString(value) { - const encoder = new TextEncoder(); - // Note: in order to efficiently write this data, we first write the - // string data, reserving 4 bytes for the size. - const dest = new Uint8Array(this.dataView.buffer, this.pos + 4); - const encodeResult = encoder.encodeInto(value, dest); - if (encodeResult.read != value.length) { - throw new UniFFIError( - "writeString: out of space when writing to ArrayBuffer. Did the computeSize() method returned the wrong result?" - ); - } - const size = encodeResult.written; - // Next, go back and write the size before the string data - this.dataView.setUint32(this.pos, size); - // Finally, advance our position past both the size and string data - this.pos += size + 4; - } - - readString() { - const decoder = new TextDecoder(); - const size = this.readUint32(); - const source = new Uint8Array(this.dataView.buffer, this.pos, size) - const value = decoder.decode(source); - this.pos += size; - return value; - } - - {%- for object in ci.object_definitions() %} - - // Reads a {{ object.nm() }} pointer from the data stream - // UniFFI Pointers are **always** 8 bytes long. That is enforced - // by the C++ and Rust Scaffolding code. - readPointer{{ object.nm() }}() { - const pointerId = {{ object_ids.get(ci, object) }}; // {{ object_ids.name(ci, object) }} - const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); - this.pos += 8; - return res; - } - - // Writes a {{ object.nm() }} pointer into the data stream - // UniFFI Pointers are **always** 8 bytes long. That is enforced - // by the C++ and Rust Scaffolding code. - writePointer{{ object.nm() }}(value) { - const pointerId = {{ object_ids.get(ci, object) }}; // {{ object_ids.name(ci, object) }} - UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); - this.pos += 8; - } - {% endfor %} -} - -function handleRustResult(result, liftCallback, liftErrCallback) { - switch (result.code) { - case "success": - return liftCallback(result.data); - - case "error": - throw liftErrCallback(result.data); - - case "internal-error": - let message = result.internalErrorMessage; - if (message) { - throw new UniFFIInternalError(message); - } else { - throw new UniFFIInternalError("Unknown error"); - } - - default: - throw new UniFFIError(`Unexpected status code: ${result.code}`); - } -} - -class UniFFIError { - constructor(message) { - this.message = message; - } -} - -class UniFFIInternalError extends UniFFIError {} - -// Base class for FFI converters -class FfiConverter { - static checkType(name, value) { - if (value === undefined ) { - throw TypeError(`${name} is undefined`); - } - if (value === null ) { - throw TypeError(`${name} is null`); - } - } -} - -// Base class for FFI converters that lift/lower by reading/writing to an ArrayBuffer -class FfiConverterArrayBuffer extends FfiConverter { - static lift(buf) { - return this.read(new ArrayBufferDataStream(buf)); - } - - static lower(value) { - const buf = new ArrayBuffer(this.computeSize(value)); - const dataStream = new ArrayBufferDataStream(buf); - this.write(dataStream, value); - return buf; - } -} - -// Symbols that are used to ensure that Object constructors -// can only be used with a proper UniFFI pointer -const uniffiObjectPtr = Symbol("uniffiObjectPtr"); -const constructUniffiObject = Symbol("constructUniffiObject"); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int16.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int16.jsm deleted file mode 100644 index d7195e2ec695..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int16.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < -32768 || value > 32767) { - throw TypeError(`${name} exceeds the I16 bounds (${value})`); - } - } - static computeSize() { - return 2; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeInt16(value) - } - static read(dataStream) { - return dataStream.readInt16() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int32.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int32.jsm deleted file mode 100644 index 81c64343ebc6..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int32.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < -2147483648 || value > 2147483647) { - throw TypeError(`${name} exceeds the I32 bounds (${value})`); - } - } - static computeSize() { - return 4; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeInt32(value) - } - static read(dataStream) { - return dataStream.readInt32() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int64.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int64.jsm deleted file mode 100644 index 7e62a4b40187..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int64.jsm +++ /dev/null @@ -1,23 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isSafeInteger(value)) { - throw TypeError(`${name} exceeds the safe integer bounds (${value})`); - } - } - static computeSize() { - return 8; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeInt64(value) - } - static read(dataStream) { - return dataStream.readInt64() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int8.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int8.jsm deleted file mode 100644 index 31e9b4c81159..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Int8.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < -128 || value > 127) { - throw TypeError(`${name} exceeds the I8 bounds (${value})`); - } - } - static computeSize() { - return 1; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeInt8(value) - } - static read(dataStream) { - return dataStream.readInt8() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Map.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Map.jsm deleted file mode 100644 index 9efa3dc556eb..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Map.jsm +++ /dev/null @@ -1,32 +0,0 @@ -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static read(dataStream) { - const len = dataStream.readInt32(); - const map = {}; - for (let i = 0; i < len; i++) { - const key = {{ key_type.ffi_converter() }}.read(dataStream); - const value = {{ value_type.ffi_converter() }}.read(dataStream); - map[key] = value; - } - - return map; - } - - static write(dataStream, value) { - dataStream.writeInt32(Object.keys(value).length); - for (const key in value) { - {{ key_type.ffi_converter() }}.write(dataStream, key); - {{ value_type.ffi_converter() }}.write(dataStream, value[key]); - } - } - - static computeSize(value) { - // The size of the length - let size = 4; - for (const key in value) { - size += {{ key_type.ffi_converter() }}.computeSize(key); - size += {{ value_type.ffi_converter() }}.computeSize(value[key]); - } - return size; - } -} - diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.jsm deleted file mode 100644 index 41fcd96b4009..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.jsm +++ /dev/null @@ -1,69 +0,0 @@ -{%- let object = ci.get_object_definition(name).unwrap() %} - -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 cons.is_async() %} - /** - * 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_) -%} - } - {%- endfor %} - - {%- for meth in object.methods() %} - {{ meth.nm() }}({{ meth.arg_names() }}) { - {%- call js::call_method(meth, type_, object) -%} - } - {%- endfor %} - -} - -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; - } -} - -EXPORTED_SYMBOLS.push("{{ object.nm() }}"); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Optional.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Optional.jsm deleted file mode 100644 index ad5be63b244b..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Optional.jsm +++ /dev/null @@ -1,36 +0,0 @@ -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static checkType(name, value) { - if (value !== undefined && value !== null) { - {{ inner.ffi_converter() }}.checkType(name, value) - } - } - - static read(dataStream) { - const code = dataStream.readUint8(0); - switch (code) { - case 0: - return null - case 1: - return {{ inner.ffi_converter() }}.read(dataStream) - default: - throw UniFFIError(`Unexpected code: ${code}`); - } - } - - static write(dataStream, value) { - if (value === null || value === undefined) { - dataStream.writeUint8(0); - return; - } - dataStream.writeUint8(1); - {{ inner.ffi_converter() }}.write(dataStream, value) - } - - static computeSize(value) { - if (value === null || value === undefined) { - return 1; - } - return 1 + {{ inner.ffi_converter() }}.computeSize(value) - } -} - diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.jsm deleted file mode 100644 index 3f9a8788a48c..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.jsm +++ /dev/null @@ -1,55 +0,0 @@ -{% let record = ci.get_record_definition(name).unwrap() %} - -class {{ record.nm() }} { - constructor({{ record.constructor_field_list() }}) { - {%- for field in record.fields() %} - {{ field.check_type() }}; - {%- endfor %} - - {%- for field in record.fields() %} - this.{{field.nm()}} = {{ field.nm() }}; - {%- endfor %} - } - equals(other) { - return ( - {%- for field in record.fields() %} - {{ field.type_().equals("this.{}"|format(field.nm()), "other.{}"|format(field.nm())) }}{% if !loop.last %} &&{% endif %} - {%- endfor %} - ) - } -} - -class {{ ffi_converter }} extends FfiConverter { - static lift(buf) { - return this.read(new ArrayBufferDataStream(buf)); - } - static lower(value) { - const buf = new ArrayBuffer(this.computeSize(value)); - const dataStream = new ArrayBufferDataStream(buf); - this.write(dataStream, value); - return buf; - } - static read(dataStream) { - return new {{record.nm()}}( - {%- for field in record.fields() %} - {{ field.read_datastream_fn() }}(dataStream) - {%- if !loop.last %}, {% endif %} - {%- endfor %} - ); - } - static write(dataStream, value) { - {%- for field in record.fields() %} - {{ field.write_datastream_fn() }}(dataStream, value.{{field.nm()}}); - {%- endfor %} - } - - static computeSize(value) { - let totalSize = 0; - {%- for field in record.fields() %} - totalSize += {{ field.ffi_converter() }}.computeSize(value.{{ field.nm() }}); - {%- endfor %} - return totalSize - } -} - -EXPORTED_SYMBOLS.push("{{ record.nm() }}"); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Sequence.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Sequence.jsm deleted file mode 100644 index ef5d5e59d1a3..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Sequence.jsm +++ /dev/null @@ -1,27 +0,0 @@ -class {{ ffi_converter }} extends FfiConverterArrayBuffer { - static read(dataStream) { - const len = dataStream.readInt32(); - const arr = []; - for (let i = 0; i < len; i++) { - arr.push({{ inner.ffi_converter() }}.read(dataStream)); - } - return arr; - } - - static write(dataStream, value) { - dataStream.writeInt32(value.length); - value.forEach((innerValue) => { - {{ inner.ffi_converter() }}.write(dataStream, innerValue); - }) - } - - static computeSize(value) { - // The size of the length - let size = 4; - for (const innerValue of value) { - size += {{ inner.ffi_converter() }}.computeSize(innerValue); - } - return size; - } -} - 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 deleted file mode 100644 index fbbde546471f..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/String.jsm +++ /dev/null @@ -1,27 +0,0 @@ - - -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 - } -} - diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/TopLevelFunctions.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/TopLevelFunctions.jsm deleted file mode 100644 index 9f869240bc32..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/TopLevelFunctions.jsm +++ /dev/null @@ -1,8 +0,0 @@ -{%- for func in ci.function_definitions() %} -function {{ func.nm() }}({{ func.arg_names() }}) { - {% call js::call_scaffolding_function(func) %} -} - -EXPORTED_SYMBOLS.push("{{ func.nm() }}"); - -{%- endfor %} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.jsm deleted file mode 100644 index 7c4bb8439fc3..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Types.jsm +++ /dev/null @@ -1,66 +0,0 @@ -{%- for type_ in ci.iter_types() %} -{%- let ffi_converter = type_.ffi_converter() %} -{%- match type_ %} - -{%- when Type::Boolean %} -{%- include "Boolean.jsm" %} - -{%- when Type::UInt8 %} -{%- include "UInt8.jsm" %} - -{%- when Type::UInt16 %} -{%- include "UInt16.jsm" %} - -{%- when Type::UInt32 %} -{%- include "UInt32.jsm" %} - -{%- when Type::UInt64 %} -{%- include "UInt64.jsm" %} - -{%- when Type::Int8 %} -{%- include "Int8.jsm" %} - -{%- when Type::Int16 %} -{%- include "Int16.jsm" %} - -{%- when Type::Int32 %} -{%- include "Int32.jsm" %} - -{%- when Type::Int64 %} -{%- include "Int64.jsm" %} - -{%- when Type::Float32 %} -{%- include "Float32.jsm" %} - -{%- when Type::Float64 %} -{%- include "Float64.jsm" %} - -{%- when Type::Record with (name) %} -{%- include "Record.jsm" %} - -{%- when Type::Optional with (inner) %} -{%- include "Optional.jsm" %} - -{%- when Type::String %} -{%- include "String.jsm" %} - -{%- when Type::Sequence with (inner) %} -{%- include "Sequence.jsm" %} - -{%- when Type::Map with (key_type, value_type) %} -{%- include "Map.jsm" %} - -{%- when Type::Error with (name) %} -{% include "Error.jsm" %} - -{% when Type::Enum with (name) %} -{% include "Enum.jsm" %} - -{% when Type::Object with (name) %} -{% include "Object.jsm" %} - -{%- else %} -{# TODO implement the other types #} - -{%- endmatch %} -{%- endfor %} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt16.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt16.jsm deleted file mode 100644 index b118a75d6cc6..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt16.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < 0 || value > 65535) { - throw TypeError(`${name} exceeds the U16 bounds (${value})`); - } - } - static computeSize() { - return 2; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeUint16(value) - } - static read(dataStream) { - return dataStream.readUint16() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt32.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt32.jsm deleted file mode 100644 index cf7d7c6edb80..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt32.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < 0 || value > 4294967295) { - throw TypeError(`${name} exceeds the U32 bounds (${value})`); - } - } - static computeSize() { - return 4; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeUint32(value) - } - static read(dataStream) { - return dataStream.readUint32() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt64.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt64.jsm deleted file mode 100644 index 1284d7738aa7..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt64.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isSafeInteger(value)) { - throw TypeError(`${name} exceeds the safe integer bounds (${value})`); - } - if (value < 0) { - throw TypeError(`${name} exceeds the U64 bounds (${value})`); - } - } - static computeSize() { - return 8; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeUint64(value) - } - static read(dataStream) { - return dataStream.readUint64() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt8.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt8.jsm deleted file mode 100644 index 17f0c5c54b82..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/UInt8.jsm +++ /dev/null @@ -1,26 +0,0 @@ -class {{ ffi_converter }} extends FfiConverter { - static checkType(name, value) { - super.checkType(name, value); - if (!Number.isInteger(value)) { - throw TypeError(`${name} is not an integer(${value})`); - } - if (value < 0 || value > 256) { - throw TypeError(`${name} exceeds the U8 bounds (${value})`); - } - } - static computeSize() { - return 1; - } - static lift(value) { - return value; - } - static lower(value) { - return value; - } - static write(dataStream, value) { - dataStream.writeUint8(value) - } - static read(dataStream) { - return dataStream.readUint8() - } -} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/macros.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/macros.jsm deleted file mode 100644 index d5be655da169..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/macros.jsm +++ /dev/null @@ -1,55 +0,0 @@ -{%- macro call_scaffolding_function(func) %} -{%- call _call_scaffolding_function(func, func.return_type(), "") -%} -{%- endmacro %} - -{%- macro call_constructor(cons, object_type) %} -{%- call _call_scaffolding_function(cons, Some(object_type), "") -%} -{%- endmacro %} - -{%- macro call_method(method, object_type) %} -{%- call _call_scaffolding_function(method, method.return_type(), object_type.ffi_converter()) -%} -{%- endmacro %} - -{%- macro _call_scaffolding_function(func, return_type, receiver_ffi_converter) %} - {%- match return_type %} - {%- when Some with (return_type) %} - const liftResult = (result) => {{ return_type.ffi_converter() }}.lift(result); - {%- else %} - const liftResult = (result) => undefined; - {%- endmatch %} - {%- match func.throws_type() %} - {%- when Some with (err_type) %} - const liftError = (data) => {{ err_type.ffi_converter() }}.lift(data); - {%- else %} - const liftError = null; - {%- endmatch %} - const functionCall = () => { - {%- for arg in func.arguments() %} - {{ arg.check_type() }}; - {%- endfor %} - - {%- if func.is_async() %} - return UniFFIScaffolding.callAsync( - {%- else %} - return UniFFIScaffolding.callSync( - {%- endif %} - {{ function_ids.get(ci, func.ffi_func()) }}, // {{ function_ids.name(ci, func.ffi_func()) }} - {%- if receiver_ffi_converter != "" %} - {{ receiver_ffi_converter }}.lower(this), - {%- endif %} - {%- for arg in func.arguments() %} - {{ arg.lower_fn_name() }}({{ arg.nm() }}), - {%- endfor %} - ) - } - - {%- if func.is_async() %} - try { - return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); - } catch (error) { - return Promise.reject(error) - } - {%- else %} - return handleRustResult(functionCall(), liftResult, liftError); - {%- endif %} -{%- endmacro %} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/wrapper.jsm b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/wrapper.jsm deleted file mode 100644 index 8f257b98826f..000000000000 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/wrapper.jsm +++ /dev/null @@ -1,14 +0,0 @@ -// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate. -// Trust me, you don't want to mess with it! - -{% import "macros.jsm" as js %} - -"use strict"; - -var EXPORTED_SYMBOLS = []; - -{% include "Helpers.jsm" %} - -{% include "Types.jsm" %} - -{% include "TopLevelFunctions.jsm" %} diff --git a/toolkit/components/uniffi-js/OwnedRustBuffer.cpp b/toolkit/components/uniffi-js/OwnedRustBuffer.cpp deleted file mode 100644 index 96d9dc1fd7b4..000000000000 --- a/toolkit/components/uniffi-js/OwnedRustBuffer.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsString.h" -#include "mozilla/dom/OwnedRustBuffer.h" - -namespace mozilla::uniffi { - -using dom::ArrayBuffer; - -OwnedRustBuffer::OwnedRustBuffer(const RustBuffer& aBuf) { - mBuf = aBuf; - MOZ_ASSERT(IsValid()); -} - -Result OwnedRustBuffer::FromArrayBuffer( - const ArrayBuffer& aArrayBuffer) { - if (aArrayBuffer.Length() > INT32_MAX) { - return Err("Input ArrayBuffer is too large"_ns); - } - - RustCallStatus status{}; - RustBuffer buf = uniffi_rustbuffer_alloc( - static_cast(aArrayBuffer.Length()), &status); - buf.len = aArrayBuffer.Length(); - if (status.code != 0) { - if (status.error_buf.data) { - auto message = nsCString("uniffi_rustbuffer_alloc: "); - message.Append( - nsDependentCSubstring(reinterpret_cast(status.error_buf.data), - status.error_buf.len)); - RustCallStatus status2{}; - uniffi_rustbuffer_free(status.error_buf, &status2); - MOZ_RELEASE_ASSERT(status2.code == 0, - "Freeing a rustbuffer should never fail"); - return Err(message); - - } else { - return Err("Unknown error allocating rust buffer"_ns); - } - } - - memcpy(buf.data, aArrayBuffer.Data(), buf.len); - return OwnedRustBuffer(buf); -} - -OwnedRustBuffer::OwnedRustBuffer(OwnedRustBuffer&& aOther) : mBuf(aOther.mBuf) { - aOther.mBuf = RustBuffer{0}; -} - -OwnedRustBuffer& OwnedRustBuffer::operator=(OwnedRustBuffer&& aOther) { - if (&aOther != this) { - FreeData(); - } - mBuf = aOther.mBuf; - aOther.mBuf = RustBuffer{0}; - return *this; -} - -void OwnedRustBuffer::FreeData() { - if (IsValid()) { - RustCallStatus status{}; - uniffi_rustbuffer_free(mBuf, &status); - MOZ_RELEASE_ASSERT(status.code == 0, - "Freeing a rustbuffer should never fail"); - mBuf = {0}; - } -} - -OwnedRustBuffer::~OwnedRustBuffer() { FreeData(); } - -RustBuffer OwnedRustBuffer::IntoRustBuffer() { - RustBuffer rv = mBuf; - mBuf = {}; - return rv; -} - -JSObject* OwnedRustBuffer::IntoArrayBuffer(JSContext* cx) { - int32_t len = mBuf.len; - void* data = mBuf.data; - auto userData = MakeUnique(std::move(*this)); - return JS::NewExternalArrayBuffer(cx, len, data, &ArrayBufferFreeFunc, - userData.release()); -} - -void OwnedRustBuffer::ArrayBufferFreeFunc(void* contents, void* userData) { - UniquePtr buf{reinterpret_cast(userData)}; -} -} // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-js/OwnedRustBuffer.h b/toolkit/components/uniffi-js/OwnedRustBuffer.h deleted file mode 100644 index d43a23330671..000000000000 --- a/toolkit/components/uniffi-js/OwnedRustBuffer.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_OwnedRustBuffer_h -#define mozilla_OwnedRustBuffer_h - -#include "mozilla/ErrorResult.h" -#include "mozilla/ResultVariant.h" -#include "mozilla/dom/TypedArray.h" -#include "mozilla/dom/UniFFIRust.h" - -namespace mozilla::uniffi { - -// RustBuffer that's owned by the JS code and handles the memory management -class OwnedRustBuffer final { - private: - RustBuffer mBuf; - - void FreeData(); - - public: - // The default constructor creates an invalid OwnedRustBuffer - OwnedRustBuffer() : mBuf{0} {}; - - // Constructor for creating an OwnedRustBuffer from a raw RustBuffer struct - // that was returned by Rust (therefore we now own the RustBuffer). - explicit OwnedRustBuffer(const RustBuffer& aBuf); - - // Manual implementation of move constructor and assignment operator. - OwnedRustBuffer(OwnedRustBuffer&& aOther); - OwnedRustBuffer& operator=(OwnedRustBuffer&& aOther); - - // Delete copy & move constructor as this type is non-copyable. - OwnedRustBuffer(const OwnedRustBuffer&) = delete; - OwnedRustBuffer& operator=(const OwnedRustBuffer&) = delete; - - // Destructor that frees the RustBuffer if it is still valid - ~OwnedRustBuffer(); - - // Constructor for creating an OwnedRustBuffer from an ArrayBuffer. Will set - // aError to failed and construct an invalid OwnedRustBuffer if the - // conversion failed. - static Result FromArrayBuffer( - const mozilla::dom::ArrayBuffer& aArrayBuffer); - - // Moves the buffer out of this `OwnedArrayBuffer` into a raw `RustBuffer` - // struct. The raw struct must be passed into a Rust function, transfering - // ownership to Rust. After this call the buffer will no longer be valid. - RustBuffer IntoRustBuffer(); - - // Moves the buffer out of this `OwnedArrayBuffer` into a JS ArrayBuffer. - // This transfers ownership into the JS engine. After this call the buffer - // will no longer be valid. - JSObject* IntoArrayBuffer(JSContext* cx); - - // Is this RustBuffer pointing to valid data? - bool IsValid() const { return mBuf.data != nullptr; } - - private: - // Helper function used by IntoArrayBuffer. - static void ArrayBufferFreeFunc(void* contents, void* userData); -}; - -} // namespace mozilla::uniffi - -#endif // mozilla_OwnedRustBuffer_h diff --git a/toolkit/components/uniffi-js/README.md b/toolkit/components/uniffi-js/README.md deleted file mode 100644 index addd0b4bcc52..000000000000 --- a/toolkit/components/uniffi-js/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# uniffi-js - -This directory contains C++ helper code for the UniFFI Rust library -(https://github.com/mozilla/uniffi-rs/). - - - `UniFFIPointer.*` and `UniFFIPointerType.*` implement the `UniFFIPointer` WebIDL class - - - `UniFFI*Scaffolding.cpp` implements the `UniFFIScaffolding` WebIDL class. - - UniFFIGeneratedScaffolding.cpp contains the generated code for all - non-testing UDL files. - - UniFFIFixtureScaffolding.cpp contains generated code for test fixture UDL - files. It's only compiled if `--enable-uniffi-fixtures` is set. - - UniFFIScaffolding.cpp is a facade that wraps UniFFIFixtureScaffolding, and - UniFFIGeneratedScaffolding if enabled, to implement the interface. - -- `ScaffoldingConverter.h`, `ScaffoldingCall.h` contain generic code to make - the scaffolding calls. In general, we try to keep the logic of the calls in - these files and limit the generated code to routing call IDs to template - classes defined here. - -- `OwnedRustBuffer.*` implements a C++ class to help manager ownership of a RustBuffer. - -- `UniFFIRust.h` contains definitions for the C functions that UniFFI exports. diff --git a/toolkit/components/uniffi-js/ScaffoldingCall.h b/toolkit/components/uniffi-js/ScaffoldingCall.h deleted file mode 100644 index bd6efd8aad63..000000000000 --- a/toolkit/components/uniffi-js/ScaffoldingCall.h +++ /dev/null @@ -1,260 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_ScaffoldingCall_h -#define mozilla_ScaffoldingCall_h - -#include -#include -#include "nsIGlobalObject.h" -#include "nsPrintfCString.h" -#include "mozilla/MozPromise.h" -#include "mozilla/ResultVariant.h" -#include "mozilla/dom/OwnedRustBuffer.h" -#include "mozilla/dom/Promise.h" -#include "mozilla/dom/ScaffoldingConverter.h" -#include "mozilla/dom/UniFFIBinding.h" -#include "mozilla/dom/UniFFIRust.h" - -namespace mozilla::uniffi { - -// Low-level result of calling a scaffolding function -// -// This stores what Rust returned in order to convert it into -// UniFFIScaffoldingCallResult -template -struct RustCallResult { - ReturnType mReturnValue; - RustCallStatus mCallStatus = {}; -}; - -template <> -struct RustCallResult { - RustCallStatus mCallStatus = {}; -}; - -// Does the work required to call a scaffolding function -// -// This class is generic over the type signature of the scaffolding function. -// This seems better than being generic over the functions themselves, since it -// saves space whenever 2 functions share a signature. -template -class ScaffoldingCallHandler { - public: - // Pointer to a scaffolding function that can be called by this - // ScaffoldingConverter - using ScaffoldingFunc = typename ReturnConverter::RustType (*)( - typename ArgConverters::RustType..., RustCallStatus*); - - // Perform an async scaffolding call - static already_AddRefed CallAsync( - ScaffoldingFunc aScaffoldingFunc, const dom::GlobalObject& aGlobal, - const dom::Sequence& aArgs, - const nsLiteralCString& aFuncName, ErrorResult& aError) { - auto convertResult = ConvertJsArgs(aArgs); - if (convertResult.isErr()) { - aError.ThrowUnknownError(aFuncName + convertResult.unwrapErr()); - return nullptr; - } - auto convertedArgs = convertResult.unwrap(); - - // Create the promise that we return to JS - nsCOMPtr xpcomGlobal = - do_QueryInterface(aGlobal.GetAsSupports()); - RefPtr returnPromise = - dom::Promise::Create(xpcomGlobal, aError); - if (aError.Failed()) { - return nullptr; - } - - // Create a second promise that gets resolved by a background task that - // calls the scaffolding function - RefPtr taskPromise = new typename TaskPromiseType::Private(aFuncName.get()); - nsresult dispatchResult = NS_DispatchBackgroundTask( - NS_NewRunnableFunction(aFuncName.get(), - [args = std::move(convertedArgs), taskPromise, - aScaffoldingFunc, aFuncName]() mutable { - auto callResult = CallScaffoldingFunc( - aScaffoldingFunc, std::move(args)); - taskPromise->Resolve(std::move(callResult), - aFuncName.get()); - }), - NS_DISPATCH_EVENT_MAY_BLOCK); - if (NS_FAILED(dispatchResult)) { - taskPromise->Reject(dispatchResult, aFuncName.get()); - } - - // When the background task promise completes, resolve the JS promise - taskPromise->Then( - GetCurrentSerialEventTarget(), aFuncName.get(), - [xpcomGlobal, returnPromise, - aFuncName](typename TaskPromiseType::ResolveOrRejectValue&& aResult) { - if (!aResult.IsResolve()) { - returnPromise->MaybeRejectWithUnknownError(aFuncName); - return; - } - - dom::AutoEntryScript aes(xpcomGlobal, aFuncName.get()); - dom::RootedDictionary returnValue( - aes.cx()); - - ReturnResult(aes.cx(), aResult.ResolveValue(), returnValue, - aFuncName); - returnPromise->MaybeResolve(returnValue); - }); - - // Return the JS promise, using forget() to convert it to already_AddRefed - return returnPromise.forget(); - } - - // Perform an sync scaffolding call - // - // aFuncName should be a literal C string - static void CallSync( - ScaffoldingFunc aScaffoldingFunc, const dom::GlobalObject& aGlobal, - const dom::Sequence& aArgs, - dom::RootedDictionary& aReturnValue, - const nsLiteralCString& aFuncName, ErrorResult& aError) { - auto convertResult = ConvertJsArgs(aArgs); - if (convertResult.isErr()) { - aError.ThrowUnknownError(aFuncName + convertResult.unwrapErr()); - return; - } - - auto callResult = CallScaffoldingFunc(aScaffoldingFunc, - std::move(convertResult.unwrap())); - - ReturnResult(aGlobal.Context(), callResult, aReturnValue, aFuncName); - } - - private: - using RustArgs = std::tuple; - using IntermediateArgs = - std::tuple; - using RustCallResult = RustCallResult; - using TaskPromiseType = MozPromise; - - template - using NthArgConverter = - typename std::tuple_element>::type; - - // Convert arguments from JS - // - // This should be called in the main thread - static Result ConvertJsArgs( - const dom::Sequence& aArgs) { - IntermediateArgs convertedArgs; - if (aArgs.Length() != std::tuple_size_v) { - return mozilla::Err("Wrong argument count"_ns); - } - auto result = PrepareArgsHelper<0>(aArgs, convertedArgs); - return result.map([&](auto _) { return std::move(convertedArgs); }); - } - - // Helper function for PrepareArgs that uses c++ magic to help with iteration - template - static Result PrepareArgsHelper( - const dom::Sequence& aArgs, - IntermediateArgs& aConvertedArgs) { - if constexpr (I >= sizeof...(ArgConverters)) { - // Iteration complete - return mozilla::Ok(); - } else { - // Single iteration step - auto result = NthArgConverter::FromJs(aArgs[I]); - if (result.isOk()) { - // The conversion worked, store our result and move on to the next - std::get(aConvertedArgs) = result.unwrap(); - return PrepareArgsHelper(aArgs, aConvertedArgs); - } else { - // The conversion failed, return an error and don't continue - return mozilla::Err(result.unwrapErr() + - nsPrintfCString(" (arg %ld)", I)); - } - } - } - - // Call the scaffolding function - // - // For async calls this should be called in the worker thread - static RustCallResult CallScaffoldingFunc(ScaffoldingFunc aFunc, - IntermediateArgs&& aArgs) { - return CallScaffoldingFuncHelper( - aFunc, std::move(aArgs), std::index_sequence_for()); - } - - // Helper function for CallScaffoldingFunc that uses c++ magic to help with - // iteration - template - static RustCallResult CallScaffoldingFuncHelper( - ScaffoldingFunc aFunc, IntermediateArgs&& aArgs, - std::index_sequence seq) { - RustCallResult result; - - auto makeCall = [&]() mutable { - return aFunc( - NthArgConverter::IntoRust(std::move(std::get(aArgs)))..., - &result.mCallStatus); - }; - if constexpr (std::is_void_v) { - makeCall(); - } else { - result.mReturnValue = makeCall(); - } - return result; - } - - // Return the result of the scaffolding call back to JS - // - // This should be called on the main thread - static void ReturnResult( - JSContext* aContext, RustCallResult& aCallResult, - dom::RootedDictionary& aReturnValue, - const nsLiteralCString& aFuncName) { - switch (aCallResult.mCallStatus.code) { - case RUST_CALL_SUCCESS: { - aReturnValue.mCode = dom::UniFFIScaffoldingCallCode::Success; - if constexpr (!std::is_void_v) { - auto convertResult = - ReturnConverter::FromRust(aCallResult.mReturnValue); - if (convertResult.isOk()) { - ReturnConverter::IntoJs(aContext, std::move(convertResult.unwrap()), - aReturnValue.mData.Construct()); - } else { - aReturnValue.mCode = dom::UniFFIScaffoldingCallCode::Internal_error; - aReturnValue.mInternalErrorMessage.Construct( - aFuncName + " converting result: "_ns + - convertResult.unwrapErr()); - } - } - break; - } - - case RUST_CALL_ERROR: { - // Rust Err() value. Populate data with the `RustBuffer` containing the - // error - aReturnValue.mCode = dom::UniFFIScaffoldingCallCode::Error; - aReturnValue.mData.Construct().SetAsArrayBuffer().Init( - OwnedRustBuffer(aCallResult.mCallStatus.error_buf) - .IntoArrayBuffer(aContext)); - break; - } - - default: { - // This indicates a RustError, which shouldn't happen in practice since - // FF sets panic=abort - aReturnValue.mCode = dom::UniFFIScaffoldingCallCode::Internal_error; - aReturnValue.mInternalErrorMessage.Construct(aFuncName + - " Unexpected Error"_ns); - break; - } - } - } -}; - -} // namespace mozilla::uniffi - -#endif // mozilla_ScaffoldingCall_h diff --git a/toolkit/components/uniffi-js/ScaffoldingConverter.h b/toolkit/components/uniffi-js/ScaffoldingConverter.h deleted file mode 100644 index 59829938c2e2..000000000000 --- a/toolkit/components/uniffi-js/ScaffoldingConverter.h +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_ScaffoldingConverter_h -#define mozilla_ScaffoldingConverter_h - -#include -#include -#include "nsString.h" -#include "mozilla/ResultVariant.h" -#include "mozilla/dom/OwnedRustBuffer.h" -#include "mozilla/dom/PrimitiveConversions.h" -#include "mozilla/dom/TypedArray.h" -#include "mozilla/dom/UniFFIBinding.h" -#include "mozilla/dom/UniFFIPointer.h" -#include "mozilla/dom/UniFFIPointerType.h" -#include "mozilla/dom/UniFFIRust.h" -#include "mozilla/dom/UniFFIScaffolding.h" - -namespace mozilla::uniffi { - -class ScaffoldingConverterTagDefault {}; - -// Handle converting types between JS and Rust -// -// Scaffolding conversions are done using a 2 step process: -// - Call FromJs/FromRust to convert to an intermediate type -// - Call IntoJs/IntoRust to convert from that type to the target type -// -// The main reason for this is handling RustBuffers when other arguments fail -// to convert. By using OwnedRustBuffer as the intermediate type, we can -// ensure those buffers get freed in that case. Note that we can't use -// OwnedRustBuffer as the Rust type. Passing the buffer into Rust transfers -// ownership so we shouldn't free the buffer in this case. -// -// For most other types, we just use the Rust type as the intermediate type. -template -class ScaffoldingConverter { - public: - using RustType = T; - using IntermediateType = T; - - // Convert a JS value to an intermedate type - // - // This inputs a const ref, because that's what the WebIDL bindings send to - // us. - // - // If this succeeds then IntoRust is also guaranteed to succeed - static mozilla::Result FromJs( - const dom::ScaffoldingType& aValue) { - if (!aValue.IsDouble()) { - return Err("Bad argument type"_ns); - } - double value = aValue.GetAsDouble(); - - if (std::isnan(value)) { - return Err("NaN not allowed"_ns); - } - - if constexpr (std::is_integral::value) { - // Use PrimitiveConversionTraits_Limits rather than std::numeric_limits, - // since it handles JS-specific bounds like the 64-bit integer limits. - // (see Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER) - if (value < dom::PrimitiveConversionTraits_Limits::min() || - value > dom::PrimitiveConversionTraits_Limits::max()) { - return Err("Out of bounds"_ns); - } - } - - // Don't check float bounds for a few reasons. - // - It's difficult because - // PrimitiveConversionTraits_Limits::min() is the smallest - // positive value, rather than the most negative. - // - A float value unlikely to overflow - // - It's also likely that we can't do an exact conversion because the - // float doesn't have enough precision, but it doesn't seem correct - // to error out in that case. - - RustType rv = static_cast(value); - if constexpr (std::is_integral::value) { - if (rv != value) { - return Err("Not an integer"_ns); - } - } - - return rv; - } - - // Convert an intermediate type to a Rust type - // - // IntoRust doesn't touch the JS data, so it's safe to call in a worker thread - static RustType IntoRust(IntermediateType aValue) { return aValue; } - - // Convert an Rust type to an intermediate type - // - // This inputs a value since RustTypes are POD types - // - // If this succeeds then IntoJs is also guaranteed to succeed - static mozilla::Result FromRust( - RustType aValue) { - if constexpr (std::is_same::value || - std::is_same::value) { - // Check that the value can fit in a double (only needed for 64 bit types) - if (aValue < dom::PrimitiveConversionTraits_Limits::min() || - aValue > dom::PrimitiveConversionTraits_Limits::max()) { - return Err("Out of bounds"_ns); - } - } - if constexpr (std::is_floating_point::value) { - if (std::isnan(aValue)) { - return Err("NaN not allowed"_ns); - } - } - return aValue; - } - - // Convert an intermedate type to a JS type - // - // This inputs an r-value reference since we may want to move data out of - // this type. - static void IntoJs(JSContext* aContext, IntermediateType&& aValue, - dom::ScaffoldingType& aDest) { - aDest.SetAsDouble() = aValue; - } -}; - -template <> -class ScaffoldingConverter { - public: - using RustType = RustBuffer; - using IntermediateType = OwnedRustBuffer; - - static mozilla::Result FromJs( - const dom::ScaffoldingType& aValue) { - if (!aValue.IsArrayBuffer()) { - return Err("Bad argument type"_ns); - } - - const dom::ArrayBuffer& arrayBuf = aValue.GetAsArrayBuffer(); - arrayBuf.ComputeState(); - return OwnedRustBuffer::FromArrayBuffer(arrayBuf); - } - - static RustBuffer IntoRust(OwnedRustBuffer&& aValue) { - return aValue.IntoRustBuffer(); - } - - static mozilla::Result FromRust( - RustBuffer aValue) { - return OwnedRustBuffer(aValue); - } - - static void IntoJs(JSContext* aContext, OwnedRustBuffer&& aValue, - dom::ScaffoldingType& aDest) { - aDest.SetAsArrayBuffer().Init(aValue.IntoArrayBuffer(aContext)); - } -}; - -// ScaffoldingConverter for object pointers -template -class ScaffoldingObjectConverter { - public: - using RustType = void*; - using IntermediateType = void*; - - static mozilla::Result FromJs( - const dom::ScaffoldingType& aValue) { - if (!aValue.IsUniFFIPointer()) { - return Err("Bad argument type"_ns); - } - dom::UniFFIPointer& value = aValue.GetAsUniFFIPointer(); - if (!value.IsSamePtrType(PointerType)) { - return Err("Bad pointer type"_ns); - } - return value.GetPtr(); - } - - static void* IntoRust(void* aValue) { return aValue; } - - static mozilla::Result FromRust(void* aValue) { - return aValue; - } - - static void IntoJs(JSContext* aContext, void* aValue, - dom::ScaffoldingType& aDest) { - aDest.SetAsUniFFIPointer() = - dom::UniFFIPointer::Create(aValue, PointerType); - } -}; - -// ScaffoldingConverter for void returns -// -// This doesn't implement the normal interface, it's only use is a the -// ReturnConverter parameter of ScaffoldingCallHandler. -template <> -class ScaffoldingConverter { - public: - using RustType = void; -}; - -} // namespace mozilla::uniffi - -#endif // mozilla_ScaffoldingConverter_h diff --git a/toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp b/toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp deleted file mode 100644 index 46b9ec9a3992..000000000000 --- a/toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp +++ /dev/null @@ -1,992 +0,0 @@ -// Generated by uniffi-bindgen-gecko-js. DO NOT EDIT. - -#include "nsString.h" -#include "nsPrintfCString.h" -#include "mozilla/Maybe.h" -#include "mozilla/dom/UniFFIScaffolding.h" -#include "mozilla/dom/ScaffoldingCall.h" - -namespace mozilla::uniffi { - -using dom::ArrayBuffer; -using dom::GlobalObject; -using dom::RootedDictionary; -using dom::Promise; -using dom::ScaffoldingType; -using dom::Sequence; -using dom::UniFFIPointer; -using dom::UniFFIScaffoldingCallResult; - -// Define scaffolding functions from UniFFI -extern "C" { - double geometry_ba8c_gradient(RustBuffer, RustCallStatus*); - RustBuffer geometry_ba8c_intersection(RustBuffer, RustBuffer, RustCallStatus*); - uint64_t arithmetic_77d6_add(uint64_t, uint64_t, RustCallStatus*); - uint64_t arithmetic_77d6_sub(uint64_t, uint64_t, RustCallStatus*); - uint64_t arithmetic_77d6_div(uint64_t, uint64_t, RustCallStatus*); - int8_t arithmetic_77d6_equal(uint64_t, uint64_t, RustCallStatus*); - void ffi_rondpoint_84bf_Retourneur_object_free(void *, RustCallStatus*); - void * rondpoint_84bf_Retourneur_new(RustCallStatus*); - int8_t rondpoint_84bf_Retourneur_identique_i8(void *, int8_t, RustCallStatus*); - uint8_t rondpoint_84bf_Retourneur_identique_u8(void *, uint8_t, RustCallStatus*); - int16_t rondpoint_84bf_Retourneur_identique_i16(void *, int16_t, RustCallStatus*); - uint16_t rondpoint_84bf_Retourneur_identique_u16(void *, uint16_t, RustCallStatus*); - int32_t rondpoint_84bf_Retourneur_identique_i32(void *, int32_t, RustCallStatus*); - uint32_t rondpoint_84bf_Retourneur_identique_u32(void *, uint32_t, RustCallStatus*); - int64_t rondpoint_84bf_Retourneur_identique_i64(void *, int64_t, RustCallStatus*); - uint64_t rondpoint_84bf_Retourneur_identique_u64(void *, uint64_t, RustCallStatus*); - float rondpoint_84bf_Retourneur_identique_float(void *, float, RustCallStatus*); - double rondpoint_84bf_Retourneur_identique_double(void *, double, RustCallStatus*); - int8_t rondpoint_84bf_Retourneur_identique_boolean(void *, int8_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Retourneur_identique_string(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Retourneur_identique_nombres_signes(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Retourneur_identique_nombres(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire(void *, RustBuffer, RustCallStatus*); - void ffi_rondpoint_84bf_Stringifier_object_free(void *, RustCallStatus*); - void * rondpoint_84bf_Stringifier_new(RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_well_known_string(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_i8(void *, int8_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_u8(void *, uint8_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_i16(void *, int16_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_u16(void *, uint16_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_i32(void *, int32_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_u32(void *, uint32_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_i64(void *, int64_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_u64(void *, uint64_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_float(void *, float, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_double(void *, double, RustCallStatus*); - RustBuffer rondpoint_84bf_Stringifier_to_string_boolean(void *, int8_t, RustCallStatus*); - void ffi_rondpoint_84bf_Optionneur_object_free(void *, RustCallStatus*); - void * rondpoint_84bf_Optionneur_new(RustCallStatus*); - int8_t rondpoint_84bf_Optionneur_sinon_boolean(void *, int8_t, RustCallStatus*); - RustBuffer rondpoint_84bf_Optionneur_sinon_string(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Optionneur_sinon_sequence(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Optionneur_sinon_null(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_Optionneur_sinon_zero(void *, RustBuffer, RustCallStatus*); - uint8_t rondpoint_84bf_Optionneur_sinon_u8_dec(void *, uint8_t, RustCallStatus*); - int8_t rondpoint_84bf_Optionneur_sinon_i8_dec(void *, int8_t, RustCallStatus*); - uint16_t rondpoint_84bf_Optionneur_sinon_u16_dec(void *, uint16_t, RustCallStatus*); - int16_t rondpoint_84bf_Optionneur_sinon_i16_dec(void *, int16_t, RustCallStatus*); - uint32_t rondpoint_84bf_Optionneur_sinon_u32_dec(void *, uint32_t, RustCallStatus*); - int32_t rondpoint_84bf_Optionneur_sinon_i32_dec(void *, int32_t, RustCallStatus*); - uint64_t rondpoint_84bf_Optionneur_sinon_u64_dec(void *, uint64_t, RustCallStatus*); - int64_t rondpoint_84bf_Optionneur_sinon_i64_dec(void *, int64_t, RustCallStatus*); - uint8_t rondpoint_84bf_Optionneur_sinon_u8_hex(void *, uint8_t, RustCallStatus*); - int8_t rondpoint_84bf_Optionneur_sinon_i8_hex(void *, int8_t, RustCallStatus*); - uint16_t rondpoint_84bf_Optionneur_sinon_u16_hex(void *, uint16_t, RustCallStatus*); - int16_t rondpoint_84bf_Optionneur_sinon_i16_hex(void *, int16_t, RustCallStatus*); - uint32_t rondpoint_84bf_Optionneur_sinon_u32_hex(void *, uint32_t, RustCallStatus*); - int32_t rondpoint_84bf_Optionneur_sinon_i32_hex(void *, int32_t, RustCallStatus*); - uint64_t rondpoint_84bf_Optionneur_sinon_u64_hex(void *, uint64_t, RustCallStatus*); - int64_t rondpoint_84bf_Optionneur_sinon_i64_hex(void *, int64_t, RustCallStatus*); - uint32_t rondpoint_84bf_Optionneur_sinon_u32_oct(void *, uint32_t, RustCallStatus*); - float rondpoint_84bf_Optionneur_sinon_f32(void *, float, RustCallStatus*); - double rondpoint_84bf_Optionneur_sinon_f64(void *, double, RustCallStatus*); - RustBuffer rondpoint_84bf_Optionneur_sinon_enum(void *, RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_copie_dictionnaire(RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_copie_enumeration(RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_copie_enumerations(RustBuffer, RustCallStatus*); - RustBuffer rondpoint_84bf_copie_carte(RustBuffer, RustCallStatus*); - int8_t rondpoint_84bf_switcheroo(int8_t, RustCallStatus*); - void ffi_sprites_f59e_Sprite_object_free(void *, RustCallStatus*); - void * sprites_f59e_Sprite_new(RustBuffer, RustCallStatus*); - void * sprites_f59e_Sprite_new_relative_to(RustBuffer, RustBuffer, RustCallStatus*); - RustBuffer sprites_f59e_Sprite_get_position(void *, RustCallStatus*); - void sprites_f59e_Sprite_move_to(void *, RustBuffer, RustCallStatus*); - void sprites_f59e_Sprite_move_by(void *, RustBuffer, RustCallStatus*); - RustBuffer sprites_f59e_translate(RustBuffer, RustBuffer, RustCallStatus*); - void ffi_todolist_9473_TodoList_object_free(void *, RustCallStatus*); - void * todolist_9473_TodoList_new(RustCallStatus*); - void todolist_9473_TodoList_add_item(void *, RustBuffer, RustCallStatus*); - void todolist_9473_TodoList_add_entry(void *, RustBuffer, RustCallStatus*); - RustBuffer todolist_9473_TodoList_get_entries(void *, RustCallStatus*); - RustBuffer todolist_9473_TodoList_get_items(void *, RustCallStatus*); - void todolist_9473_TodoList_add_entries(void *, RustBuffer, RustCallStatus*); - void todolist_9473_TodoList_add_items(void *, RustBuffer, RustCallStatus*); - RustBuffer todolist_9473_TodoList_get_last_entry(void *, RustCallStatus*); - RustBuffer todolist_9473_TodoList_get_last(void *, RustCallStatus*); - RustBuffer todolist_9473_TodoList_get_first(void *, RustCallStatus*); - void todolist_9473_TodoList_clear_item(void *, RustBuffer, RustCallStatus*); - void todolist_9473_TodoList_make_default(void *, RustCallStatus*); - RustBuffer todolist_9473_get_default_list(RustCallStatus*); - void todolist_9473_set_default_list(void *, RustCallStatus*); - RustBuffer todolist_9473_create_entry_with(RustBuffer, RustCallStatus*); -} - -// Define pointer types -const static mozilla::uniffi::UniFFIPointerType kRondpointRetourneurPointerType { - "rondpoint::Retourneur"_ns, - ffi_rondpoint_84bf_Retourneur_object_free -}; -const static mozilla::uniffi::UniFFIPointerType kRondpointStringifierPointerType { - "rondpoint::Stringifier"_ns, - ffi_rondpoint_84bf_Stringifier_object_free -}; -const static mozilla::uniffi::UniFFIPointerType kRondpointOptionneurPointerType { - "rondpoint::Optionneur"_ns, - ffi_rondpoint_84bf_Optionneur_object_free -}; -const static mozilla::uniffi::UniFFIPointerType kSpritesSpritePointerType { - "sprites::Sprite"_ns, - ffi_sprites_f59e_Sprite_object_free -}; -const static mozilla::uniffi::UniFFIPointerType kTodolistTodoListPointerType { - "todolist::TodoList"_ns, - ffi_todolist_9473_TodoList_object_free -}; - -Maybe> UniFFIFixturesCallAsync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, ErrorResult& aError) { - switch (aId) { - case 0: { // geometry:geometry_ba8c_gradient - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(geometry_ba8c_gradient, aGlobal, aArgs, "geometry_ba8c_gradient: "_ns, aError)); - } - case 1: { // geometry:geometry_ba8c_intersection - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(geometry_ba8c_intersection, aGlobal, aArgs, "geometry_ba8c_intersection: "_ns, aError)); - } - case 2: { // arithmetic:arithmetic_77d6_add - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(arithmetic_77d6_add, aGlobal, aArgs, "arithmetic_77d6_add: "_ns, aError)); - } - case 3: { // arithmetic:arithmetic_77d6_sub - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(arithmetic_77d6_sub, aGlobal, aArgs, "arithmetic_77d6_sub: "_ns, aError)); - } - case 4: { // arithmetic:arithmetic_77d6_div - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(arithmetic_77d6_div, aGlobal, aArgs, "arithmetic_77d6_div: "_ns, aError)); - } - case 5: { // arithmetic:arithmetic_77d6_equal - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(arithmetic_77d6_equal, aGlobal, aArgs, "arithmetic_77d6_equal: "_ns, aError)); - } - case 6: { // rondpoint:rondpoint_84bf_Retourneur_new - using CallHandler = ScaffoldingCallHandler>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_new, aGlobal, aArgs, "rondpoint_84bf_Retourneur_new: "_ns, aError)); - } - case 7: { // rondpoint:rondpoint_84bf_Retourneur_identique_i8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_i8, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_i8: "_ns, aError)); - } - case 8: { // rondpoint:rondpoint_84bf_Retourneur_identique_u8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_u8, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_u8: "_ns, aError)); - } - case 9: { // rondpoint:rondpoint_84bf_Retourneur_identique_i16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_i16, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_i16: "_ns, aError)); - } - case 10: { // rondpoint:rondpoint_84bf_Retourneur_identique_u16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_u16, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_u16: "_ns, aError)); - } - case 11: { // rondpoint:rondpoint_84bf_Retourneur_identique_i32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_i32, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_i32: "_ns, aError)); - } - case 12: { // rondpoint:rondpoint_84bf_Retourneur_identique_u32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_u32, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_u32: "_ns, aError)); - } - case 13: { // rondpoint:rondpoint_84bf_Retourneur_identique_i64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_i64, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_i64: "_ns, aError)); - } - case 14: { // rondpoint:rondpoint_84bf_Retourneur_identique_u64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_u64, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_u64: "_ns, aError)); - } - case 15: { // rondpoint:rondpoint_84bf_Retourneur_identique_float - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_float, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_float: "_ns, aError)); - } - case 16: { // rondpoint:rondpoint_84bf_Retourneur_identique_double - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_double, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_double: "_ns, aError)); - } - case 17: { // rondpoint:rondpoint_84bf_Retourneur_identique_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_boolean, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_boolean: "_ns, aError)); - } - case 18: { // rondpoint:rondpoint_84bf_Retourneur_identique_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_string, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_string: "_ns, aError)); - } - case 19: { // rondpoint:rondpoint_84bf_Retourneur_identique_nombres_signes - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_nombres_signes, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_nombres_signes: "_ns, aError)); - } - case 20: { // rondpoint:rondpoint_84bf_Retourneur_identique_nombres - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_nombres, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_nombres: "_ns, aError)); - } - case 21: { // rondpoint:rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire, aGlobal, aArgs, "rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire: "_ns, aError)); - } - case 22: { // rondpoint:rondpoint_84bf_Stringifier_new - using CallHandler = ScaffoldingCallHandler>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_new, aGlobal, aArgs, "rondpoint_84bf_Stringifier_new: "_ns, aError)); - } - case 23: { // rondpoint:rondpoint_84bf_Stringifier_well_known_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_well_known_string, aGlobal, aArgs, "rondpoint_84bf_Stringifier_well_known_string: "_ns, aError)); - } - case 24: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_i8, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_i8: "_ns, aError)); - } - case 25: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_u8, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_u8: "_ns, aError)); - } - case 26: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_i16, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_i16: "_ns, aError)); - } - case 27: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_u16, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_u16: "_ns, aError)); - } - case 28: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_i32, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_i32: "_ns, aError)); - } - case 29: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_u32, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_u32: "_ns, aError)); - } - case 30: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_i64, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_i64: "_ns, aError)); - } - case 31: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_u64, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_u64: "_ns, aError)); - } - case 32: { // rondpoint:rondpoint_84bf_Stringifier_to_string_float - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_float, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_float: "_ns, aError)); - } - case 33: { // rondpoint:rondpoint_84bf_Stringifier_to_string_double - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_double, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_double: "_ns, aError)); - } - case 34: { // rondpoint:rondpoint_84bf_Stringifier_to_string_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Stringifier_to_string_boolean, aGlobal, aArgs, "rondpoint_84bf_Stringifier_to_string_boolean: "_ns, aError)); - } - case 35: { // rondpoint:rondpoint_84bf_Optionneur_new - using CallHandler = ScaffoldingCallHandler>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_new, aGlobal, aArgs, "rondpoint_84bf_Optionneur_new: "_ns, aError)); - } - case 36: { // rondpoint:rondpoint_84bf_Optionneur_sinon_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_boolean, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_boolean: "_ns, aError)); - } - case 37: { // rondpoint:rondpoint_84bf_Optionneur_sinon_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_string, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_string: "_ns, aError)); - } - case 38: { // rondpoint:rondpoint_84bf_Optionneur_sinon_sequence - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_sequence, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_sequence: "_ns, aError)); - } - case 39: { // rondpoint:rondpoint_84bf_Optionneur_sinon_null - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_null, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_null: "_ns, aError)); - } - case 40: { // rondpoint:rondpoint_84bf_Optionneur_sinon_zero - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_zero, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_zero: "_ns, aError)); - } - case 41: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u8_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u8_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u8_dec: "_ns, aError)); - } - case 42: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i8_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i8_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i8_dec: "_ns, aError)); - } - case 43: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u16_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u16_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u16_dec: "_ns, aError)); - } - case 44: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i16_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i16_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i16_dec: "_ns, aError)); - } - case 45: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u32_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u32_dec: "_ns, aError)); - } - case 46: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i32_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i32_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i32_dec: "_ns, aError)); - } - case 47: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u64_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u64_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u64_dec: "_ns, aError)); - } - case 48: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i64_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i64_dec, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i64_dec: "_ns, aError)); - } - case 49: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u8_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u8_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u8_hex: "_ns, aError)); - } - case 50: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i8_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i8_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i8_hex: "_ns, aError)); - } - case 51: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u16_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u16_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u16_hex: "_ns, aError)); - } - case 52: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i16_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i16_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i16_hex: "_ns, aError)); - } - case 53: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u32_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u32_hex: "_ns, aError)); - } - case 54: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i32_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i32_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i32_hex: "_ns, aError)); - } - case 55: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u64_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u64_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u64_hex: "_ns, aError)); - } - case 56: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i64_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_i64_hex, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_i64_hex: "_ns, aError)); - } - case 57: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_oct - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_u32_oct, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_u32_oct: "_ns, aError)); - } - case 58: { // rondpoint:rondpoint_84bf_Optionneur_sinon_f32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_f32, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_f32: "_ns, aError)); - } - case 59: { // rondpoint:rondpoint_84bf_Optionneur_sinon_f64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_f64, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_f64: "_ns, aError)); - } - case 60: { // rondpoint:rondpoint_84bf_Optionneur_sinon_enum - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_Optionneur_sinon_enum, aGlobal, aArgs, "rondpoint_84bf_Optionneur_sinon_enum: "_ns, aError)); - } - case 61: { // rondpoint:rondpoint_84bf_copie_dictionnaire - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_copie_dictionnaire, aGlobal, aArgs, "rondpoint_84bf_copie_dictionnaire: "_ns, aError)); - } - case 62: { // rondpoint:rondpoint_84bf_copie_enumeration - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_copie_enumeration, aGlobal, aArgs, "rondpoint_84bf_copie_enumeration: "_ns, aError)); - } - case 63: { // rondpoint:rondpoint_84bf_copie_enumerations - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_copie_enumerations, aGlobal, aArgs, "rondpoint_84bf_copie_enumerations: "_ns, aError)); - } - case 64: { // rondpoint:rondpoint_84bf_copie_carte - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_copie_carte, aGlobal, aArgs, "rondpoint_84bf_copie_carte: "_ns, aError)); - } - case 65: { // rondpoint:rondpoint_84bf_switcheroo - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(rondpoint_84bf_switcheroo, aGlobal, aArgs, "rondpoint_84bf_switcheroo: "_ns, aError)); - } - case 66: { // sprites:sprites_f59e_Sprite_new - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(sprites_f59e_Sprite_new, aGlobal, aArgs, "sprites_f59e_Sprite_new: "_ns, aError)); - } - case 67: { // sprites:sprites_f59e_Sprite_new_relative_to - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(sprites_f59e_Sprite_new_relative_to, aGlobal, aArgs, "sprites_f59e_Sprite_new_relative_to: "_ns, aError)); - } - case 68: { // sprites:sprites_f59e_Sprite_get_position - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>>; - return Some(CallHandler::CallAsync(sprites_f59e_Sprite_get_position, aGlobal, aArgs, "sprites_f59e_Sprite_get_position: "_ns, aError)); - } - case 69: { // sprites:sprites_f59e_Sprite_move_to - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(sprites_f59e_Sprite_move_to, aGlobal, aArgs, "sprites_f59e_Sprite_move_to: "_ns, aError)); - } - case 70: { // sprites:sprites_f59e_Sprite_move_by - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(sprites_f59e_Sprite_move_by, aGlobal, aArgs, "sprites_f59e_Sprite_move_by: "_ns, aError)); - } - case 71: { // sprites:sprites_f59e_translate - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(sprites_f59e_translate, aGlobal, aArgs, "sprites_f59e_translate: "_ns, aError)); - } - case 72: { // todolist:todolist_9473_TodoList_new - using CallHandler = ScaffoldingCallHandler>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_new, aGlobal, aArgs, "todolist_9473_TodoList_new: "_ns, aError)); - } - case 73: { // todolist:todolist_9473_TodoList_add_item - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_add_item, aGlobal, aArgs, "todolist_9473_TodoList_add_item: "_ns, aError)); - } - case 74: { // todolist:todolist_9473_TodoList_add_entry - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_add_entry, aGlobal, aArgs, "todolist_9473_TodoList_add_entry: "_ns, aError)); - } - case 75: { // todolist:todolist_9473_TodoList_get_entries - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_get_entries, aGlobal, aArgs, "todolist_9473_TodoList_get_entries: "_ns, aError)); - } - case 76: { // todolist:todolist_9473_TodoList_get_items - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_get_items, aGlobal, aArgs, "todolist_9473_TodoList_get_items: "_ns, aError)); - } - case 77: { // todolist:todolist_9473_TodoList_add_entries - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_add_entries, aGlobal, aArgs, "todolist_9473_TodoList_add_entries: "_ns, aError)); - } - case 78: { // todolist:todolist_9473_TodoList_add_items - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_add_items, aGlobal, aArgs, "todolist_9473_TodoList_add_items: "_ns, aError)); - } - case 79: { // todolist:todolist_9473_TodoList_get_last_entry - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_get_last_entry, aGlobal, aArgs, "todolist_9473_TodoList_get_last_entry: "_ns, aError)); - } - case 80: { // todolist:todolist_9473_TodoList_get_last - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_get_last, aGlobal, aArgs, "todolist_9473_TodoList_get_last: "_ns, aError)); - } - case 81: { // todolist:todolist_9473_TodoList_get_first - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_get_first, aGlobal, aArgs, "todolist_9473_TodoList_get_first: "_ns, aError)); - } - case 82: { // todolist:todolist_9473_TodoList_clear_item - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_clear_item, aGlobal, aArgs, "todolist_9473_TodoList_clear_item: "_ns, aError)); - } - case 83: { // todolist:todolist_9473_TodoList_make_default - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_TodoList_make_default, aGlobal, aArgs, "todolist_9473_TodoList_make_default: "_ns, aError)); - } - case 84: { // todolist:todolist_9473_get_default_list - using CallHandler = ScaffoldingCallHandler>; - return Some(CallHandler::CallAsync(todolist_9473_get_default_list, aGlobal, aArgs, "todolist_9473_get_default_list: "_ns, aError)); - } - case 85: { // todolist:todolist_9473_set_default_list - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - return Some(CallHandler::CallAsync(todolist_9473_set_default_list, aGlobal, aArgs, "todolist_9473_set_default_list: "_ns, aError)); - } - case 86: { // todolist:todolist_9473_create_entry_with - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - return Some(CallHandler::CallAsync(todolist_9473_create_entry_with, aGlobal, aArgs, "todolist_9473_create_entry_with: "_ns, aError)); - } - } - return Nothing(); -} - -bool UniFFIFixturesCallSync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, RootedDictionary& aReturnValue, ErrorResult& aError) { - switch (aId) { - case 0: { // geometry:geometry_ba8c_gradient - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(geometry_ba8c_gradient, aGlobal, aArgs, aReturnValue, "geometry_ba8c_gradient: "_ns, aError); - return true; - } - case 1: { // geometry:geometry_ba8c_intersection - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(geometry_ba8c_intersection, aGlobal, aArgs, aReturnValue, "geometry_ba8c_intersection: "_ns, aError); - return true; - } - case 2: { // arithmetic:arithmetic_77d6_add - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(arithmetic_77d6_add, aGlobal, aArgs, aReturnValue, "arithmetic_77d6_add: "_ns, aError); - return true; - } - case 3: { // arithmetic:arithmetic_77d6_sub - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(arithmetic_77d6_sub, aGlobal, aArgs, aReturnValue, "arithmetic_77d6_sub: "_ns, aError); - return true; - } - case 4: { // arithmetic:arithmetic_77d6_div - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(arithmetic_77d6_div, aGlobal, aArgs, aReturnValue, "arithmetic_77d6_div: "_ns, aError); - return true; - } - case 5: { // arithmetic:arithmetic_77d6_equal - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(arithmetic_77d6_equal, aGlobal, aArgs, aReturnValue, "arithmetic_77d6_equal: "_ns, aError); - return true; - } - case 6: { // rondpoint:rondpoint_84bf_Retourneur_new - using CallHandler = ScaffoldingCallHandler>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_new, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_new: "_ns, aError); - return true; - } - case 7: { // rondpoint:rondpoint_84bf_Retourneur_identique_i8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_i8, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_i8: "_ns, aError); - return true; - } - case 8: { // rondpoint:rondpoint_84bf_Retourneur_identique_u8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_u8, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_u8: "_ns, aError); - return true; - } - case 9: { // rondpoint:rondpoint_84bf_Retourneur_identique_i16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_i16, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_i16: "_ns, aError); - return true; - } - case 10: { // rondpoint:rondpoint_84bf_Retourneur_identique_u16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_u16, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_u16: "_ns, aError); - return true; - } - case 11: { // rondpoint:rondpoint_84bf_Retourneur_identique_i32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_i32, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_i32: "_ns, aError); - return true; - } - case 12: { // rondpoint:rondpoint_84bf_Retourneur_identique_u32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_u32, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_u32: "_ns, aError); - return true; - } - case 13: { // rondpoint:rondpoint_84bf_Retourneur_identique_i64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_i64, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_i64: "_ns, aError); - return true; - } - case 14: { // rondpoint:rondpoint_84bf_Retourneur_identique_u64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_u64, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_u64: "_ns, aError); - return true; - } - case 15: { // rondpoint:rondpoint_84bf_Retourneur_identique_float - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_float, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_float: "_ns, aError); - return true; - } - case 16: { // rondpoint:rondpoint_84bf_Retourneur_identique_double - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_double, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_double: "_ns, aError); - return true; - } - case 17: { // rondpoint:rondpoint_84bf_Retourneur_identique_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_boolean, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_boolean: "_ns, aError); - return true; - } - case 18: { // rondpoint:rondpoint_84bf_Retourneur_identique_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_string, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_string: "_ns, aError); - return true; - } - case 19: { // rondpoint:rondpoint_84bf_Retourneur_identique_nombres_signes - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_nombres_signes, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_nombres_signes: "_ns, aError); - return true; - } - case 20: { // rondpoint:rondpoint_84bf_Retourneur_identique_nombres - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_nombres, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_nombres: "_ns, aError); - return true; - } - case 21: { // rondpoint:rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointRetourneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Retourneur_identique_optionneur_dictionnaire: "_ns, aError); - return true; - } - case 22: { // rondpoint:rondpoint_84bf_Stringifier_new - using CallHandler = ScaffoldingCallHandler>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_new, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_new: "_ns, aError); - return true; - } - case 23: { // rondpoint:rondpoint_84bf_Stringifier_well_known_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_well_known_string, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_well_known_string: "_ns, aError); - return true; - } - case 24: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_i8, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_i8: "_ns, aError); - return true; - } - case 25: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u8 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_u8, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_u8: "_ns, aError); - return true; - } - case 26: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_i16, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_i16: "_ns, aError); - return true; - } - case 27: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u16 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_u16, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_u16: "_ns, aError); - return true; - } - case 28: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_i32, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_i32: "_ns, aError); - return true; - } - case 29: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_u32, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_u32: "_ns, aError); - return true; - } - case 30: { // rondpoint:rondpoint_84bf_Stringifier_to_string_i64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_i64, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_i64: "_ns, aError); - return true; - } - case 31: { // rondpoint:rondpoint_84bf_Stringifier_to_string_u64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_u64, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_u64: "_ns, aError); - return true; - } - case 32: { // rondpoint:rondpoint_84bf_Stringifier_to_string_float - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_float, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_float: "_ns, aError); - return true; - } - case 33: { // rondpoint:rondpoint_84bf_Stringifier_to_string_double - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_double, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_double: "_ns, aError); - return true; - } - case 34: { // rondpoint:rondpoint_84bf_Stringifier_to_string_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointStringifierPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Stringifier_to_string_boolean, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Stringifier_to_string_boolean: "_ns, aError); - return true; - } - case 35: { // rondpoint:rondpoint_84bf_Optionneur_new - using CallHandler = ScaffoldingCallHandler>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_new, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_new: "_ns, aError); - return true; - } - case 36: { // rondpoint:rondpoint_84bf_Optionneur_sinon_boolean - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_boolean, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_boolean: "_ns, aError); - return true; - } - case 37: { // rondpoint:rondpoint_84bf_Optionneur_sinon_string - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_string, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_string: "_ns, aError); - return true; - } - case 38: { // rondpoint:rondpoint_84bf_Optionneur_sinon_sequence - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_sequence, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_sequence: "_ns, aError); - return true; - } - case 39: { // rondpoint:rondpoint_84bf_Optionneur_sinon_null - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_null, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_null: "_ns, aError); - return true; - } - case 40: { // rondpoint:rondpoint_84bf_Optionneur_sinon_zero - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_zero, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_zero: "_ns, aError); - return true; - } - case 41: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u8_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u8_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u8_dec: "_ns, aError); - return true; - } - case 42: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i8_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i8_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i8_dec: "_ns, aError); - return true; - } - case 43: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u16_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u16_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u16_dec: "_ns, aError); - return true; - } - case 44: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i16_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i16_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i16_dec: "_ns, aError); - return true; - } - case 45: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u32_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u32_dec: "_ns, aError); - return true; - } - case 46: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i32_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i32_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i32_dec: "_ns, aError); - return true; - } - case 47: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u64_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u64_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u64_dec: "_ns, aError); - return true; - } - case 48: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i64_dec - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i64_dec, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i64_dec: "_ns, aError); - return true; - } - case 49: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u8_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u8_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u8_hex: "_ns, aError); - return true; - } - case 50: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i8_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i8_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i8_hex: "_ns, aError); - return true; - } - case 51: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u16_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u16_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u16_hex: "_ns, aError); - return true; - } - case 52: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i16_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i16_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i16_hex: "_ns, aError); - return true; - } - case 53: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u32_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u32_hex: "_ns, aError); - return true; - } - case 54: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i32_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i32_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i32_hex: "_ns, aError); - return true; - } - case 55: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u64_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u64_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u64_hex: "_ns, aError); - return true; - } - case 56: { // rondpoint:rondpoint_84bf_Optionneur_sinon_i64_hex - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_i64_hex, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_i64_hex: "_ns, aError); - return true; - } - case 57: { // rondpoint:rondpoint_84bf_Optionneur_sinon_u32_oct - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_u32_oct, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_u32_oct: "_ns, aError); - return true; - } - case 58: { // rondpoint:rondpoint_84bf_Optionneur_sinon_f32 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_f32, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_f32: "_ns, aError); - return true; - } - case 59: { // rondpoint:rondpoint_84bf_Optionneur_sinon_f64 - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_f64, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_f64: "_ns, aError); - return true; - } - case 60: { // rondpoint:rondpoint_84bf_Optionneur_sinon_enum - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kRondpointOptionneurPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_Optionneur_sinon_enum, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_Optionneur_sinon_enum: "_ns, aError); - return true; - } - case 61: { // rondpoint:rondpoint_84bf_copie_dictionnaire - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_copie_dictionnaire, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_copie_dictionnaire: "_ns, aError); - return true; - } - case 62: { // rondpoint:rondpoint_84bf_copie_enumeration - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_copie_enumeration, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_copie_enumeration: "_ns, aError); - return true; - } - case 63: { // rondpoint:rondpoint_84bf_copie_enumerations - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_copie_enumerations, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_copie_enumerations: "_ns, aError); - return true; - } - case 64: { // rondpoint:rondpoint_84bf_copie_carte - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_copie_carte, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_copie_carte: "_ns, aError); - return true; - } - case 65: { // rondpoint:rondpoint_84bf_switcheroo - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(rondpoint_84bf_switcheroo, aGlobal, aArgs, aReturnValue, "rondpoint_84bf_switcheroo: "_ns, aError); - return true; - } - case 66: { // sprites:sprites_f59e_Sprite_new - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(sprites_f59e_Sprite_new, aGlobal, aArgs, aReturnValue, "sprites_f59e_Sprite_new: "_ns, aError); - return true; - } - case 67: { // sprites:sprites_f59e_Sprite_new_relative_to - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(sprites_f59e_Sprite_new_relative_to, aGlobal, aArgs, aReturnValue, "sprites_f59e_Sprite_new_relative_to: "_ns, aError); - return true; - } - case 68: { // sprites:sprites_f59e_Sprite_get_position - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>>; - CallHandler::CallSync(sprites_f59e_Sprite_get_position, aGlobal, aArgs, aReturnValue, "sprites_f59e_Sprite_get_position: "_ns, aError); - return true; - } - case 69: { // sprites:sprites_f59e_Sprite_move_to - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>, ScaffoldingConverter>; - CallHandler::CallSync(sprites_f59e_Sprite_move_to, aGlobal, aArgs, aReturnValue, "sprites_f59e_Sprite_move_to: "_ns, aError); - return true; - } - case 70: { // sprites:sprites_f59e_Sprite_move_by - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kSpritesSpritePointerType>, ScaffoldingConverter>; - CallHandler::CallSync(sprites_f59e_Sprite_move_by, aGlobal, aArgs, aReturnValue, "sprites_f59e_Sprite_move_by: "_ns, aError); - return true; - } - case 71: { // sprites:sprites_f59e_translate - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter, ScaffoldingConverter>; - CallHandler::CallSync(sprites_f59e_translate, aGlobal, aArgs, aReturnValue, "sprites_f59e_translate: "_ns, aError); - return true; - } - case 72: { // todolist:todolist_9473_TodoList_new - using CallHandler = ScaffoldingCallHandler>; - CallHandler::CallSync(todolist_9473_TodoList_new, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_new: "_ns, aError); - return true; - } - case 73: { // todolist:todolist_9473_TodoList_add_item - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_TodoList_add_item, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_add_item: "_ns, aError); - return true; - } - case 74: { // todolist:todolist_9473_TodoList_add_entry - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_TodoList_add_entry, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_add_entry: "_ns, aError); - return true; - } - case 75: { // todolist:todolist_9473_TodoList_get_entries - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_get_entries, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_get_entries: "_ns, aError); - return true; - } - case 76: { // todolist:todolist_9473_TodoList_get_items - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_get_items, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_get_items: "_ns, aError); - return true; - } - case 77: { // todolist:todolist_9473_TodoList_add_entries - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_TodoList_add_entries, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_add_entries: "_ns, aError); - return true; - } - case 78: { // todolist:todolist_9473_TodoList_add_items - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_TodoList_add_items, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_add_items: "_ns, aError); - return true; - } - case 79: { // todolist:todolist_9473_TodoList_get_last_entry - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_get_last_entry, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_get_last_entry: "_ns, aError); - return true; - } - case 80: { // todolist:todolist_9473_TodoList_get_last - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_get_last, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_get_last: "_ns, aError); - return true; - } - case 81: { // todolist:todolist_9473_TodoList_get_first - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_get_first, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_get_first: "_ns, aError); - return true; - } - case 82: { // todolist:todolist_9473_TodoList_clear_item - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_TodoList_clear_item, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_clear_item: "_ns, aError); - return true; - } - case 83: { // todolist:todolist_9473_TodoList_make_default - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_TodoList_make_default, aGlobal, aArgs, aReturnValue, "todolist_9473_TodoList_make_default: "_ns, aError); - return true; - } - case 84: { // todolist:todolist_9473_get_default_list - using CallHandler = ScaffoldingCallHandler>; - CallHandler::CallSync(todolist_9473_get_default_list, aGlobal, aArgs, aReturnValue, "todolist_9473_get_default_list: "_ns, aError); - return true; - } - case 85: { // todolist:todolist_9473_set_default_list - using CallHandler = ScaffoldingCallHandler, ScaffoldingObjectConverter<&kTodolistTodoListPointerType>>; - CallHandler::CallSync(todolist_9473_set_default_list, aGlobal, aArgs, aReturnValue, "todolist_9473_set_default_list: "_ns, aError); - return true; - } - case 86: { // todolist:todolist_9473_create_entry_with - using CallHandler = ScaffoldingCallHandler, ScaffoldingConverter>; - CallHandler::CallSync(todolist_9473_create_entry_with, aGlobal, aArgs, aReturnValue, "todolist_9473_create_entry_with: "_ns, aError); - return true; - } - } - return false; -} - -Maybe> UniFFIFixturesReadPointer(const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - case 0: { // rondpoint:Retourneur - type = &kRondpointRetourneurPointerType; - break; - } - case 1: { // rondpoint:Stringifier - type = &kRondpointStringifierPointerType; - break; - } - case 2: { // rondpoint:Optionneur - type = &kRondpointOptionneurPointerType; - break; - } - case 3: { // sprites:Sprite - type = &kSpritesSpritePointerType; - break; - } - case 4: { // todolist:TodoList - type = &kTodolistTodoListPointerType; - break; - } - default: - return Nothing(); - } - return Some(UniFFIPointer::Read(aArrayBuff, aPosition, type, aError)); -} - -bool UniFFIFixturesWritePointer(const GlobalObject& aGlobal, uint64_t aId, const UniFFIPointer& aPtr, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - case 0: { // rondpoint:Retourneur - type = &kRondpointRetourneurPointerType; - break; - } - case 1: { // rondpoint:Stringifier - type = &kRondpointStringifierPointerType; - break; - } - case 2: { // rondpoint:Optionneur - type = &kRondpointOptionneurPointerType; - break; - } - case 3: { // sprites:Sprite - type = &kSpritesSpritePointerType; - break; - } - case 4: { // todolist:TodoList - type = &kTodolistTodoListPointerType; - break; - } - default: - return false; - } - aPtr.Write(aArrayBuff, aPosition, type, aError); - return true; -} - -} // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp b/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp deleted file mode 100644 index ca19440a8570..000000000000 --- a/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Generated by uniffi-bindgen-gecko-js. DO NOT EDIT. - -#include "nsString.h" -#include "nsPrintfCString.h" -#include "mozilla/Maybe.h" -#include "mozilla/dom/UniFFIScaffolding.h" -#include "mozilla/dom/ScaffoldingCall.h" - -namespace mozilla::uniffi { - -using dom::ArrayBuffer; -using dom::GlobalObject; -using dom::RootedDictionary; -using dom::Promise; -using dom::ScaffoldingType; -using dom::Sequence; -using dom::UniFFIPointer; -using dom::UniFFIScaffoldingCallResult; - -// Define scaffolding functions from UniFFI -extern "C" { -} - -// Define pointer types - -Maybe> UniFFICallAsync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, ErrorResult& aError) { - switch (aId) { - } - return Nothing(); -} - -bool UniFFICallSync(const GlobalObject& aGlobal, uint64_t aId, const Sequence& aArgs, RootedDictionary& aReturnValue, ErrorResult& aError) { - switch (aId) { - } - return false; -} - -Maybe> UniFFIReadPointer(const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - default: - return Nothing(); - } - return Some(UniFFIPointer::Read(aArrayBuff, aPosition, type, aError)); -} - -bool UniFFIWritePointer(const GlobalObject& aGlobal, uint64_t aId, const UniFFIPointer& aPtr, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - default: - return false; - } - aPtr.Write(aArrayBuff, aPosition, type, aError); - return true; -} - -} // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-js/UniFFIPointer.cpp b/toolkit/components/uniffi-js/UniFFIPointer.cpp deleted file mode 100644 index 9a204aac5de8..000000000000 --- a/toolkit/components/uniffi-js/UniFFIPointer.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsPrintfCString.h" -#include "mozilla/EndianUtils.h" -#include "mozilla/dom/UniFFIPointer.h" -#include "mozilla/dom/UniFFIBinding.h" -#include "mozilla/Logging.h" -#include "UniFFIRust.h" - -static mozilla::LazyLogModule sUniFFIPointerLogger("uniffi_logger"); - -namespace mozilla::dom { -using uniffi::RUST_CALL_SUCCESS; -using uniffi::RustCallStatus; -using uniffi::UniFFIPointerType; - -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(UniFFIPointer) - -NS_IMPL_CYCLE_COLLECTING_ADDREF(UniFFIPointer) -NS_IMPL_CYCLE_COLLECTING_RELEASE(UniFFIPointer) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(UniFFIPointer) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -// Static function -already_AddRefed UniFFIPointer::Create( - void* aPtr, const UniFFIPointerType* aType) { - RefPtr uniFFIPointer = new UniFFIPointer(aPtr, aType); - return uniFFIPointer.forget(); -} - -already_AddRefed UniFFIPointer::Read( - const ArrayBuffer& aArrayBuff, uint32_t aPosition, - const UniFFIPointerType* aType, ErrorResult& aError) { - MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info, - ("[UniFFI] Reading Pointer from buffer")); - aArrayBuff.ComputeState(); - - CheckedUint32 position = aPosition; - CheckedUint32 end = position + 8; - if (!end.isValid() || end.value() > aArrayBuff.Length()) { - aError.ThrowRangeError("position is out of range"); - return nullptr; - } - // in Rust and Write(), a pointer is converted to a void* then written as u64 - // BigEndian we do the reverse here - uint8_t* data_ptr = aArrayBuff.Data() + - aPosition; // Pointer arithmetic, move by position bytes - void* ptr = (void*)mozilla::BigEndian::readUint64(data_ptr); - return UniFFIPointer::Create(ptr, aType); -} - -void UniFFIPointer::Write(const ArrayBuffer& aArrayBuff, uint32_t aPosition, - const UniFFIPointerType* aType, - ErrorResult& aError) const { - if (!this->IsSamePtrType(aType)) { - aError.ThrowUnknownError(nsPrintfCString( - "Attempt to write pointer with wrong type: %s (expected: %s)", - aType->typeName.get(), this->mType->typeName.get())); - return; - } - MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info, - ("[UniFFI] Writing Pointer to buffer")); - aArrayBuff.ComputeState(); - CheckedUint32 position = aPosition; - CheckedUint32 end = position + 8; - if (!end.isValid() || end.value() > aArrayBuff.Length()) { - aError.ThrowRangeError("position is out of range"); - return; - } - // in Rust and Read(), a u64 is read as BigEndian and then converted to a - // pointer we do the reverse here - uint8_t* data_ptr = aArrayBuff.Data() + - aPosition; // Pointer arithmetic, move by position bytes - mozilla::BigEndian::writeUint64(data_ptr, (uint64_t)GetPtr()); -} - -UniFFIPointer::UniFFIPointer(void* aPtr, const UniFFIPointerType* aType) { - mPtr = aPtr; - mType = aType; -} - -JSObject* UniFFIPointer::WrapObject(JSContext* aCx, - JS::Handle aGivenProto) { - return dom::UniFFIPointer_Binding::Wrap(aCx, this, aGivenProto); -} - -void* UniFFIPointer::GetPtr() const { - MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info, - ("[UniFFI] Getting raw pointer")); - return this->mPtr; -} - -bool UniFFIPointer::IsSamePtrType(const UniFFIPointerType* aType) const { - return this->mType == aType; -} - -UniFFIPointer::~UniFFIPointer() { - MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info, - ("[UniFFI] Destroying pointer")); - RustCallStatus status{}; - this->mType->destructor(this->mPtr, &status); - MOZ_DIAGNOSTIC_ASSERT(status.code == RUST_CALL_SUCCESS, - "UniFFI destructor call returned a non-success result"); -} - -} // namespace mozilla::dom diff --git a/toolkit/components/uniffi-js/UniFFIPointer.h b/toolkit/components/uniffi-js/UniFFIPointer.h deleted file mode 100644 index 9a824d81ede4..000000000000 --- a/toolkit/components/uniffi-js/UniFFIPointer.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_UniFFIPointer_h -#define mozilla_dom_UniFFIPointer_h - -#include "nsISupports.h" -#include "nsWrapperCache.h" -#include "nsString.h" -#include "mozilla/dom/UniFFIPointerType.h" - -namespace mozilla::dom { - -class UniFFIPointer final : public nsISupports, public nsWrapperCache { - public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(UniFFIPointer) - - static already_AddRefed Create( - void* aPtr, const uniffi::UniFFIPointerType* aType); - static already_AddRefed Read( - const ArrayBuffer& aArrayBuff, uint32_t aPosition, - const uniffi::UniFFIPointerType* aType, ErrorResult& aError); - void Write(const ArrayBuffer& aArrayBuff, uint32_t aPosition, - const uniffi::UniFFIPointerType* aType, ErrorResult& aError) const; - - UniFFIPointer(void* aPtr, const uniffi::UniFFIPointerType* aType); - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - nsISupports* GetParentObject() { return nullptr; } - - /** - * returns the raw pointer `UniFFIPointer` holds - * This is safe because: - * - The pointer was allocated in Rust as a reference counted `Arc` - * - Rust cloned the pointer without destructing it when passed into C++ - * - Eventually, when the destructor of `UniFFIPointer` runs, we return - * ownership to Rust, which then decrements the count and deallocates the - * memory the pointer points to. - */ - void* GetPtr() const; - - /** - * Returns true if the pointer type `this` holds is the same as the argument - * it does so using pointer comparison, as there is **exactly** one static - * `UniFFIPointerType` per type exposed in the UniFFI interface - */ - bool IsSamePtrType(const uniffi::UniFFIPointerType* type) const; - - private: - const uniffi::UniFFIPointerType* mType; - void* mPtr; - - protected: - /** - * Destructs the `UniFFIPointer`, making sure to give back ownership of the - * raw pointer back to Rust, which deallocates the pointer - */ - ~UniFFIPointer(); -}; -} // namespace mozilla::dom - -#endif /* mozilla_dom_UniFFIPointer_h */ diff --git a/toolkit/components/uniffi-js/UniFFIPointerType.h b/toolkit/components/uniffi-js/UniFFIPointerType.h deleted file mode 100644 index 7236e50cb79c..000000000000 --- a/toolkit/components/uniffi-js/UniFFIPointerType.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_UniFFIPointerType_h -#define mozilla_UniFFIPointerType_h - -#include "nsISupports.h" -#include "nsWrapperCache.h" -#include "nsLiteralString.h" -#include "UniFFIRust.h" - -namespace mozilla::uniffi { - -/** - * UniFFIPointerType represents of UniFFI allocated pointers. - * Each UniFFIPointer will have a UniFFIPointerType, which will be a statically - * allocated type per object exposed by the UniFFI interface - **/ -struct UniFFIPointerType { - nsLiteralCString typeName; - // The Rust destructor for the pointer, this gives back ownership to Rust - void (*destructor)(void*, RustCallStatus*); -}; -} // namespace mozilla::uniffi - -#endif /* mozilla_UniFFIPointerType_h */ diff --git a/toolkit/components/uniffi-js/UniFFIRust.h b/toolkit/components/uniffi-js/UniFFIRust.h deleted file mode 100644 index b7bffbe6bdf9..000000000000 --- a/toolkit/components/uniffi-js/UniFFIRust.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_UniFFIRust_h -#define mozilla_UniFFIRust_h - -#include - -namespace mozilla::uniffi { - -// Low-level Rust structs for UniFFI - -// RustCallStatus.code values -constexpr int8_t RUST_CALL_SUCCESS = 0; -constexpr int8_t RUST_CALL_ERROR = 1; -constexpr int8_t RUST_CALL_INTERNAL_ERROR = 2; - -// structs/functions from UniFFI -extern "C" { -struct RustBuffer { - int32_t capacity; - int32_t len; - uint8_t* data; -}; - -struct RustCallStatus { - int8_t code; - RustBuffer error_buf; -}; - -RustBuffer uniffi_rustbuffer_alloc(int32_t size, RustCallStatus* call_status); -void uniffi_rustbuffer_free(RustBuffer buf, RustCallStatus* call_status); -} - -} // namespace mozilla::uniffi - -#endif /* mozilla_UniFFIRust_h */ diff --git a/toolkit/components/uniffi-js/UniFFIScaffolding.cpp b/toolkit/components/uniffi-js/UniFFIScaffolding.cpp deleted file mode 100644 index 6be1693faf7e..000000000000 --- a/toolkit/components/uniffi-js/UniFFIScaffolding.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include -#include "nsError.h" -#include "nsString.h" -#include "nsPrintfCString.h" -#include "mozilla/Maybe.h" -#include "mozilla/dom/UniFFIScaffolding.h" - -// This file implements the UniFFI WebIDL interface by leveraging the generate -// code in UniFFIScaffolding.cpp and UniFFIFixtureScaffolding.cpp. It's main -// purpose is to check if MOZ_UNIFFI_FIXTURES is set and only try calling the -// scaffolding code if it is. - -using mozilla::dom::GlobalObject; -using mozilla::dom::Promise; -using mozilla::dom::RootedDictionary; -using mozilla::dom::ScaffoldingType; -using mozilla::dom::Sequence; -using mozilla::dom::UniFFIPointer; -using mozilla::dom::UniFFIScaffoldingCallResult; - -namespace mozilla::uniffi { - -// Prototypes for the generated functions -Maybe> UniFFICallAsync( - const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, ErrorResult& aError); -bool UniFFICallSync(const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, - RootedDictionary& aReturnValue, - ErrorResult& aError); -Maybe> UniFFIReadPointer( - const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, - long aPosition, ErrorResult& aError); -bool UniFFIWritePointer(const GlobalObject& aGlobal, uint64_t aId, - const UniFFIPointer& aPtr, - const ArrayBuffer& aArrayBuff, long aPosition, - ErrorResult& aError); - -#ifdef MOZ_UNIFFI_FIXTURES -Maybe> UniFFIFixturesCallAsync( - const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, ErrorResult& aError); -bool UniFFIFixturesCallSync( - const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, - RootedDictionary& aReturnValue, - ErrorResult& aError); -Maybe> UniFFIFixturesReadPointer( - const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, - long aPosition, ErrorResult& aError); -bool UniFFIFixturesWritePointer(const GlobalObject& aGlobal, uint64_t aId, - const UniFFIPointer& aPtr, - const ArrayBuffer& aArrayBuff, long aPosition, - ErrorResult& aError); -#endif -} // namespace mozilla::uniffi - -namespace mozilla::dom { - -// Implement the interface using the generated functions - -already_AddRefed UniFFIScaffolding::CallAsync( - const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, ErrorResult& aError) { - Maybe> firstTry = - uniffi::UniFFICallAsync(aGlobal, aId, aArgs, aError); - if (firstTry.isSome()) { - return firstTry.extract(); - } -#ifdef MOZ_UNIFFI_FIXTURES - Maybe> secondTry = - uniffi::UniFFIFixturesCallAsync(aGlobal, aId, aArgs, aError); - if (secondTry.isSome()) { - return secondTry.extract(); - } -#endif - - aError.ThrowUnknownError( - nsPrintfCString("Unknown function id: %" PRIu64, aId)); - return nullptr; -} - -void UniFFIScaffolding::CallSync( - const GlobalObject& aGlobal, uint64_t aId, - const Sequence& aArgs, - RootedDictionary& aReturnValue, - ErrorResult& aError) { - if (uniffi::UniFFICallSync(aGlobal, aId, aArgs, aReturnValue, aError)) { - return; - } -#ifdef MOZ_UNIFFI_FIXTURES - if (uniffi::UniFFIFixturesCallSync(aGlobal, aId, aArgs, aReturnValue, - aError)) { - return; - } -#endif - - aError.ThrowUnknownError( - nsPrintfCString("Unknown function id: %" PRIu64, aId)); -} - -already_AddRefed UniFFIScaffolding::ReadPointer( - const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, - long aPosition, ErrorResult& aError) { - Maybe> firstTry = - uniffi::UniFFIReadPointer(aGlobal, aId, aArrayBuff, aPosition, aError); - if (firstTry.isSome()) { - return firstTry.extract(); - } -#ifdef MOZ_UNIFFI_FIXTURES - Maybe> secondTry = - uniffi::UniFFIFixturesReadPointer(aGlobal, aId, aArrayBuff, aPosition, - aError); - if (secondTry.isSome()) { - return secondTry.extract(); - } -#endif - - aError.ThrowUnknownError(nsPrintfCString("Unknown object id: %" PRIu64, aId)); - return nullptr; -} - -void UniFFIScaffolding::WritePointer(const GlobalObject& aGlobal, uint64_t aId, - const UniFFIPointer& aPtr, - const ArrayBuffer& aArrayBuff, - long aPosition, ErrorResult& aError) { - if (uniffi::UniFFIWritePointer(aGlobal, aId, aPtr, aArrayBuff, aPosition, - aError)) { - return; - } -#ifdef MOZ_UNIFFI_FIXTURES - if (uniffi::UniFFIFixturesWritePointer(aGlobal, aId, aPtr, aArrayBuff, - aPosition, aError)) { - return; - } -#endif - - aError.ThrowUnknownError(nsPrintfCString("Unknown object id: %" PRIu64, aId)); -} - -} // namespace mozilla::dom diff --git a/toolkit/components/uniffi-js/UniFFIScaffolding.h b/toolkit/components/uniffi-js/UniFFIScaffolding.h deleted file mode 100644 index 7b0270cd77a2..000000000000 --- a/toolkit/components/uniffi-js/UniFFIScaffolding.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_UniFFI_h -#define mozilla_dom_UniFFI_h - -#include "mozilla/dom/RootedDictionary.h" -#include "mozilla/dom/UniFFIBinding.h" - -namespace mozilla::dom { - -using ScaffoldingType = OwningDoubleOrArrayBufferOrUniFFIPointer; - -// Handle functions defined in UniFFIScaffolding.webidl -class UniFFIScaffolding { - public: - static already_AddRefed CallAsync( - const GlobalObject& aUniFFIGlobal, uint64_t aId, - const Sequence& aArgs, ErrorResult& aUniFFIErrorResult); - - static void CallSync( - const GlobalObject& aUniFFIGlobal, uint64_t aId, - const Sequence& aArgs, - RootedDictionary& aUniFFIReturnValue, - ErrorResult& aUniFFIErrorResult); - - static already_AddRefed ReadPointer( - const GlobalObject& aUniFFIGlobal, uint64_t aId, - const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError); - - static void WritePointer(const GlobalObject& aUniFFIGlobal, uint64_t aId, - const UniFFIPointer& aPtr, - const ArrayBuffer& aArrayBuff, long aPosition, - ErrorResult& aError); -}; - -} // namespace mozilla::dom - -#endif /* mozilla_dom_UniFFI_h */ diff --git a/toolkit/components/uniffi-js/moz.build b/toolkit/components/uniffi-js/moz.build deleted file mode 100644 index b1311a93e424..000000000000 --- a/toolkit/components/uniffi-js/moz.build +++ /dev/null @@ -1,29 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -FINAL_LIBRARY = "xul" - -UNIFIED_SOURCES += [ - "OwnedRustBuffer.cpp", - "UniFFIGeneratedScaffolding.cpp", - "UniFFIPointer.cpp", - "UniFFIScaffolding.cpp", -] - -if CONFIG["MOZ_UNIFFI_FIXTURES"]: - UNIFIED_SOURCES += [ - "UniFFIFixtureScaffolding.cpp", - ] - -EXPORTS.mozilla.dom += [ - "OwnedRustBuffer.h", - "ScaffoldingCall.h", - "ScaffoldingConverter.h", - "UniFFIPointer.h", - "UniFFIPointerType.h", - "UniFFIRust.h", - "UniFFIScaffolding.h", -] diff --git a/toolkit/library/rust/gkrust-features.mozbuild b/toolkit/library/rust/gkrust-features.mozbuild index 393b41462b57..ed01a4717dbb 100644 --- a/toolkit/library/rust/gkrust-features.mozbuild +++ b/toolkit/library/rust/gkrust-features.mozbuild @@ -74,8 +74,6 @@ if CONFIG["MOZ_CRASHREPORTER"] and CONFIG['MOZ_OXIDIZED_BREAKPAD']: if CONFIG["MOZ_WEBMIDI_MIDIR_IMPL"]: gkrust_features += ['webmidi_midir_impl'] -if CONFIG["MOZ_UNIFFI_FIXTURES"]: - gkrust_features += ['uniffi_fixtures'] # This must remain last. gkrust_features = ["gkrust-shared/%s" % f for f in gkrust_features] diff --git a/toolkit/library/rust/shared/Cargo.toml b/toolkit/library/rust/shared/Cargo.toml index 994e545f8a58..acf761c307b8 100644 --- a/toolkit/library/rust/shared/Cargo.toml +++ b/toolkit/library/rust/shared/Cargo.toml @@ -75,11 +75,6 @@ origin-trials-ffi = { path = "../../../../dom/origin-trials/ffi" } jog = { path = "../../../components/glean/bindings/jog" } dap_ffi = { path = "../../../components/telemetry/dap/ffi" } data-encoding-ffi = { path = "../../../../dom/fs/parent/rust/data-encoding-ffi" } -uniffi-example-arithmetic = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "bb2039f077a29dba0879372a67e764e6ace8e33f", optional = true } -uniffi-example-geometry = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "bb2039f077a29dba0879372a67e764e6ace8e33f", optional = true } -uniffi-example-rondpoint = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "bb2039f077a29dba0879372a67e764e6ace8e33f", optional = true } -uniffi-example-sprites = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "bb2039f077a29dba0879372a67e764e6ace8e33f", optional = true } -uniffi-example-todolist = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "bb2039f077a29dba0879372a67e764e6ace8e33f", optional = true } # Note: `modern_sqlite` means rusqlite's bindings file be for a sqlite with # version less than or equal to what we link to. This isn't a problem because we @@ -132,10 +127,6 @@ glean_with_gecko = ["fog_control/with_gecko", "jog/with_gecko"] oxidized_breakpad = ["rust_minidump_writer_linux"] with_dbus = ["audio_thread_priority/with_dbus"] thread_sanitizer = ["xpcom/thread_sanitizer"] -uniffi_fixtures = [ - "uniffi-example-arithmetic", "uniffi-example-geometry", "uniffi-example-rondpoint", "uniffi-example-sprites", - "uniffi-example-todolist", -] webmidi_midir_impl = ["midir_impl"] [lib] diff --git a/toolkit/library/rust/shared/lib.rs b/toolkit/library/rust/shared/lib.rs index 308c92bda052..e77109188425 100644 --- a/toolkit/library/rust/shared/lib.rs +++ b/toolkit/library/rust/shared/lib.rs @@ -99,21 +99,6 @@ extern crate dap_ffi; extern crate data_encoding_ffi; -#[cfg(feature = "uniffi_fixtures")] -mod uniffi_fixtures { - extern crate arithmetical; - extern crate uniffi_geometry; - extern crate uniffi_rondpoint; - extern crate uniffi_sprites; - extern crate uniffi_todolist; - - arithmetical::uniffi_reexport_scaffolding!(); - uniffi_geometry::uniffi_reexport_scaffolding!(); - uniffi_rondpoint::uniffi_reexport_scaffolding!(); - uniffi_sprites::uniffi_reexport_scaffolding!(); - uniffi_todolist::uniffi_reexport_scaffolding!(); -} - extern crate log; use log::info; diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 5db14cc00fb8..3eda632d7020 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -3202,19 +3202,6 @@ def disable_smart_cards(build_project): set_config("MOZ_NO_SMART_CARDS", True, when=disable_smart_cards) set_define("MOZ_NO_SMART_CARDS", True, when=disable_smart_cards) -# Enable UniFFI fixtures -# ============================================================== -# These are used to test the uniffi-bindgen-gecko-js code generation. They -# should not be enabled in release builds. - -option( - "--enable-uniffi-fixtures", - help="Enable UniFFI Fixtures/Examples", -) - - -set_config("MOZ_UNIFFI_FIXTURES", True, when="--enable-uniffi-fixtures") - # Checks for library functions # ============================================================== with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")): diff --git a/tools/lint/license.yml b/tools/lint/license.yml index fdc088146e7a..2f48282c2fc1 100644 --- a/tools/lint/license.yml +++ b/tools/lint/license.yml @@ -60,8 +60,6 @@ license: - toolkit/components/reputationservice/chromium/chrome/common/safe_browsing/csd.pb.h - toolkit/mozapps/update/updater/crctable.h - tools/lint/eslint/eslint-plugin-mozilla/lib/configs - # template fragments used to generate .js sources. - - toolkit/components/uniffi-bindgen-gecko-js/src/templates/js # By design - tools/lint/test/ extensions: diff --git a/tools/rewriting/Generated.txt b/tools/rewriting/Generated.txt index 88250c4ea984..1865e4ac32c9 100644 --- a/tools/rewriting/Generated.txt +++ b/tools/rewriting/Generated.txt @@ -9,5 +9,3 @@ node_modules/ intl/components/src/UnicodeScriptCodes.h intl/unicharutil/util/nsSpecialCasingData.cpp intl/unicharutil/util/nsUnicodePropertyData.cpp -toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp -toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp