Fuse Community

JS Objects as Arguments to NativeFunctions

Hello, I have started using Uno.Wasm.Bootstrap to generate WASM in order to run C# client side. I.e. I’m not using the full Uno UI platform.

I was looking at the Fuse Native JS Modules examples: Creating native JavaScript Modules in Uno - Fuse Documentation

In the example the SendMessage function receives the message in the object[] array and is cast to a string.

What if I want to be able to pass a more complex javascript object as an argument? I.e. a javascript object that has properties and methods.

Is it possible to do something like this so that I can have a handle to a JS object and interact with it?

object[] SendMessage(Fuse.Scripting.Context context, object[] args)
    {
        var jsObject = args.First() as Fuse.Scripting.Object;
        jsObject.CallMethod("someJsIObjectMethod", 123);
    }

I think it can be done, take a look at this source code for reference:

and: