diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/ILLink/ILLink.Suppressions.Browser.xml b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/ILLink/ILLink.Suppressions.Browser.xml deleted file mode 100644 index ac291162097d2..0000000000000 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/ILLink/ILLink.Suppressions.Browser.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - ILLink - IL2075 - member - T:System.Runtime.InteropServices.JavaScript.Runtime - - - \ No newline at end of file diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs index 813f07046d0a1..044aefc1eb351 100644 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs +++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs @@ -2,10 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using System.Diagnostics; namespace System.Runtime.InteropServices.JavaScript { @@ -336,6 +337,9 @@ private static void SetupJSContinuation(Task task, JSObject continuationObj) else task.GetAwaiter().OnCompleted(Complete); + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", + Justification = "The DynamicDependency ensures Task.Result is always preserved.")] + [DynamicDependency("get_Result", typeof(Task<>))] void Complete() { try @@ -348,10 +352,15 @@ void Complete() { result = System.Array.Empty(); } + else if (IsAssignableToGenericTaskType(task_type)) + { + result = task_type.GetMethod("get_Result")?.Invoke(task, null); + } else { - result = task_type.GetMethod("get_Result")?.Invoke(task, System.Array.Empty()); + result = null; } + continuationObj.Invoke("resolve", result); } else @@ -371,6 +380,21 @@ void Complete() } } + private static bool IsAssignableToGenericTaskType(Type? t) + { + while (t != null) + { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Task<>)) + { + return true; + } + + t = t.BaseType; + } + + return false; + } + private static string ObjectToString(object o) { return o.ToString() ?? string.Empty;