Skip to content

Commit 1d8495c

Browse files
committed
Remove JSInvocationInfo from interop bridge communication
1 parent 28c8d39 commit 1d8495c

File tree

22 files changed

+329
-469
lines changed

22 files changed

+329
-469
lines changed

src/Components/Server/src/Circuits/RemoteJSRuntime.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected override void BeginInvokeJS(long asyncHandle, string identifier, strin
119119
BeginInvokeJS(invocationInfo);
120120
}
121121

122-
protected override void BeginInvokeJS(JSInvocationInfo invocationInfo)
122+
protected override void BeginInvokeJS(in JSInvocationInfo invocationInfo)
123123
{
124124
if (_clientProxy is null)
125125
{
@@ -138,11 +138,16 @@ protected override void BeginInvokeJS(JSInvocationInfo invocationInfo)
138138
}
139139
}
140140

141-
var invocationInfoJson = invocationInfo.ToJson();
142-
143141
Log.BeginInvokeJS(_logger, invocationInfo.AsyncHandle, invocationInfo.Identifier);
144142

145-
_clientProxy.SendAsync("JS.BeginInvokeJS", invocationInfoJson);
143+
_clientProxy.SendAsync(
144+
"JS.BeginInvokeJS",
145+
invocationInfo.AsyncHandle,
146+
invocationInfo.Identifier,
147+
invocationInfo.ArgsJson,
148+
(int)invocationInfo.ResultType,
149+
invocationInfo.TargetInstanceId,
150+
(int)invocationInfo.CallType);
146151
}
147152

148153
protected override void ReceiveByteArray(int id, byte[] data)

src/Components/Web.JS/src/Boot.WebAssembly.Common.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,12 @@ async function scheduleAfterStarted(operations: string): Promise<void> {
264264
Blazor._internal.updateRootComponents(operations);
265265
}
266266

