-
Notifications
You must be signed in to change notification settings - Fork 10.5k
IJSUnmarshalledObjectReference for unmarshalled JS interop calls on JavaScript objects. Fixes #25208 #25548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mkArtakMSFT
merged 8 commits into
release/5.0-rc2
from
t-mabuc/js-unmarshalled-object-reference
Sep 4, 2020
Merged
IJSUnmarshalledObjectReference for unmarshalled JS interop calls on JavaScript objects. Fixes #25208 #25548
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
42abd33
Added IJSUnmarshalledObjectReference
MackinnonBuck a575bf7
Working support for IJSUnmarshalledObjectReference
MackinnonBuck 0d8e849
CR feedback
MackinnonBuck 9db874b
Merge branch 'release/5.0-rc2' of https://github.com/dotnet/aspnetcor…
MackinnonBuck fc3ab5d
Removed IVT and made JSObjectReference public
MackinnonBuck deec48d
Updated JSON converter.
MackinnonBuck 5ac5bc2
Update JSObjectReferenceJsonConverterTest.cs
MackinnonBuck 5bff875
Removed whitespace :sweat:
MackinnonBuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Components/WebAssembly/JSInterop/src/WebAssemblyJSObjectReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.JSInterop.Implementation; | ||
|
|
||
| namespace Microsoft.JSInterop.WebAssembly | ||
| { | ||
| internal class WebAssemblyJSObjectReference : JSInProcessObjectReference, IJSUnmarshalledObjectReference | ||
| { | ||
| private readonly WebAssemblyJSRuntime _jsRuntime; | ||
|
|
||
| public WebAssemblyJSObjectReference(WebAssemblyJSRuntime jsRuntime, long id) : base(jsRuntime, id) | ||
| { | ||
| _jsRuntime = jsRuntime; | ||
| } | ||
|
|
||
| public TResult InvokeUnmarshalled<TResult>(string identifier) | ||
| { | ||
| ThrowIfDisposed(); | ||
|
|
||
| return _jsRuntime.InvokeUnmarshalled<object, object, object, TResult>(identifier, null, null, null, Id); | ||
| } | ||
|
|
||
| public TResult InvokeUnmarshalled<T0, TResult>(string identifier, T0 arg0) | ||
| { | ||
| ThrowIfDisposed(); | ||
|
|
||
| return _jsRuntime.InvokeUnmarshalled<T0, object, object, TResult>(identifier, arg0, null, null, Id); | ||
| } | ||
|
|
||
| public TResult InvokeUnmarshalled<T0, T1, TResult>(string identifier, T0 arg0, T1 arg1) | ||
| { | ||
| ThrowIfDisposed(); | ||
|
|
||
| return _jsRuntime.InvokeUnmarshalled<T0, T1, object, TResult>(identifier, arg0, arg1, null, Id); | ||
| } | ||
|
|
||
| public TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2) | ||
| { | ||
| ThrowIfDisposed(); | ||
|
|
||
| return _jsRuntime.InvokeUnmarshalled<T0, T1, T2, TResult>(identifier, arg0, arg1, arg2, Id); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Components/test/testassets/BasicTestApp/InteropTest/InteropStruct.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace BasicTestApp.InteropTest | ||
| { | ||
| [StructLayout(LayoutKind.Explicit)] | ||
| public struct InteropStruct | ||
| { | ||
| [FieldOffset(0)] | ||
| public string Message; | ||
|
|
||
| [FieldOffset(8)] | ||
| public int NumberField; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/JSInterop/Microsoft.JSInterop/src/IJSInProcessObjectReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/JSInterop/Microsoft.JSInterop/src/IJSUnmarshalledObjectReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.JSInterop | ||
| { | ||
| /// <summary> | ||
| /// Represents a reference to a JavaScript object whose functions can be invoked synchronously without JSON marshalling. | ||
| /// </summary> | ||
| public interface IJSUnmarshalledObjectReference : IJSInProcessObjectReference | ||
| { | ||
| /// <summary> | ||
| /// Invokes the JavaScript function registered with the specified identifier. | ||
| /// </summary> | ||
| /// <typeparam name="TResult">The .NET type corresponding to the function's return value type.</typeparam> | ||
| /// <param name="identifier">The identifier used when registering the target function.</param> | ||
| /// <returns>The result of the function invocation.</returns> | ||
| TResult InvokeUnmarshalled<TResult>(string identifier); | ||
|
|
||
| /// <summary> | ||
| /// Invokes the JavaScript function registered with the specified identifier. | ||
| /// </summary> | ||
| /// <typeparam name="T0">The type of the first argument.</typeparam> | ||
| /// <typeparam name="TResult">The .NET type corresponding to the function's return value type.</typeparam> | ||
| /// <param name="identifier">The identifier used when registering the target function.</param> | ||
| /// <param name="arg0">The first argument.</param> | ||
| /// <returns>The result of the function invocation.</returns> | ||
| TResult InvokeUnmarshalled<T0, TResult>(string identifier, T0 arg0); | ||
|
|
||
| /// <summary> | ||
| /// Invokes the JavaScript function registered with the specified identifier. | ||
| /// </summary> | ||
| /// <typeparam name="T0">The type of the first argument.</typeparam> | ||
| /// <typeparam name="T1">The type of the second argument.</typeparam> | ||
| /// <typeparam name="TResult">The .NET type corresponding to the function's return value type.</typeparam> | ||
| /// <param name="identifier">The identifier used when registering the target function.</param> | ||
| /// <param name="arg0">The first argument.</param> | ||
| /// <param name="arg1">The second argument.</param> | ||
| /// <returns>The result of the function invocation.</returns> | ||
| TResult InvokeUnmarshalled<T0, T1, TResult>(string identifier, T0 arg0, T1 arg1); | ||
|
|
||
| /// <summary> | ||
| /// Invokes the JavaScript function registered with the specified identifier. | ||
| /// </summary> | ||
| /// <typeparam name="T0">The type of the first argument.</typeparam> | ||
| /// <typeparam name="T1">The type of the second argument.</typeparam> | ||
| /// <typeparam name="T2">The type of the third argument.</typeparam> | ||
| /// <typeparam name="TResult">The .NET type corresponding to the function's return value type.</typeparam> | ||
| /// <param name="identifier">The identifier used when registering the target function.</param> | ||
| /// <param name="arg0">The first argument.</param> | ||
| /// <param name="arg1">The second argument.</param> | ||
| /// <param name="arg2">The third argument.</param> | ||
| /// <returns>The result of the function invocation.</returns> | ||
| TResult InvokeUnmarshalled<T0, T1, T2, TResult>(string identifier, T0 arg0, T1 arg1, T2 arg2); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/JSInterop/Microsoft.JSInterop/src/Implementation/JSInProcessObjectReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace Microsoft.JSInterop.Implementation | ||
| { | ||
| /// <summary> | ||
| /// Implements functionality for <see cref="IJSInProcessObjectReference"/>. | ||
| /// </summary> | ||
| public class JSInProcessObjectReference : JSObjectReference, IJSInProcessObjectReference | ||
| { | ||
| private readonly JSInProcessRuntime _jsRuntime; | ||
|
|
||
| /// <summary> | ||
| /// Inititializes a new <see cref="JSInProcessObjectReference"/> instance. | ||
| /// </summary> | ||
| /// <param name="jsRuntime">The <see cref="JSInProcessRuntime"/> used for invoking JS interop calls.</param> | ||
| /// <param name="id">The unique identifier.</param> | ||
| protected internal JSInProcessObjectReference(JSInProcessRuntime jsRuntime, long id) : base(jsRuntime, id) | ||
| { | ||
| _jsRuntime = jsRuntime; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| [return: MaybeNull] | ||
| public TValue Invoke<TValue>(string identifier, params object?[]? args) | ||
| { | ||
| ThrowIfDisposed(); | ||
|
|
||
| return _jsRuntime.Invoke<TValue>(identifier, Id, args); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public void Dispose() | ||
| { | ||
| if (!Disposed) | ||
| { | ||
| Disposed = true; | ||
|
|
||
| _jsRuntime.InvokeVoid("DotNet.jsCallDispatcher.disposeJSObjectReferenceById", Id); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.