IJSObject and GeneratedJSObject #463
Unanswered
SerratedSharp
asked this question in
Q&A
Replies: 1 comment 6 replies
-
Those APIs are likely to be replaced in the medium term, depending on how the Wasm specification evolves. In general, though, interoperating this way is generally costly and we're going to be replacing parts of this with another mechanism found in Uno (TSInteropMarshaller). |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
IJSObject has this comment:
DO NOT USE - This is not intended to be implemented manually, but generated using the [GeneratedJSObject].
However when I search source I don't see anything called GeneratedJSObject.
I'm wondering why RenderingLoopAnimator is the only type I see across Uno repos that directly implements IJSObject. I'm guessing that is a special case, and based on the "don't use this" IJSObject comment that there's a different more common way that Uno uses when it wants a type to have corresponding JS/C# types. I assume [GeneratedJSObject] or some more recently renamed attribute is the more commonly used way to do this?
I see WebAssemblyRuntime.InvokeJS checks a _trace.IsEnabled field? Where do I access that to set to true, and where is the trace written? I'm guessing JS browser console?
Edit: After working through a few issues, this is the code I have currently. The calls from C# to javascript are working. I was having trouble getting the ManagedEcho method to generate from the C# object for managed calls from JS to C#, which I'd expect to generate from
JSObjectMetadataProvider.ReflectionMetadata.BuildPrototype
as a result of me calling JSObjectHandle.Create(this). The Find and Hide methods did generate.I ran this code to verify the ManagedEcho method met the criteria that the metadata generator uses, and it was listed in this output:
Code changes were definitely being reflected when I built the WASM package, but the JS proxy/prototype generated from
JSObjectMetadataProvider.ReflectionMetadata.BuildPrototype
didn't seem to reflect changes. I tried different things, completely closing the browser, Ctrl+F5 hard refresh, explicitly rebuilding the project, deleting all prior WASM packages. After those things didn't work, I kind of gave up and started adding other methods and eventually ManagedEcho appeared on the JS object. I see that there is some caching going on where it does._getByReflection.AsMemoized
instead of regenerating the proxy.When I finally got the methods to generate, attempting to call them gave "Uno is not defined" error on the JS->C# call for
Uno.Foundation.Interop.ManagedObject.dispatch(this.__managedHandle, "ManagedEcho");
I copied ManagedObject.ts from Uno.UI (I'm only useing .Boostrap), commented out
private static assembly: UI.Interop.IMonoAssemblyHandle;
and added the definition for Module from emscripten. Then the managed calls succeeded.JQueryBox.cs
Beta Was this translation helpful? Give feedback.
All reactions