Skip to content

Commit c3fb958

Browse files
authored
Add default implementations for new interface methods in Blazor JS interop (#61850)
1 parent c7415ff commit c3fb958

File tree

8 files changed

+52
-25
lines changed

8 files changed

+52
-25
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public interface IInternalWebJSInProcessRuntime
2222
/// <summary>
2323
/// For internal framework use only.
2424
/// </summary>
25-
string InvokeJS(in JSInvocationInfo invocationInfo);
25+
string InvokeJS(in JSInvocationInfo invocationInfo)
26+
=> throw new NotImplementedException();
2627
}

src/JSInterop/Microsoft.JSInterop/src/IJSInProcessObjectReference.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public interface IJSInProcessObjectReference : IJSObjectReference, IDisposable
2828
/// <param name="args">JSON-serializable arguments.</param>
2929
/// <returns>An <see cref="IJSInProcessObjectReference"/> instance that represents the created JS object.</returns>
3030
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
31-
IJSInProcessObjectReference InvokeNew(string identifier, object?[]? args);
31+
IJSInProcessObjectReference InvokeNew(string identifier, object?[]? args)
32+
=> throw new NotImplementedException();
3233

3334
/// <summary>
3435
/// Reads the value of the specified JavaScript property synchronously.
@@ -37,7 +38,8 @@ public interface IJSInProcessObjectReference : IJSObjectReference, IDisposable
3738
/// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>window.someScope.someProp</c>.</param>
3839
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
3940
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
40-
TValue GetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier);
41+
TValue GetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier)
42+
=> throw new NotImplementedException();
4143

4244
/// <summary>
4345
/// Updates the value of the specified JavaScript property synchronously. If the property is not defined on the target object, it will be created.
@@ -46,5 +48,6 @@ public interface IJSInProcessObjectReference : IJSObjectReference, IDisposable
4648
/// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>window.someScope.someProp</c>.</param>
4749
/// <param name="value">JSON-serializable value.</param>
4850
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
49-
void SetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value);
51+
void SetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value)
52+
=> throw new NotImplementedException();
5053
}

src/JSInterop/Microsoft.JSInterop/src/IJSInProcessRuntime.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public interface IJSInProcessRuntime : IJSRuntime
2828
/// <param name="args">JSON-serializable arguments.</param>
2929
/// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns>
3030
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
31-
IJSInProcessObjectReference InvokeNew(string identifier, params object?[]? args);
31+
IJSInProcessObjectReference InvokeNew(string identifier, params object?[]? args)
32+
=> throw new NotImplementedException();
3233

3334
/// <summary>
3435
/// Reads the value of the specified JavaScript property synchronously.
@@ -37,7 +38,8 @@ public interface IJSInProcessRuntime : IJSRuntime
3738
/// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>window.someScope.someProp</c>.</param>
3839
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
3940
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
40-
TValue GetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier);
41+
TValue GetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier)
42+
=> throw new NotImplementedException();
4143

4244
/// <summary>
4345
/// Updates the value of the specified JavaScript property synchronously. If the property is not defined on the target object, it will be created.
@@ -46,5 +48,6 @@ public interface IJSInProcessRuntime : IJSRuntime
4648
/// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>window.someScope.someProp</c>.</param>
4749
/// <param name="value">JSON-serializable value.</param>
4850
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
49-
void SetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value);
51+
void SetValue<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value)
52+
=> throw new NotImplementedException();
5053
}

src/JSInterop/Microsoft.JSInterop/src/IJSObjectReference.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public interface IJSObjectReference : IAsyncDisposable
4343
/// <param name="identifier">An identifier for the constructor function to invoke. For example, the value <c>"someScope.SomeClass"</c> will invoke the constructor <c>someScope.SomeClass</c> on the target instance.</param>
4444
/// <param name="args">JSON-serializable arguments.</param>
4545
/// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns>
46-
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, object?[]? args);
46+
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, object?[]? args)
47+
=> throw new NotImplementedException();
4748

4849
/// <summary>
4950
/// Invokes the specified JavaScript constructor function asynchronously. The function is invoked with the <c>new</c> operator.
@@ -55,15 +56,17 @@ public interface IJSObjectReference : IAsyncDisposable
5556
/// </param>
5657
/// <param name="args">JSON-serializable arguments.</param>
5758
/// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns>
58-
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, CancellationToken cancellationToken, object?[]? args);
59+
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, CancellationToken cancellationToken, object?[]? args)
60+
=> throw new NotImplementedException();
5961

