Skip to content

Commit

Permalink
Follow-Up: Ensure that the "skipFinallyBlock" variable is set even if…
Browse files Browse the repository at this point in the history
… CatchBlock is null.
  • Loading branch information
kpreisser committed Mar 5, 2017
1 parent c773bf2 commit cdc5359
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions Jurassic/Compiler/Statements/TryCatchFinallyStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,37 @@ public override void GenerateCode(ILGenerator generator, OptimizationInfo optimi

// Generate code for the catch block.
ILLocalVariable skipFinallyBlock = null;
if (this.CatchBlock != null)


// Begin a catch block. The exception is on the top of the stack.
generator.BeginCatchBlock(typeof(Exception));

// Check the exception is catchable by calling CanCatchException(ex).
// We need to handle the case where JS code calls into .NET code which then throws
// a JavaScriptException from a different ScriptEngine.
// If CatchBlock is null, we need to rethrow the exception in every case.
var endOfIfLabel = generator.CreateLabel();
generator.Duplicate(); // ex
var exceptionTemporary = generator.CreateTemporaryVariable(typeof(Exception));
generator.StoreVariable(exceptionTemporary);
EmitHelpers.LoadScriptEngine(generator);
generator.LoadVariable(exceptionTemporary);
generator.ReleaseTemporaryVariable(exceptionTemporary);
generator.Call(ReflectionHelpers.ScriptEngine_CanCatchException);
generator.BranchIfTrue(endOfIfLabel);
if (this.FinallyBlock != null)
{
// Begin a catch block. The exception is on the top of the stack.
generator.BeginCatchBlock(typeof(Exception));

// Check the exception is catchable by calling CanCatchException(ex).
// We need to handle the case where JS code calls into .NET code which then throws
// a JavaScriptException from a different ScriptEngine.
var endOfIfLabel = generator.CreateLabel();
generator.Duplicate(); // ex
var exceptionTemporary = generator.CreateTemporaryVariable(typeof(Exception));
generator.StoreVariable(exceptionTemporary);
EmitHelpers.LoadScriptEngine(generator);
generator.LoadVariable(exceptionTemporary);
generator.ReleaseTemporaryVariable(exceptionTemporary);
generator.Call(ReflectionHelpers.ScriptEngine_CanCatchException);
generator.BranchIfTrue(endOfIfLabel);
generator.LoadBoolean(true);
if (this.FinallyBlock != null)
{
skipFinallyBlock = generator.DeclareVariable(typeof(bool), "skipFinallyBlock");
generator.StoreVariable(skipFinallyBlock);
}
generator.Rethrow();
skipFinallyBlock = generator.DeclareVariable(typeof(bool), "skipFinallyBlock");
generator.StoreVariable(skipFinallyBlock);
}
if (this.CatchBlock == null)
generator.DefineLabelPosition(endOfIfLabel);
generator.Rethrow();
if (this.CatchBlock != null)
generator.DefineLabelPosition(endOfIfLabel);

if (this.CatchBlock != null) {
// Create a new DeclarativeScope.
this.CatchScope.GenerateScopeCreation(generator, optimizationInfo);

Expand Down Expand Up @@ -152,13 +157,9 @@ public override void GenerateCode(ILGenerator generator, OptimizationInfo optimi
// If an exception was thrown that wasn't handled by the catch block, then don't
// run the finally block either. This prevents user code from being run when a
// ThreadAbortException is thrown.
var endOfFinallyBlock = generator.CreateLabel();
if (skipFinallyBlock != null)
{
var endOfSkipFinallyBlockLabel = generator.CreateLabel();
generator.LoadVariable(skipFinallyBlock);
generator.BranchIfTrue(endOfFinallyBlock);
}
var endOfFinallyBlock = generator.CreateLabel();
generator.LoadVariable(skipFinallyBlock);
generator.BranchIfTrue(endOfFinallyBlock);

var branches = new List<ILLabel>();
var previousStackSize = optimizationInfo.LongJumpStackSizeThreshold;
Expand Down

0 comments on commit cdc5359

Please sign in to comment.