mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.69k stars 221 forks source link

Gecko-js: Don't expose raw pointers to JS using the `setPrivate()` API #1264

Closed bendk closed 2 years ago

bendk commented 2 years ago

Replace this:

Promise<UniFFIRustCallResult> todolist126TodoListAddItem(any ptr, ArrayBuffer todo);

With something like this:

enum UniFFIPtrType { "todo-list", "coveralls", ... };
interface UniFFIPtr {
  readonly attribute UniFFIPtrType type;
  // Will store a `void *` corresponding to the Rust Arc<> in the C++ class
};

// This function will check that `ptr` has `type = TodoList` and will get the `void *` from the C++ class to pass to Rust.
Promise<UniFFIRustCallResult> todolist126TodoListAddItem(UniFFIPtr ptr, ArrayBuffer todo);

Pros:

Cons:

Related: Replace how we read ArrayBuffer data to avoid handling the pointer data in JS

┆Issue is synchronized with this Jira Task ┆epic: Rust Components on Desktop ┆friendlyId: UNIFFI-172 ┆sprintEndDate: 2022-06-10

data-sync-user commented 2 years ago

➤ Tarik Eshaq commented:

PR: https://mozilla-hub.atlassian.net/browse/UNIFFI-172 ( https://mozilla-hub.atlassian.net/browse/UNIFFI-172|smart-link )