private void EmitFunctionImplementation(CodeGen cg, CodeGen icg, bool context) { if (context) { if (IsClosure) { icg.StaticLinkSlot = icg.GetArgumentSlot(0); } icg.ContextSlot = icg.GetArgumentSlot(0); icg.ModuleSlot = new PropertySlot(icg.ContextSlot, typeof(ICallerContext).GetProperty("Module")); } if (EmitLocalDictionary) { PromoteLocalsToEnvironment(); } if (Options.TracebackSupport) { // push a try for traceback support icg.PushTryBlock(); icg.BeginExceptionBlock(); } // emit the actual body if (yieldCount > 0) { EmitGeneratorBody(icg, cg); } else { EmitFunctionBody(icg, cg); } if (Options.TracebackSupport) { // push a fault block (runs only if there's an exception, doesn't handle the exception) icg.PopTargets(); if (icg.IsDynamicMethod) { icg.BeginCatchBlock(typeof(Exception)); } else { icg.BeginFaultBlock(); } EmitUpdateTraceBack(icg, cg); // end the exception block if (icg.IsDynamicMethod) { icg.Emit(OpCodes.Rethrow); } icg.EndExceptionBlock(); } icg.Finish(); }
public static void EmitStackTraceFaultBlock(CodeGen cg, string name, string displayName) { Contract.RequiresNotNull(cg, "cg"); Contract.RequiresNotNull(name, "name"); Contract.RequiresNotNull(displayName, "displayName"); if (ScriptDomainManager.Options.DynamicStackTraceSupport) { // push a fault block (runs only if there's an exception, doesn't handle the exception) cg.PopTargets(); if (cg.IsDynamicMethod) { cg.BeginCatchBlock(typeof(Exception)); } else { cg.BeginFaultBlock(); } cg.EmitCodeContext(); if (cg.IsDynamicMethod) { cg.ConstantPool.AddData(cg.MethodBase).EmitGet(cg); } else { cg.Emit(OpCodes.Ldtoken, cg.MethodInfo); cg.EmitCall(typeof(MethodBase), "GetMethodFromHandle", new Type[] { typeof(RuntimeMethodHandle) }); } cg.EmitString(name); cg.EmitString(displayName); cg.EmitGetCurrentLine(); cg.EmitCall(typeof(ExceptionHelpers), "UpdateStackTrace"); // end the exception block if (cg.IsDynamicMethod) { cg.Emit(OpCodes.Rethrow); } cg.EndExceptionBlock(); } }