Example #1
0
 internal static void SetAutomaticVariable(AutomaticVariable variable, object value, MutableTuple locals)
 {
     locals.SetValue((int)variable, value);
 }
Example #2
0
        private static ActionPreference ProcessTraps(FunctionContext funcContext, RuntimeException rte)
        {
            int       index = -1;
            Exception replaceParentContainsErrorRecordException = null;
            Exception innerException = rte.InnerException;

            Type[] types = funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item1;
            Action <FunctionContext>[] actionArray = funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item2;
            if (innerException != null)
            {
                index = FindMatchingHandlerByType(innerException.GetType(), types);
                replaceParentContainsErrorRecordException = innerException;
            }
            if ((index == -1) || types[index].Equals(typeof(CatchAll)))
            {
                int num2 = FindMatchingHandlerByType(rte.GetType(), types);
                if (num2 != index)
                {
                    index = num2;
                    replaceParentContainsErrorRecordException = rte;
                }
            }
            if (index != -1)
            {
                try
                {
                    ErrorRecord      errorRecord = rte.ErrorRecord;
                    ExecutionContext context     = funcContext._executionContext;
                    if (context.CurrentCommandProcessor != null)
                    {
                        context.CurrentCommandProcessor.ForgetScriptException();
                    }
                    try
                    {
                        MutableTuple tuple = MutableTuple.MakeTuple(funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item3[index], Compiler.DottedLocalsNameIndexMap);
                        tuple.SetAutomaticVariable(AutomaticVariable.Underbar, new ErrorRecord(errorRecord, replaceParentContainsErrorRecordException), context);
                        for (int i = 1; i < 9; i++)
                        {
                            tuple.SetValue(i, funcContext._localsTuple.GetValue(i));
                        }
                        SessionStateScope scope = context.EngineSessionState.NewScope(false);
                        context.EngineSessionState.CurrentScope = scope;
                        scope.LocalsTuple = tuple;
                        FunctionContext context2 = new FunctionContext {
                            _scriptBlock      = funcContext._scriptBlock,
                            _sequencePoints   = funcContext._sequencePoints,
                            _executionContext = funcContext._executionContext,
                            _boundBreakpoints = funcContext._boundBreakpoints,
                            _outputPipe       = funcContext._outputPipe,
                            _breakPoints      = funcContext._breakPoints,
                            _localsTuple      = tuple
                        };
                        actionArray[index](context2);
                    }
                    catch (TargetInvocationException exception3)
                    {
                        throw exception3.InnerException;
                    }
                    finally
                    {
                        context.EngineSessionState.RemoveScope(context.EngineSessionState.CurrentScope);
                    }
                    return(QueryForAction(rte, replaceParentContainsErrorRecordException.Message, context));
                }
                catch (ContinueException)
                {
                    return(ActionPreference.SilentlyContinue);
                }
                catch (BreakException)
                {
                    return(ActionPreference.Stop);
                }
            }
            return(ActionPreference.Stop);
        }