[JSExport] Attribute With Complex Type Parameters #112182
-
Hi everyone! My team and I are working on a solution that will allow us to use a common codebase for the backend and frontend to ensure consistency in some of our computations. We tried using the [JSExport] attribute with WASM assembly, but we are running into some difficulties. The main question is how to pass and return classes/records/structs? Our first option was JSON or Binary serialization. But we'll have to add a (de)serialization code for every call. And I don't know if we can simplify it using some kind of middleware. Additionally, in our scenarios we may call methods really frequently and I wouldn't like to add overhead to the existing interop, but I think it's not a really big issue if we solve the problem with the boilerplate code. As an alternative, we were trying to use JSObject directly. In this case it works perfectly on the frontend side. Looks like a simple call of JS function. But there are issues on the backend. Firstly, we can't return a similar JSObject, only ManagedObject. And we didn't find a way to obtain any properties from this object on the JS side. Secondly, not all properties can be obtained from a JSObject on the c# side. We can't get arrays from this object. We tried to use a hack like this, but it doesn't work for boolean arrays: [JSImport("INTERNAL.get_property")]
public static partial int[] GetPropertyAsInt32Array(JSObject self, string propertyName); I hope you can help me understand some points. Or probably provide an even better solution. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
We don't support that and we probably would not do it any time soon. If you need more perf, there is similar discussion dotnet/aspnetcore#54946 (comment) with pointers to solutions and tricks others use. And few related feature requests |
Beta Was this translation helpful? Give feedback.
We don't support that and we probably would not do it any time soon.
Marshaling structures by value leads to serialization similar to what JSON does.
If you need more perf, there is similar discussion dotnet/aspnetcore#54946 (comment) with pointers to solutions and tricks others use.
And few related feature requests
#77784
#78905
#78906
#78455