@@ -28,25 +28,23 @@ public static class DotNetDispatcher
28
28
/// Receives a call from JS to .NET, locating and invoking the specified method.
29
29
/// </summary>
30
30
/// <param name="jsRuntime">The <see cref="JSRuntime"/>.</param>
31
- /// <param name="assemblyName">The assembly containing the method to be invoked.</param>
32
- /// <param name="methodIdentifier">The identifier of the method to be invoked. The method must be annotated with a <see cref="JSInvokableAttribute"/> matching this identifier string.</param>
33
- /// <param name="dotNetObjectId">For instance method calls, identifies the target object.</param>
31
+ /// <param name="invocationInfo">The <see cref="DotNetInvocationInfo"/>.</param>
34
32
/// <param name="argsJson">A JSON representation of the parameters.</param>
35
33
/// <returns>A JSON representation of the return value, or null.</returns>
36
- public static string Invoke ( JSRuntime jsRuntime , string assemblyName , string methodIdentifier , long dotNetObjectId , string argsJson )
34
+ public static string Invoke ( JSRuntime jsRuntime , in DotNetInvocationInfo invocationInfo , string argsJson )
37
35
{
38
36
// This method doesn't need [JSInvokable] because the platform is responsible for having
39
37
// some way to dispatch calls here. The logic inside here is the thing that checks whether
40
38
// the targeted method has [JSInvokable]. It is not itself subject to that restriction,
41
39
// because there would be nobody to police that. This method *is* the police.
42
40
43
41
IDotNetObjectReference targetInstance = default ;
44
- if ( dotNetObjectId != default )
42
+ if ( invocationInfo . DotNetObjectId != default )
45
43
{
46
- targetInstance = jsRuntime . GetObjectReference ( dotNetObjectId ) ;
44
+ targetInstance = jsRuntime . GetObjectReference ( invocationInfo . DotNetObjectId ) ;
47
45
}
48
46
49
- var syncResult = InvokeSynchronously ( jsRuntime , assemblyName , methodIdentifier , targetInstance , argsJson ) ;
47
+ var syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , argsJson ) ;
50
48
if ( syncResult == null )
51
49
{
52
50
return null ;
@@ -59,13 +57,10 @@ public static string Invoke(JSRuntime jsRuntime, string assemblyName, string met
59
57
/// Receives a call from JS to .NET, locating and invoking the specified method asynchronously.
60
58
/// </summary>
61
59
/// <param name="jsRuntime">The <see cref="JSRuntime"/>.</param>
62
- /// <param name="callId">A value identifying the asynchronous call that should be passed back with the result, or null if no result notification is required.</param>
63
- /// <param name="assemblyName">The assembly containing the method to be invoked.</param>
64
- /// <param name="methodIdentifier">The identifier of the method to be invoked. The method must be annotated with a <see cref="JSInvokableAttribute"/> matching this identifier string.</param>
65
- /// <param name="dotNetObjectId">For instance method calls, identifies the target object.</param>
60
+ /// <param name="invocationInfo">The <see cref="DotNetInvocationInfo"/>.</param>
66
61
/// <param name="argsJson">A JSON representation of the parameters.</param>
67
62
/// <returns>A JSON representation of the return value, or null.</returns>
68
- public static void BeginInvokeDotNet ( JSRuntime jsRuntime , string callId , string assemblyName , string methodIdentifier , long dotNetObjectId , string argsJson )
63
+ public static void BeginInvokeDotNet ( JSRuntime jsRuntime , DotNetInvocationInfo invocationInfo , string argsJson )
69
64
{
70
65
// This method doesn't need [JSInvokable] because the platform is responsible for having
71
66
// some way to dispatch calls here. The logic inside here is the thing that checks whether
@@ -75,18 +70,19 @@ public static void BeginInvokeDotNet(JSRuntime jsRuntime, string callId, string
75
70
// Using ExceptionDispatchInfo here throughout because we want to always preserve
76
71
// original stack traces.
77
72
73
+ var callId = invocationInfo . CallId ;
74
+
78
75
object syncResult = null ;
79
76
ExceptionDispatchInfo syncException = null ;
80
77
IDotNetObjectReference targetInstance = null ;
81
-
82
78
try
83
79
{
84
- if ( dotNetObjectId != default )
80
+ if ( invocationInfo . DotNetObjectId != default )
85
81
{
86
- targetInstance = jsRuntime . GetObjectReference ( dotNetObjectId ) ;
82
+ targetInstance = jsRuntime . GetObjectReference ( invocationInfo . DotNetObjectId ) ;
87
83
}
88
84
89
- syncResult = InvokeSynchronously ( jsRuntime , assemblyName , methodIdentifier , targetInstance , argsJson ) ;
85
+ syncResult = InvokeSynchronously ( jsRuntime , invocationInfo , targetInstance , argsJson ) ;
90
86
}
91
87
catch ( Exception ex )
92
88
{
@@ -101,7 +97,7 @@ public static void BeginInvokeDotNet(JSRuntime jsRuntime, string callId, string
101
97
else if ( syncException != null )
102
98
{
103
99
// Threw synchronously, let's respond.
104
- jsRuntime . EndInvokeDotNet ( callId , false , syncException , assemblyName , methodIdentifier , dotNetObjectId ) ;
100
+ jsRuntime . EndInvokeDotNet ( invocationInfo , new DotNetInvocationResult ( syncException . SourceException , "InvocationFailure" ) ) ;
105
101
}
106
102
else if ( syncResult is Task task )
107
103
{
@@ -111,23 +107,27 @@ public static void BeginInvokeDotNet(JSRuntime jsRuntime, string callId, string
111
107
{
112
108
if ( t . Exception != null )
113
109
{
114
- var exception = t . Exception . GetBaseException ( ) ;
115
-
116
- jsRuntime . EndInvokeDotNet ( callId , false , ExceptionDispatchInfo . Capture ( exception ) , assemblyName , methodIdentifier , dotNetObjectId ) ;
110
+ var exceptionDispatchInfo = ExceptionDispatchInfo . Capture ( t . Exception . GetBaseException ( ) ) ;
111
+ var dispatchResult = new DotNetInvocationResult ( exceptionDispatchInfo . SourceException , "InvocationFailure" ) ;
112
+ jsRuntime . EndInvokeDotNet ( invocationInfo , dispatchResult ) ;
117
113
}
118
114
119
115
var result = TaskGenericsUtil . GetTaskResult ( task ) ;
120
- jsRuntime . EndInvokeDotNet ( callId , true , result , assemblyName , methodIdentifier , dotNetObjectId ) ;
116
+ jsRuntime . EndInvokeDotNet ( invocationInfo , new DotNetInvocationResult ( result ) ) ;
121
117
} , TaskScheduler . Current ) ;
122
118
}
123
119
else
124
120
{
125
- jsRuntime . EndInvokeDotNet ( callId , true , syncResult , assemblyName , methodIdentifier , dotNetObjectId ) ;
121
+ var dispatchResult = new DotNetInvocationResult ( syncResult ) ;
122
+ jsRuntime . EndInvokeDotNet ( invocationInfo , dispatchResult ) ;
126
123
}
127
124
}
128
125
129
- private static object InvokeSynchronously ( JSRuntime jsRuntime , string assemblyName , string methodIdentifier , IDotNetObjectReference objectReference , string argsJson )
126
+ private static object InvokeSynchronously ( JSRuntime jsRuntime , in DotNetInvocationInfo callInfo , IDotNetObjectReference objectReference , string argsJson )
130
127
{
128
+ var assemblyName = callInfo . AssemblyName ;
129
+ var methodIdentifier = callInfo . MethodIdentifier ;
130
+
131
131
AssemblyKey assemblyKey ;
132
132
if ( objectReference is null )
133
133
{
0 commit comments