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:
No chance of JS code misusing the pointer (modifying the value, not properly freeing, etc)
Avoids round-tripping the pointer value through JS as double value
Simplified freeing. We can call the UniFFI free function in the C++ destructor and not have to manually free. Alternatively, we can implement a free method in C++ and have it null out the pointer to avoid use-after-free bugs.
Type safety. We can check that the pointer is the proper type for the function/method call.
Cons:
Need to enumerate all the pointer types, this means that there will need to be some process that reads all the UDL files and generates a WebIDL file from that. We're probably going to need to do this for other reasons anyways, so let's discuss this in another thread.
Some memory and CPU required to store the type value, but this is probably negligible.
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
Replace this:
With something like this:
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