From 753f368aba7d452abaa3a46aec7514cf93252139 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:11:39 -0400 Subject: [PATCH] perf: Add JSObject.Dispatch() export --- .../Interop/JSObject.wasm.cs | 9 ++++++++- .../Uno.Foundation.Runtime.WebAssembly.csproj | 1 + src/Uno.UI/ts/ExportManager.ts | 8 +++++++- src/Uno.UI/ts/Interop/ManagedObject.ts | 8 +++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs index 1bfd7f23a4..9c55fa3df5 100644 --- a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs +++ b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs @@ -5,14 +5,21 @@ using System.Reflection; using System.Runtime.InteropServices; // using Uno.Logging; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.JavaScript; +#endif + namespace Uno.Foundation.Interop { [Obfuscation(Feature = "renaming", Exclude = true)] - public sealed class JSObject + public sealed partial class JSObject { /// /// Used by javascript to dispatch a method call to the managed object at . /// +#if NET7_0_OR_GREATER + [JSExport] +#endif [Obfuscation(Feature = "renaming", Exclude = true)] public static void Dispatch(IntPtr handlePtr, string method, string parameters) { diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj b/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj index 423a325e90..4eb88facad 100644 --- a/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj +++ b/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj @@ -11,6 +11,7 @@ $(NoWarn);NU1701 + true $(DefineConstants);IS_UNO_FOUNDATION_RUNTIME_WEBASSEMBLY_PROJECT false diff --git a/src/Uno.UI/ts/ExportManager.ts b/src/Uno.UI/ts/ExportManager.ts index bb4e9436df..8fa02cf857 100644 --- a/src/Uno.UI/ts/ExportManager.ts +++ b/src/Uno.UI/ts/ExportManager.ts @@ -9,7 +9,13 @@ namespace Uno.UI { const unoExports = await (Module).getAssemblyExports("Uno"); const unoUIExports = await (Module).getAssemblyExports("Uno.UI"); - (globalThis).DotnetExports = { Uno: unoExports, UnoUI: unoUIExports }; + const runtimeWasmExports = await (Module).getAssemblyExports("Uno.Foundation.Runtime.WebAssembly"); + + (globalThis).DotnetExports = { + Uno: unoExports, + UnoUI: unoUIExports, + UnoFoundationRuntimeWebAssembly: runtimeWasmExports + }; } } } diff --git a/src/Uno.UI/ts/Interop/ManagedObject.ts b/src/Uno.UI/ts/Interop/ManagedObject.ts index 51ac284629..7493a31637 100644 --- a/src/Uno.UI/ts/Interop/ManagedObject.ts +++ b/src/Uno.UI/ts/Interop/ManagedObject.ts @@ -4,7 +4,13 @@ private static dispatchMethod: (handle: number, method: string, parameters: string) => number; private static init() { - ManagedObject.dispatchMethod = (Module).mono_bind_static_method("[Uno.Foundation.Runtime.WebAssembly] Uno.Foundation.Interop.JSObject:Dispatch"); + const exports = (globalThis).DotnetExports?.UnoFoundationRuntimeWebAssembly?.Uno?.Foundation?.Interop?.JSObject; + + if (exports !== undefined) { + ManagedObject.dispatchMethod = exports.Dispatch; + } else { + ManagedObject.dispatchMethod = (Module).mono_bind_static_method("[Uno.Foundation.Runtime.WebAssembly] Uno.Foundation.Interop.JSObject:Dispatch"); + } } public static dispatch(handle: number, method: string, parameters: string): void { -- GitLab