From 668a867cce2652bad46a4c307c82cac85af98f18 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 4 Feb 2020 14:51:48 -0800 Subject: [PATCH] Remove Mono.WebAssembly.Interop \n\nCommit migrated from https://github.com/dotnet/extensions/commit/211046f01bf335241a4084b5cac2c08593835cb9 --- src/JSInterop/JSInterop.slnf | 3 +- .../Directory.Build.props | 9 - .../ref/Mono.WebAssembly.Interop.csproj | 10 -- ...Mono.WebAssembly.Interop.netstandard2.0.cs | 18 -- .../src/InternalCalls.cs | 25 --- .../src/Mono.WebAssembly.Interop.csproj | 18 -- .../src/MonoWebAssemblyJSRuntime.cs | 157 ------------------ 7 files changed, 1 insertion(+), 239 deletions(-) delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/Directory.Build.props delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.csproj delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.netstandard2.0.cs delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/src/InternalCalls.cs delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/src/Mono.WebAssembly.Interop.csproj delete mode 100644 src/JSInterop/Mono.WebAssembly.Interop/src/MonoWebAssemblyJSRuntime.cs diff --git a/src/JSInterop/JSInterop.slnf b/src/JSInterop/JSInterop.slnf index c6cbd4cb3a..faae0051a5 100644 --- a/src/JSInterop/JSInterop.slnf +++ b/src/JSInterop/JSInterop.slnf @@ -3,8 +3,7 @@ "path": "..\\..\\Extensions.sln", "projects": [ "src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj", - "src\\JSInterop\\Microsoft.JSInterop\\test\\Microsoft.JSInterop.Tests.csproj", - "src\\JSInterop\\Mono.WebAssembly.Interop\\src\\Mono.WebAssembly.Interop.csproj", + "src\\JSInterop\\Microsoft.JSInterop\\test\\Microsoft.JSInterop.Tests.csproj" ] } } diff --git a/src/JSInterop/Mono.WebAssembly.Interop/Directory.Build.props b/src/JSInterop/Mono.WebAssembly.Interop/Directory.Build.props deleted file mode 100644 index ce32dcd999..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/Directory.Build.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - $(BlazorWasmPreReleaseVersionLabel) - - - diff --git a/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.csproj b/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.csproj deleted file mode 100644 index a1ba605705..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - netstandard2.0 - - - - - - diff --git a/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.netstandard2.0.cs b/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.netstandard2.0.cs deleted file mode 100644 index 8dd70b946a..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/ref/Mono.WebAssembly.Interop.netstandard2.0.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 Mono.WebAssembly.Interop -{ - public partial class MonoWebAssemblyJSRuntime : Microsoft.JSInterop.JSInProcessRuntime - { - public MonoWebAssemblyJSRuntime() { } - protected override void BeginInvokeJS(long asyncHandle, string identifier, string argsJson) { } - protected override void EndInvokeDotNet(Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo callInfo, in Microsoft.JSInterop.Infrastructure.DotNetInvocationResult dispatchResult) { } - protected static void Initialize(Mono.WebAssembly.Interop.MonoWebAssemblyJSRuntime jsRuntime) { } - protected override string InvokeJS(string identifier, string argsJson) { throw null; } - public TRes InvokeUnmarshalled(string identifier) { throw null; } - public TRes InvokeUnmarshalled(string identifier, T0 arg0) { throw null; } - public TRes InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1) { throw null; } - public TRes InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1, T2 arg2) { throw null; } - } -} diff --git a/src/JSInterop/Mono.WebAssembly.Interop/src/InternalCalls.cs b/src/JSInterop/Mono.WebAssembly.Interop/src/InternalCalls.cs deleted file mode 100644 index 60c0cdc429..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/src/InternalCalls.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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.Runtime.CompilerServices; - -namespace WebAssembly.JSInterop -{ - /// - /// Methods that map to the functions compiled into the Mono WebAssembly runtime, - /// as defined by 'mono_add_internal_call' calls in driver.c - /// - internal class InternalCalls - { - // The exact namespace, type, and method names must match the corresponding entries - // in driver.c in the Mono distribution - - // We're passing asyncHandle by ref not because we want it to be writable, but so it gets - // passed as a pointer (4 bytes). We can pass 4-byte values, but not 8-byte ones. - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern string InvokeJSMarshalled(out string exception, ref long asyncHandle, string functionIdentifier, string argsJson); - - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern TRes InvokeJSUnmarshalled(out string exception, string functionIdentifier, T0 arg0, T1 arg1, T2 arg2); - } -} diff --git a/src/JSInterop/Mono.WebAssembly.Interop/src/Mono.WebAssembly.Interop.csproj b/src/JSInterop/Mono.WebAssembly.Interop/src/Mono.WebAssembly.Interop.csproj deleted file mode 100644 index f85c89a6d3..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/src/Mono.WebAssembly.Interop.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - netstandard2.0 - Abstractions and features for interop between Mono WebAssembly and JavaScript code. - wasm;javascript;interop - true - true - true - - true - - - - - - - diff --git a/src/JSInterop/Mono.WebAssembly.Interop/src/MonoWebAssemblyJSRuntime.cs b/src/JSInterop/Mono.WebAssembly.Interop/src/MonoWebAssemblyJSRuntime.cs deleted file mode 100644 index 654263a123..0000000000 --- a/src/JSInterop/Mono.WebAssembly.Interop/src/MonoWebAssemblyJSRuntime.cs +++ /dev/null @@ -1,157 +0,0 @@ -// 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; -using System.Text.Json; -using Microsoft.JSInterop; -using Microsoft.JSInterop.Infrastructure; -using WebAssembly.JSInterop; - -namespace Mono.WebAssembly.Interop -{ - /// - /// Provides methods for invoking JavaScript functions for applications running - /// on the Mono WebAssembly runtime. - /// - public class MonoWebAssemblyJSRuntime : JSInProcessRuntime - { - /// - /// Gets the used to perform operations using . - /// - private static MonoWebAssemblyJSRuntime Instance { get; set; } - - /// - /// Initializes the to be used to perform operations using . - /// - /// The instance. - protected static void Initialize(MonoWebAssemblyJSRuntime jsRuntime) - { - if (Instance != null) - { - throw new InvalidOperationException("MonoWebAssemblyJSRuntime has already been initialized."); - } - - Instance = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime)); - } - - /// - protected override string InvokeJS(string identifier, string argsJson) - { - var noAsyncHandle = default(long); - var result = InternalCalls.InvokeJSMarshalled(out var exception, ref noAsyncHandle, identifier, argsJson); - return exception != null - ? throw new JSException(exception) - : result; - } - - /// - protected override void BeginInvokeJS(long asyncHandle, string identifier, string argsJson) - { - InternalCalls.InvokeJSMarshalled(out _, ref asyncHandle, identifier, argsJson); - } - - // Invoked via Mono's JS interop mechanism (invoke_method) - private static string InvokeDotNet(string assemblyName, string methodIdentifier, string dotNetObjectId, string argsJson) - { - var callInfo = new DotNetInvocationInfo(assemblyName, methodIdentifier, dotNetObjectId == null ? default : long.Parse(dotNetObjectId), callId: null); - return DotNetDispatcher.Invoke(Instance, callInfo, argsJson); - } - - // Invoked via Mono's JS interop mechanism (invoke_method) - private static void EndInvokeJS(string argsJson) - => DotNetDispatcher.EndInvokeJS(Instance, argsJson); - - // Invoked via Mono's JS interop mechanism (invoke_method) - private static void BeginInvokeDotNet(string callId, string assemblyNameOrDotNetObjectId, string methodIdentifier, string argsJson) - { - // Figure out whether 'assemblyNameOrDotNetObjectId' is the assembly name or the instance ID - // We only need one for any given call. This helps to work around the limitation that we can - // only pass a maximum of 4 args in a call from JS to Mono WebAssembly. - string assemblyName; - long dotNetObjectId; - if (char.IsDigit(assemblyNameOrDotNetObjectId[0])) - { - dotNetObjectId = long.Parse(assemblyNameOrDotNetObjectId); - assemblyName = null; - } - else - { - dotNetObjectId = default; - assemblyName = assemblyNameOrDotNetObjectId; - } - - var callInfo = new DotNetInvocationInfo(assemblyName, methodIdentifier, dotNetObjectId, callId); - DotNetDispatcher.BeginInvokeDotNet(Instance, callInfo, argsJson); - } - - protected override void EndInvokeDotNet(DotNetInvocationInfo callInfo, in DotNetInvocationResult dispatchResult) - { - // For failures, the common case is to call EndInvokeDotNet with the Exception object. - // For these we'll serialize as something that's useful to receive on the JS side. - // If the value is not an Exception, we'll just rely on it being directly JSON-serializable. - var resultOrError = dispatchResult.Success ? dispatchResult.Result : dispatchResult.Exception.ToString(); - - // We pass 0 as the async handle because we don't want the JS-side code to - // send back any notification (we're just providing a result for an existing async call) - var args = JsonSerializer.Serialize(new[] { callInfo.CallId, dispatchResult.Success, resultOrError }, JsonSerializerOptions); - BeginInvokeJS(0, "DotNet.jsCallDispatcher.endInvokeDotNetFromJS", args); - } - - #region Custom MonoWebAssemblyJSRuntime methods - - /// - /// Invokes the JavaScript function registered with the specified identifier. - /// - /// The .NET type corresponding to the function's return value type. - /// The identifier used when registering the target function. - /// The result of the function invocation. - public TRes InvokeUnmarshalled(string identifier) - => InvokeUnmarshalled(identifier, null, null, null); - - /// - /// Invokes the JavaScript function registered with the specified identifier. - /// - /// The type of the first argument. - /// The .NET type corresponding to the function's return value type. - /// The identifier used when registering the target function. - /// The first argument. - /// The result of the function invocation. - public TRes InvokeUnmarshalled(string identifier, T0 arg0) - => InvokeUnmarshalled(identifier, arg0, null, null); - - /// - /// Invokes the JavaScript function registered with the specified identifier. - /// - /// The type of the first argument. - /// The type of the second argument. - /// The .NET type corresponding to the function's return value type. - /// The identifier used when registering the target function. - /// The first argument. - /// The second argument. - /// The result of the function invocation. - public TRes InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1) - => InvokeUnmarshalled(identifier, arg0, arg1, null); - - /// - /// Invokes the JavaScript function registered with the specified identifier. - /// - /// The type of the first argument. - /// The type of the second argument. - /// The type of the third argument. - /// The .NET type corresponding to the function's return value type. - /// The identifier used when registering the target function. - /// The first argument. - /// The second argument. - /// The third argument. - /// The result of the function invocation. - public TRes InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1, T2 arg2) - { - var result = InternalCalls.InvokeJSUnmarshalled(out var exception, identifier, arg0, arg1, arg2); - return exception != null - ? throw new JSException(exception) - : result; - } - - #endregion - } -}