Skip to content

Commit

Permalink
Merge pull request #13663 from Youssef1313/cleanup-is-net-core
Browse files Browse the repository at this point in the history
chore: Cleanup unneeded IsNetCore on Wasm
  • Loading branch information
jeromelaban authored Sep 18, 2023
2 parents 22636af + 06fdf46 commit e9287cc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 34 deletions.
15 changes: 0 additions & 15 deletions src/Uno.Foundation.Runtime.WebAssembly/Interop/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Uno.Foundation.Runtime.WebAssembly.Interop
{
internal class PlatformHelper
{
private static bool _isNetCore;
private static bool _initialized;
private static bool _isWebAssembly;

Expand All @@ -23,18 +22,6 @@ internal static bool IsWebAssembly
}
}

/// <summary>
/// Determines if the current runtime is running on .NET Core or 5 and later
/// </summary>
internal static bool IsNetCore
{
get
{
EnsureInitialized();
return _isNetCore;
}
}

/// <summary>
/// Initialization is performed explicitly to avoid a mono/mono issue regarding .cctor and FullAOT
/// see https://github.com/unoplatform/uno/issues/5395
Expand All @@ -45,8 +32,6 @@ private static void EnsureInitialized()
{
_initialized = true;

_isNetCore = Type.GetType("System.Runtime.Loader.AssemblyLoadContext") != null;

// Origin of the value : https://github.com/mono/mono/blob/a65055dbdf280004c56036a5d6dde6bec9e42436/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs#L115
_isWebAssembly =
RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY")) // Legacy Value (Bootstrapper 1.2.0-dev.29 or earlier).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ internal sealed class Runtime
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string InvokeJS(string str, out int exceptional_result);

// Disable inlining to avoid the interpreter to evaluate an internal call that may not be available
[MethodImpl(MethodImplOptions.NoInlining)]
private static string MonoInvokeJS(string str, out int exceptionResult) => InvokeJS(str, out exceptionResult);

// Disable inlining to avoid the interpreter to evaluate an internal call that may not be available
[MethodImpl(MethodImplOptions.NoInlining)]
private static string NetCoreInvokeJS(string str, out int exceptionResult)
Expand All @@ -32,9 +28,7 @@ private static string NetCoreInvokeJS(string str, out int exceptionResult)
internal static string InvokeJS(string str)
{
int exceptionResult;
var result = PlatformHelper.IsNetCore
? NetCoreInvokeJS(str, out exceptionResult)
: MonoInvokeJS(str, out exceptionResult);
var result = NetCoreInvokeJS(str, out exceptionResult);

if (exceptionResult != 0)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Uno.UI/UI/Xaml/DependencyPropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ internal class DependencyPropertyDescriptor
private static readonly bool CanUseTypeGetType =
#if __WASM__
// Workaround for https://github.com/dotnet/runtime/issues/45078
Uno.Foundation.Runtime.WebAssembly.Interop.PlatformHelper.IsNetCore
&& Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE") == "Interpreter";
Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE") == "Interpreter";
#else
true;
#endif
Expand Down
13 changes: 3 additions & 10 deletions src/Uno.UI/UI/Xaml/HtmlElementHelper.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,9 @@ private static Assembly GetUnoUIRuntimeWebAssembly()
{
const string UnoUIRuntimeWebAssemblyName = "Uno.UI.Runtime.WebAssembly";

if (PlatformHelper.IsNetCore)
{
// .NET Core fails to load assemblies property because of ALC issues: https://github.com/dotnet/runtime/issues/44269
return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == UnoUIRuntimeWebAssemblyName)
?? throw new InvalidOperationException($"Unable to find {UnoUIRuntimeWebAssemblyName} in the loaded assemblies");
}
else
{
return Assembly.Load(UnoUIRuntimeWebAssemblyName);
}
// .NET Core fails to load assemblies property because of ALC issues: https://github.com/dotnet/runtime/issues/44269
return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == UnoUIRuntimeWebAssemblyName)
?? throw new InvalidOperationException($"Unable to find {UnoUIRuntimeWebAssemblyName} in the loaded assemblies");
}

internal static HtmlTag GetHtmlTag(Type type, string defaultHtmlTag)
Expand Down

0 comments on commit e9287cc

Please sign in to comment.