Merge branch 'tests/try-finally'
This commit is contained in:
@@ -13,12 +13,12 @@ namespace Torch.Server.Views
|
|||||||
|
|
||||||
public static bool GetScrollContainer(this UIElement ui)
|
public static bool GetScrollContainer(this UIElement ui)
|
||||||
{
|
{
|
||||||
return (bool)ui.GetValue(ScrollContainerProperty);
|
return (bool) (ui?.GetValue(ScrollContainerProperty) ?? false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetScrollContainer(this UIElement ui, bool value)
|
public static void SetScrollContainer(this UIElement ui, bool value)
|
||||||
{
|
{
|
||||||
ui.SetValue(ScrollContainerProperty, value);
|
ui?.SetValue(ScrollContainerProperty, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -513,6 +513,83 @@ namespace Torch.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PatchTest]
|
||||||
|
private class StaticTryFinallyInject
|
||||||
|
{
|
||||||
|
private static bool _injectionHit;
|
||||||
|
private static bool _normalHit;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public static void Target()
|
||||||
|
{
|
||||||
|
_normalHit = true;
|
||||||
|
}
|
||||||
|
public static void Reset()
|
||||||
|
{
|
||||||
|
_injectionHit = _normalHit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InjectionTarget()
|
||||||
|
{
|
||||||
|
_injectionHit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AssertTranspile()
|
||||||
|
{
|
||||||
|
Assert.True(_injectionHit, "Failed to execute transpile");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AssertNormal()
|
||||||
|
{
|
||||||
|
Assert.True(_normalHit, "Failed to execute normal");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> instructions, MethodBase __methodBase, Func<Type, MsilLocal> __localCreator)
|
||||||
|
{
|
||||||
|
var returnHasValue = (__methodBase as MethodInfo)?.ReturnType != typeof(void);
|
||||||
|
var returnLabel = new MsilLabel();
|
||||||
|
|
||||||
|
var original = instructions.ToList();
|
||||||
|
|
||||||
|
MsilLocal returnLocal = null;
|
||||||
|
if (returnHasValue)
|
||||||
|
returnLocal = __localCreator(((MethodInfo)__methodBase).ReturnType);
|
||||||
|
|
||||||
|
// begin try block at start of method
|
||||||
|
var firstInstruction = original.First();
|
||||||
|
firstInstruction.TryCatchOperations.Add(new(MsilTryCatchOperationType.BeginExceptionBlock));
|
||||||
|
yield return firstInstruction;
|
||||||
|
|
||||||
|
// copy original except first
|
||||||
|
foreach (var instruction in original.Skip(1))
|
||||||
|
{
|
||||||
|
if (instruction.OpCode == OpCodes.Ret)
|
||||||
|
{
|
||||||
|
if (returnHasValue)
|
||||||
|
yield return instruction.CopyWith(OpCodes.Stloc).InlineValue(returnLocal);
|
||||||
|
|
||||||
|
yield return new MsilInstruction(OpCodes.Leave).InlineTarget(returnLabel);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
yield return instruction;
|
||||||
|
}
|
||||||
|
|
||||||
|
var injectionCall = new MsilInstruction(OpCodes.Call).InlineValue(new Action(InjectionTarget).Method);
|
||||||
|
// split begin and end to separate instructions if needed. endfinally instruction will be generated automatically
|
||||||
|
injectionCall.TryCatchOperations.AddRange(new MsilTryCatchOperation[]
|
||||||
|
{
|
||||||
|
new(MsilTryCatchOperationType.BeginFinallyBlock),
|
||||||
|
new(MsilTryCatchOperationType.EndExceptionBlock)
|
||||||
|
});
|
||||||
|
yield return injectionCall;
|
||||||
|
|
||||||
|
if (returnHasValue)
|
||||||
|
yield return new MsilInstruction(OpCodes.Ldloc).InlineValue(returnLocal);
|
||||||
|
|
||||||
|
yield return new MsilInstruction(OpCodes.Ret).LabelWith(returnLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#pragma warning restore 414
|
#pragma warning restore 414
|
||||||
|
@@ -38,12 +38,15 @@ Global
|
|||||||
{7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{9EFD1D91-2FA2-47ED-B537-D8BC3B0E543E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{9EFD1D91-2FA2-47ED-B537-D8BC3B0E543E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{9EFD1D91-2FA2-47ED-B537-D8BC3B0E543E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{9EFD1D91-2FA2-47ED-B537-D8BC3B0E543E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{C3C8B671-6AD1-44AA-A8DA-E0C0DC0FEDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C3C8B671-6AD1-44AA-A8DA-E0C0DC0FEDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
<PackageReference Include="NLog" Version="4.7.13" />
|
<PackageReference Include="NLog" Version="4.7.13" />
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" PrivateAssets="all" />
|
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" PrivateAssets="all" />
|
||||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||||
|
<PackageReference Include="Torch.SixLabors.ImageSharp" Version="1.0.0-beta6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="HavokWrapper, Version=1.0.6278.22649, Culture=neutral, processorArchitecture=AMD64">
|
<Reference Include="HavokWrapper, Version=1.0.6278.22649, Culture=neutral, processorArchitecture=AMD64">
|
||||||
|
Reference in New Issue
Block a user