6062
/// <summary>
6163
/// Reads the value of the specified JavaScript property asynchronously.
6264
/// </summary>
6365
/// <typeparam name="TValue">The JSON-serializable return type.</typeparam>
6466
/// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>someScope.someProp</c> on the target instance.</param>
6567
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
66-
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier);
68+
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier)
69+
=> throw new NotImplementedException();
6770

6871
/// <summary>
6972
/// Reads the value of the specified JavaScript property asynchronously.
@@ -75,7 +78,8 @@ public interface IJSObjectReference : IAsyncDisposable
7578
/// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied.
7679
/// </param>
7780
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
78-
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken);
81+
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken)
82+
=> throw new NotImplementedException();
7983

8084
/// <summary>
8185
/// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created.
@@ -84,7 +88,8 @@ public interface IJSObjectReference : IAsyncDisposable
8488
/// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>someScope.someProp</c> on the target instance.</param>
8589
/// <param name="value">JSON-serializable value.</param>
8690
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns>
87-
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value);
91+
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value)
92+
=> throw new NotImplementedException();
8893

8994
/// <summary>
9095
/// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created.
@@ -97,5 +102,6 @@ public interface IJSObjectReference : IAsyncDisposable
97102
/// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied.
98103
/// </param>
99104
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns>
100-
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value, CancellationToken cancellationToken);
105+
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value, CancellationToken cancellationToken)
106+
=> throw new NotImplementedException();
101107
}

src/JSInterop/Microsoft.JSInterop/src/IJSRuntime.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public interface IJSRuntime
4343
/// <param name="identifier">An identifier for the constructor function to invoke. For example, the value <c>"someScope.SomeClass"</c> will invoke the constructor <c>window.someScope.SomeClass</c>.</param>
4444
/// <param name="args">JSON-serializable arguments.</param>
4545
/// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns>
46-
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, object?[]? args);
46+
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, object?[]? args)
47+
=> throw new NotImplementedException();
4748

4849
/// <summary>
4950
/// Invokes the specified JavaScript constructor function asynchronously. The function is invoked with the <c>new</c> operator.
@@ -55,15 +56,17 @@ public interface IJSRuntime
5556
/// </param>
5657
/// <param name="args">JSON-serializable arguments.</param>
5758
/// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns>
58-
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, CancellationToken cancellationToken, object?[]? args);
59+
ValueTask<IJSObjectReference> InvokeNewAsync(string identifier, CancellationToken cancellationToken, object?[]? args)
60+
=> throw new NotImplementedException();
5961

6062
/// <summary>
6163
/// Reads the value of the specified JavaScript property asynchronously.
6264
/// </summary>
6365
/// <typeparam name="TValue">The JSON-serializable return type.</typeparam>
6466
/// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>window.someScope.someProp</c>.</param>
6567
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
66-
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier);
68+
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier)
69+
=> throw new NotImplementedException();
6770

6871
/// <summary>
6972
/// Reads the value of the specified JavaScript property asynchronously.
@@ -75,7 +78,8 @@ public interface IJSRuntime
7578
/// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied.
7679
/// </param>
7780
/// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns>
78-
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken);
81+
ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken)
82+
=> throw new NotImplementedException();
7983

8084
/// <summary>
8185
/// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created.
@@ -84,7 +88,8 @@ public interface IJSRuntime
8488
/// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>window.someScope.someProp</c>.</param>
8589
/// <param name="value">JSON-serializable value.</param>
8690
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns>
87-
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value);
91+
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value)
92+
=> throw new NotImplementedException();
8893

8994
/// <summary>
9095
/// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created.
@@ -97,5 +102,6 @@ public interface IJSRuntime
97102
/// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied.
98103
/// </param>
99104
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns>
100-
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value, CancellationToken cancellationToken);
105+
ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value, CancellationToken cancellationToken)
106+
=> throw new NotImplementedException();
101107
}

