@@ -35,10 +35,9 @@ public static class DotNetDispatcher
3535 /// </summary>
3636 /// <param name="jsRuntime">The <see cref="JSRuntime"/>.</param>
3737 /// <param name="invocationInfo">The <see cref="DotNetInvocationInfo"/>.</param>
38- /// <param name="argsJson">A JSON representation of the parameters.</param>
39- /// <param name="byteArrays">Byte array data extracted from the arguments for direct transfer.</param>
38+ /// <param name="serializedArgs">The serialized args containing the JSON representation along with the extracted byte arrays.</param>
4039 /// <returns>A record containing the JSON representation of the return value, or null, along with the extracted byte arrays, or null.</returns>
41- public static SerializedArgs Invoke ( JSRuntime jsRuntime , in DotNetInvocationInfo invocationInfo , string argsJson , byte [ ] [ ] ? byteArrays )
40+ public static SerializedArgs Invoke ( JSRuntime jsRuntime , in DotNetInvocationInfo invocationInfo , SerializedArgs serializedArgs )
4241 {
4342 // This method doesn't need [JSInvokable] because the platform is responsible for having
4443 // some way to dispatch calls here. The logic inside here is the thing that checks whether
@@ -51,7 +50,7 @@ public static SerializedArgs Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo
5150 targetInstance = jsRuntime . GetObjectReference ( invocationInfo . DotNetObjectId ) ;
5251 }
5352
54- var syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , argsJson , byteArrays ) ;
53+ var syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , serializedArgs ) ;
5554 if ( syncResult == null )
5655 {
5756 return new SerializedArgs ( null , null ) ;
@@ -65,9 +64,8 @@ public static SerializedArgs Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo
6564 /// </summary>
6665 /// <param name="jsRuntime">The <see cref="JSRuntime"/>.</param>
6766 /// <param name="invocationInfo">The <see cref="DotNetInvocationInfo"/>.</param>
68- /// <param name="argsJson">A JSON representation of the parameters.</param>
69- /// <param name="byteArrays">Byte array data extracted from the arguments for direct transfer.</param>
70- public static void BeginInvokeDotNet ( JSRuntime jsRuntime , DotNetInvocationInfo invocationInfo , string argsJson , byte [ ] [ ] ? byteArrays )
67+ /// <param name="serializedArgs">The serialized args containing the JSON representation along with the extracted byte arrays.</param>
68+ public static void BeginInvokeDotNet ( JSRuntime jsRuntime , DotNetInvocationInfo invocationInfo , SerializedArgs serializedArgs )
7169 {
7270 // This method doesn't need [JSInvokable] because the platform is responsible for having
7371 // some way to dispatch calls here. The logic inside here is the thing that checks whether
@@ -89,7 +87,7 @@ public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo i
8987 targetInstance = jsRuntime . GetObjectReference ( invocationInfo . DotNetObjectId ) ;
9088 }
9189
92- syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , argsJson , byteArrays ) ;
90+ syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , serializedArgs ) ;
9391 }
9492 catch ( Exception ex )
9593 {
@@ -114,9 +112,8 @@ public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo i
114112 }
115113 else
116114 {
117-
118- var serializedArgs = SerializeArgs ( jsRuntime , syncResult ) ;
119- var dispatchResult = new DotNetInvocationResult ( serializedArgs ) ;
115+ var serializedReturnArgs = SerializeArgs ( jsRuntime , syncResult ) ;
116+ var dispatchResult = new DotNetInvocationResult ( serializedReturnArgs ) ;
120117 jsRuntime . EndInvokeDotNet ( invocationInfo , dispatchResult ) ;
121118 }
122119 }
@@ -135,7 +132,7 @@ private static void EndInvokeDotNetAfterTask(Task task, JSRuntime jsRuntime, in
135132 jsRuntime . EndInvokeDotNet ( invocationInfo , new DotNetInvocationResult ( serializedArgs ) ) ;
136133 }
137134
138- private static object ? InvokeSynchronously ( JSRuntime jsRuntime , in DotNetInvocationInfo callInfo , IDotNetObjectReference ? objectReference , string argsJson , byte [ ] [ ] ? byteArrays )
135+ private static object ? InvokeSynchronously ( JSRuntime jsRuntime , in DotNetInvocationInfo callInfo , IDotNetObjectReference ? objectReference , SerializedArgs serializedArgs )
139136 {
140137 var assemblyName = callInfo . AssemblyName ;
141138 var methodIdentifier = callInfo . MethodIdentifier ;
@@ -165,7 +162,7 @@ private static void EndInvokeDotNetAfterTask(Task task, JSRuntime jsRuntime, in
165162 ( methodInfo , parameterTypes ) = GetCachedMethodInfo ( objectReference , methodIdentifier ) ;
166163 }
167164
168- var suppliedArgs = ParseArguments ( jsRuntime , methodIdentifier , argsJson , byteArrays , parameterTypes ) ;
165+ var suppliedArgs = ParseArguments ( jsRuntime , methodIdentifier , serializedArgs , parameterTypes ) ;
169166
170167 try
171168 {
@@ -184,14 +181,14 @@ private static void EndInvokeDotNetAfterTask(Task task, JSRuntime jsRuntime, in
184181 }
185182 }
186183
187- internal static object ? [ ] ParseArguments ( JSRuntime jsRuntime , string methodIdentifier , string arguments , byte [ ] [ ] ? byteArrays , Type [ ] parameterTypes )
184+ internal static object ? [ ] ParseArguments ( JSRuntime jsRuntime , string methodIdentifier , SerializedArgs serializedArgs , Type [ ] parameterTypes )
188185 {
189186 if ( parameterTypes . Length == 0 )
190187 {
191188 return Array . Empty < object > ( ) ;
192189 }
193190
194- var utf8JsonBytes = Encoding . UTF8 . GetBytes ( arguments ) ;
191+ var utf8JsonBytes = Encoding . UTF8 . GetBytes ( serializedArgs . ArgsJson ?? string . Empty ) ;
195192 var reader = new Utf8JsonReader ( utf8JsonBytes ) ;
196193 if ( ! reader . Read ( ) || reader . TokenType != JsonTokenType . StartArray )
197194 {
@@ -200,7 +197,7 @@ private static void EndInvokeDotNetAfterTask(Task task, JSRuntime jsRuntime, in
200197
201198 var suppliedArgs = new object ? [ parameterTypes . Length ] ;
202199
203- jsRuntime . ByteArrayJsonConverter . ByteArraysToDeserialize = byteArrays ;
200+ jsRuntime . ByteArrayJsonConverter . ByteArraysToDeserialize = serializedArgs . ByteArrays ;
204201
205202 var index = 0 ;
206203 while ( index < parameterTypes . Length && reader . Read ( ) && reader . TokenType != JsonTokenType . EndArray )
@@ -263,15 +260,14 @@ static bool IsIncorrectDotNetObjectRefUse(Type parameterType, Utf8JsonReader jso
263260 /// passed in as parameters.
264261 /// </remarks>
265262 /// <param name="jsRuntime">The <see cref="JSRuntime"/>.</param>
266- /// <param name="arguments">The serialized arguments for the callback completion.</param>
267- /// <param name="byteArrays">Byte array data extracted from the arguments for direct transfer.</param>
263+ /// <param name="serializedArgs">The serialized args containing the JSON representation along with the extracted byte arrays.</param>
268264 /// <exception cref="Exception">
269265 /// This method can throw any exception either from the argument received or as a result
270266 /// of executing any callback synchronously upon completion.
271267 /// </exception>
272- public static void EndInvokeJS ( JSRuntime jsRuntime , string arguments , byte [ ] [ ] ? byteArrays )
268+ public static void EndInvokeJS ( JSRuntime jsRuntime , SerializedArgs serializedArgs )
273269 {
274- var utf8JsonBytes = Encoding . UTF8 . GetBytes ( arguments ) ;
270+ var utf8JsonBytes = Encoding . UTF8 . GetBytes ( serializedArgs . ArgsJson ?? string . Empty ) ;
275271
276272 // The payload that we're trying to parse is of the format
277273 // [ taskId: long, success: boolean, value: string? | object ]
@@ -292,7 +288,7 @@ public static void EndInvokeJS(JSRuntime jsRuntime, string arguments, byte[][]?
292288 var success = reader . GetBoolean ( ) ;
293289
294290 reader . Read ( ) ;
295- jsRuntime . EndInvokeJS ( taskId , success , ref reader , byteArrays ) ;
291+ jsRuntime . EndInvokeJS ( taskId , success , ref reader , serializedArgs . ByteArrays ) ;
296292
297293 if ( ! reader . Read ( ) || reader . TokenType != JsonTokenType . EndArray )
298294 {
0 commit comments