267-
function invokeJSJson(invocationInfoJson: string): string | null {
268-
const invocationInfo: DotNet.JSInvocationInfo = JSON.parse(invocationInfoJson);
269-
if (invocationInfo.asyncHandle !== 0) {
270-
dispatcher.beginInvokeJSFromDotNet(invocationInfo);
267+
function invokeJSJson(identifier: string, targetInstanceId: number, resultType: number, argsJson: string, asyncHandle: number, callType: number): string | null {
268+
if (asyncHandle !== 0) {
269+
dispatcher.beginInvokeJSFromDotNet(asyncHandle, identifier, argsJson, resultType, targetInstanceId, callType);
271270
return null;
272271
} else {
273-
return dispatcher.invokeJSFromDotNet(invocationInfo);
272+
return dispatcher.invokeJSFromDotNet(identifier, argsJson, resultType, targetInstanceId, callType);
274273
}
275274
}
276275

src/Components/Web.JS/src/GlobalExports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface IBlazor {
5252
forceCloseConnection?: () => Promise<void>;
5353
InputFile?: typeof InputFile;
5454
NavigationLock: typeof NavigationLock;
55-
invokeJSJson?: (invocationInfoString: string) => string | null;
55+
invokeJSJson?: (identifier: string, targetInstanceId: number, resultType: number, argsJson: string, asyncHandle: number, callType: number) => string | null;
5656
endInvokeDotNetFromJS?: (callId: string, success: boolean, resultJsonOrErrorMessage: string) => void;
5757
receiveByteArray?: (id: number, data: Uint8Array) => void;
5858
getPersistedState?: () => string;

src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class CircuitManager implements DotNet.DotNetCallDispatcher {
127127
const connection = connectionBuilder.build();
128128

129129
connection.on('JS.AttachComponent', (componentId, selector) => attachRootComponentToLogicalElement(WebRendererId.Server, this.resolveElement(selector), componentId, false));
130-
connection.on('JS.BeginInvokeJS', (invocationInfoJson: string) => this.beginInvokeJSJson(invocationInfoJson));
130+
connection.on('JS.BeginInvokeJS', this._dispatcher.beginInvokeJSFromDotNet.bind(this._dispatcher));
131131
connection.on('JS.EndInvokeDotNet', this._dispatcher.endInvokeDotNetFromJS.bind(this._dispatcher));
132132
connection.on('JS.ReceiveByteArray', this._dispatcher.receiveByteArray.bind(this._dispatcher));
133133

@@ -232,11 +232,6 @@ export class CircuitManager implements DotNet.DotNetCallDispatcher {
232232
return true;
233233
}
234234

235-
private beginInvokeJSJson(invocationInfoJson: string) {
236-
const invocationInfo: DotNet.JSInvocationInfo = JSON.parse(invocationInfoJson);
237-
this._dispatcher.beginInvokeJSFromDotNet(invocationInfo);
238-
}
239-
240235
// Implements DotNet.DotNetCallDispatcher
241236
public beginInvokeDotNetFromJS(callId: number, assemblyName: string | null, methodIdentifier: string, dotNetObjectId: number | null, argsJson: string): void {
242237
this.throwIfDispatchingWhenDisposed();

src/Components/Web.JS/src/Platform/WebView/WebViewIpcReceiver.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function startIpcReceiver(): void {
3333
showErrorNotification();
3434
},
3535

36-
'BeginInvokeJS': beginInvokeJSJson,
36+
'BeginInvokeJS': dispatcher.beginInvokeJSFromDotNet.bind(dispatcher),
3737

3838
'EndInvokeDotNet': dispatcher.endInvokeDotNetFromJS.bind(dispatcher),
3939

@@ -81,7 +81,3 @@ function base64ToArrayBuffer(base64: string): Uint8Array {
8181
return result;
8282
}
8383

84-
function beginInvokeJSJson(invocationInfoJson: string) {
85-
const invocationInfo = JSON.parse(invocationInfoJson);
86-
dispatcher.beginInvokeJSFromDotNet(invocationInfo);
87-
}

src/Components/Web/src/Internal/IInternalWebJSInProcessRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ public interface IInternalWebJSInProcessRuntime
2222
/// <summary>
2323
/// For internal framework use only.
2424
/// </summary>
25-
string InvokeJS(JSInvocationInfo invocationInfo);
25+
string InvokeJS(in JSInvocationInfo invocationInfo);
2626
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#nullable enable
2-
Microsoft.AspNetCore.Components.Web.Internal.IInternalWebJSInProcessRuntime.InvokeJS(Microsoft.JSInterop.Infrastructure.JSInvocationInfo! invocationInfo) -> string!
2+
Microsoft.AspNetCore.Components.Web.Internal.IInternalWebJSInProcessRuntime.InvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> string!
33
virtual Microsoft.AspNetCore.Components.Routing.NavLink.ShouldMatch(string! uriAbsolute) -> bool

src/Components/Web/src/WebRenderer.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Extensions.DependencyInjection;
1111
using Microsoft.Extensions.Logging;
1212
using Microsoft.JSInterop;
13-
using Microsoft.JSInterop.Infrastructure;
1413
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1514

1615
namespace Microsoft.AspNetCore.Components.RenderTree;
@@ -131,16 +130,7 @@ private void AttachWebRendererInterop(IJSRuntime jsRuntime, JsonSerializerOption
131130
newJsonOptions.TypeInfoResolverChain.Add(WebRendererSerializerContext.Default);
132131
newJsonOptions.TypeInfoResolverChain.Add(JsonConverterFactoryTypeInfoResolver<DotNetObjectReference<WebRendererInteropMethods>>.Instance);
133132
var argsJson = JsonSerializer.Serialize(args, newJsonOptions);
134-
var invocationInfo = new JSInvocationInfo
135-
{
136-
AsyncHandle = 0,
137-
TargetInstanceId = 0,
138-
Identifier = JSMethodIdentifier,
139-
CallType = JSCallType.FunctionCall,
140-
ResultType = JSCallResultType.JSVoidResult,
141-
ArgsJson = argsJson,
142-
};
143-
inProcessRuntime.InvokeJS(invocationInfo);
133+
inProcessRuntime.InvokeJS(JSMethodIdentifier, argsJson, JSCallResultType.JSVoidResult, 0);
144134
}
145135
else
146136
{

src/Components/WebAssembly/JSInterop/src/InternalCalls.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ internal static partial class InternalCalls
1818
public static extern TRes InvokeJS<T0, T1, T2, TRes>(out string exception, ref JSCallInfo callInfo, [AllowNull] T0 arg0, [AllowNull] T1 arg1, [AllowNull] T2 arg2);
1919

2020
[JSImport("Blazor._internal.invokeJSJson", "blazor-internal")]
21-
public static partial string InvokeJSJson(string invocationInfoString);
21+
public static partial string InvokeJSJson(
22+
string identifier,
23+
[JSMarshalAs<JSType.Number>] long targetInstanceId,
24+
int resultType,
25+
string argsJson,
26+
[JSMarshalAs<JSType.Number>] long asyncHandle,
27+
int callType);
2228

2329
[JSImport("Blazor._internal.endInvokeDotNetFromJS", "blazor-internal")]
2430
public static partial void EndInvokeDotNetFromJS(
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#nullable enable
2-
override Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.BeginInvokeJS(long taskId, string! identifier, string? argsJson, Microsoft.JSInterop.JSCallResultType resultType, long targetInstanceId) -> void
3-
override Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.BeginInvokeJS(Microsoft.JSInterop.Infrastructure.JSInvocationInfo! invocationInfo) -> void
4-
override Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeJS(Microsoft.JSInterop.Infrastructure.JSInvocationInfo! invocationInfo) -> string!
2+
override Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.BeginInvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> void
3+
override Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> string!

0 commit comments

Comments
 (0)