src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public IJSInProcessObjectReference InvokeNew(string identifier, params object?[]
8181
=> InvokeJS(identifier, argsJson, JSCallResultType.Default, WindowObjectId);
8282

8383
/// <summary>
84-
/// Performs a synchronous function invocation.
84+
/// Performs a synchronous function invocation with the call type <see cref="JSCallType.FunctionCall"/>.
85+
/// For more configuration options, use the overload <see cref="InvokeJS(in JSInvocationInfo)" />.
8586
/// </summary>
8687
/// <param name="identifier">The identifier for the function to invoke.</param>
8788
/// <param name="argsJson">A JSON representation of the arguments.</param>
@@ -95,5 +96,8 @@ public IJSInProcessObjectReference InvokeNew(string identifier, params object?[]
9596
/// </summary>
9697
/// <param name="invocationInfo">Configuration of the interop call.</param>
9798
/// <returns>A JSON representation of the result.</returns>
98-
protected abstract string? InvokeJS(in JSInvocationInfo invocationInfo);
99+
protected virtual string? InvokeJS(in JSInvocationInfo invocationInfo)
100+
{
101+
return InvokeJS(invocationInfo.Identifier, invocationInfo.ArgsJson, invocationInfo.ResultType, invocationInfo.TargetInstanceId);
102+
}
99103
}

src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ protected virtual void BeginInvokeJS(long taskId, string identifier, [StringSynt
192192
=> BeginInvokeJS(taskId, identifier, argsJson, JSCallResultType.Default, WindowObjectId);
193193

194194
/// <summary>
195-
/// Begins an asynchronous function invocation.
195+
/// Begins an asynchronous function invocation with the call type <see cref="JSCallType.FunctionCall"/>.
196+
/// For more configuration options, use the overload <see cref="BeginInvokeJS(in JSInvocationInfo)" />.
196197
/// </summary>
197198
/// <param name="taskId">The identifier for the function invocation, or zero if no async callback is required.</param>
198199
/// <param name="identifier">The identifier for the function to invoke.</param>
@@ -205,7 +206,10 @@ protected virtual void BeginInvokeJS(long taskId, string identifier, [StringSynt
205206
/// Begins an asynchronous function invocation.
206207
/// </summary>
207208
/// <param name="invocationInfo">Configuration of the interop call from .NET to JavaScript.</param>
208-
protected abstract void BeginInvokeJS(in JSInvocationInfo invocationInfo);
209+
protected virtual void BeginInvokeJS(in JSInvocationInfo invocationInfo)
210+
{
211+
BeginInvokeJS(invocationInfo.AsyncHandle, invocationInfo.Identifier, invocationInfo.ArgsJson, invocationInfo.ResultType, invocationInfo.TargetInstanceId);
212+
}
209213

210214
/// <summary>
211215
/// Completes an async JS interop call from JavaScript to .NET

src/JSInterop/Microsoft.JSInterop/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#nullable enable
2-
abstract Microsoft.JSInterop.JSInProcessRuntime.InvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> string?
3-
abstract Microsoft.JSInterop.JSRuntime.BeginInvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> void
42
Microsoft.JSInterop.IJSInProcessObjectReference.GetValue<TValue>(string! identifier) -> TValue
53
Microsoft.JSInterop.IJSInProcessObjectReference.InvokeNew(string! identifier, object?[]? args) -> Microsoft.JSInterop.IJSInProcessObjectReference!
64
Microsoft.JSInterop.IJSInProcessObjectReference.SetValue<TValue>(string! identifier, TValue value) -> void
@@ -62,3 +60,5 @@ static Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeNewAsync(this Micro
6260
static Microsoft.JSInterop.JSRuntimeExtensions.InvokeNewAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, params object?[]? args) -> System.Threading.Tasks.ValueTask<Microsoft.JSInterop.IJSObjectReference!>
6361
static Microsoft.JSInterop.JSRuntimeExtensions.InvokeNewAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, System.Threading.CancellationToken cancellationToken, object?[]? args) -> System.Threading.Tasks.ValueTask<Microsoft.JSInterop.IJSObjectReference!>
6462
static Microsoft.JSInterop.JSRuntimeExtensions.InvokeNewAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, System.TimeSpan timeout, object?[]? args) -> System.Threading.Tasks.ValueTask<Microsoft.JSInterop.IJSObjectReference!>
63+
virtual Microsoft.JSInterop.JSInProcessRuntime.InvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> string?
64+
virtual Microsoft.JSInterop.JSRuntime.BeginInvokeJS(in Microsoft.JSInterop.Infrastructure.JSInvocationInfo invocationInfo) -> void

0 commit comments

Comments
 (0)