|
@@ -242,10 +242,12 @@ public static partial class LuaVirtualMachine
|
|
|
public async ValueTask<int> ExecuteClosureAsyncImpl()
|
|
public async ValueTask<int> ExecuteClosureAsyncImpl()
|
|
|
{
|
|
{
|
|
|
var returnFrameBase = CurrentReturnFrameBase;
|
|
var returnFrameBase = CurrentReturnFrameBase;
|
|
|
|
|
+ var toCatchFlag = false;
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
while (MoveNext(this))
|
|
while (MoveNext(this))
|
|
|
{
|
|
{
|
|
|
|
|
+ toCatchFlag = true;
|
|
|
await Task;
|
|
await Task;
|
|
|
Task = default;
|
|
Task = default;
|
|
|
if (PostOperation is not (PostOperationType.TailCall or PostOperationType.DontPop))
|
|
if (PostOperation is not (PostOperationType.TailCall or PostOperationType.DontPop))
|
|
@@ -258,11 +260,30 @@ public static partial class LuaVirtualMachine
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ toCatchFlag = false;
|
|
|
|
|
+
|
|
|
ThrowIfCancellationRequested();
|
|
ThrowIfCancellationRequested();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return Thread.Stack.Count - returnFrameBase;
|
|
return Thread.Stack.Count - returnFrameBase;
|
|
|
}
|
|
}
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (toCatchFlag)
|
|
|
|
|
+ {
|
|
|
|
|
+ State.CloseUpValues(Thread, FrameBase);
|
|
|
|
|
+ if (e is not (LuaRuntimeException or LuaCanceledException))
|
|
|
|
|
+ {
|
|
|
|
|
+ Exception newException = e is OperationCanceledException ? new LuaCanceledException(Thread, CancellationToken, e) : new LuaRuntimeException(Thread, e);
|
|
|
|
|
+ PopOnTopCallStackFrames();
|
|
|
|
|
+ throw newException;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ PopOnTopCallStackFrames();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ throw;
|
|
|
|
|
+ }
|
|
|
finally
|
|
finally
|
|
|
{
|
|
{
|
|
|
pool.TryPush(this);
|
|
pool.TryPush(this);
|
|
@@ -823,7 +844,7 @@ public static partial class LuaVirtualMachine
|
|
|
context.State.CloseUpValues(context.Thread, context.FrameBase);
|
|
context.State.CloseUpValues(context.Thread, context.FrameBase);
|
|
|
if (e is not (LuaRuntimeException or LuaCanceledException))
|
|
if (e is not (LuaRuntimeException or LuaCanceledException))
|
|
|
{
|
|
{
|
|
|
- var newException = new LuaRuntimeException(context.Thread, e);
|
|
|
|
|
|
|
+ Exception newException = e is OperationCanceledException ? new LuaCanceledException(context.Thread, context.CancellationToken, e) : new LuaRuntimeException(context.Thread, e);
|
|
|
context.PopOnTopCallStackFrames();
|
|
context.PopOnTopCallStackFrames();
|
|
|
throw newException;
|
|
throw newException;
|
|
|
}
|
|
}
|