internal void LoadMethodProperties(Exception exception, System.Diagnostics.StackFrame stackFrame) { // Validation if (exception == null || exception.TargetSite == null || typeof(System.Reflection.MethodInfo).IsAssignableFrom(exception.TargetSite.GetType()) == false) { return; } // Get Reflection Information System.Reflection.MethodBase methodBase = stackFrame.GetMethod(); System.Reflection.MethodBody methodBody = methodBase.GetMethodBody(); System.Reflection.MethodInfo methodInfo = (methodBase != null && typeof(System.Reflection.MethodInfo).IsAssignableFrom(methodBase.GetType()) == true) ? (System.Reflection.MethodInfo)methodBase : null; System.Reflection.MethodInfo targetSiteInfo = ((System.Reflection.MethodInfo)exception.TargetSite); // Get Return Information this.m_ReturnParameter = (targetSiteInfo != null && targetSiteInfo.ReturnParameter != null) ? targetSiteInfo.Name : ""; this.m_ReturnType = (targetSiteInfo != null && targetSiteInfo.ReturnType != null) ? targetSiteInfo.ReturnType.FullName : ""; // Get Line Number int intLineNumber = (GetLineNumber(exception) == 0) ? stackFrame.GetFileLineNumber() : GetLineNumber(exception); this.m_LineNumber = (this.LineNumber == 0) ? stackFrame.GetFileLineNumber() : intLineNumber; if (methodInfo != null && methodInfo.GetParameters().Count() > 0) { this.m_Parameters = methodInfo.GetParameters().Select(param => new ParameterInformation(param.Name, param.ParameterType.ToString())).ToList(); } }
internal void LoadClassFileInformation(Exception exception, System.Diagnostics.StackFrame stackFrame) { // Get Reflection Information System.Reflection.MethodBase methodBase = stackFrame.GetMethod(); System.Reflection.MethodBody methodBody = methodBase.GetMethodBody(); System.Reflection.MethodInfo methodInfo = (methodBase != null && typeof(System.Reflection.MethodInfo).IsAssignableFrom(methodBase.GetType()) == true) ? (System.Reflection.MethodInfo)methodBase : null; System.Reflection.MethodInfo targetSiteInfo = ((System.Reflection.MethodInfo)exception.TargetSite); // Load Method Properties this.Method.LoadMethodProperties(exception, stackFrame); this.m_Name = (methodInfo != null && methodInfo.ReflectedType != null) ? methodInfo.ReflectedType.Name : ""; this.m_FullName = methodBase.ReflectedType.FullName + " - " + this.Method.Name; }
private void LoadError() { // Get Application Information this.m_Application = new ApplicationInformation(); // Loop Stack Trace Frames System.Diagnostics.StackTrace CurrentStackTest = new System.Diagnostics.StackTrace(this.Exception, 0, true); for (int intIndex = 0; intIndex < CurrentStackTest.FrameCount; intIndex++) { // Get Reflection Information System.Diagnostics.StackFrame frame = (CurrentStackTest != null && intIndex >= 0) ? CurrentStackTest.GetFrame(intIndex) : null; System.Reflection.MethodBase methodBase = (frame != null) ? frame.GetMethod() : null; System.Reflection.MethodBody methodBody = (methodBase != null) ? methodBase.GetMethodBody() : null; System.Reflection.MethodInfo info = (methodBase != null && typeof(System.Reflection.MethodInfo).IsAssignableFrom(methodBase.GetType()) == true) ? info = (System.Reflection.MethodInfo)methodBase : null; //// Validation if (this.m_Class != null && this.m_Class.Method.Name != System.Reflection.MethodBase.GetCurrentMethod().Name) { // SET ATTEMPTED METHOD System.Diagnostics.StackFrame previousFrame = (intIndex - 1 >= 0) ? CurrentStackTest.GetFrame(intIndex - 1) : null; System.Reflection.MethodBase previousBase = (previousFrame != null) ? ((System.Reflection.MethodBase)previousFrame.GetMethod()) : null; string strMethod = (previousBase != null && typeof(System.Reflection.MethodInfo).IsAssignableFrom(previousBase.GetType()) == true) ? previousBase.DeclaringType.FullName + " - " + ((System.Reflection.MethodInfo)previousBase).ToString() : info.Name; this.m_Class.AttemptedMethod = (intIndex < 2 && strMethod != this.m_Class.Method.Name) ? strMethod : this.m_Class.AttemptedMethod; } // Validation if (intIndex > 2) { continue; } // LOAD ASSEMBLY PROPERTIES this.m_Assembly = new AssemblyInformation(info); // LOAD METHOD PROPERTIES this.m_Class = new ClassFileInformation(this.Exception, frame); } }
/// <summary> /// Generates CIL for the expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo) { // Get the target as a name expression: NameExpression nameExpr = Target as NameExpression; // Grab if this is a 'new' call: bool isConstructor = optimizationInfo.IsConstructCall; optimizationInfo.IsConstructCall = false; if (ResolvedMethod != null) { // We have a known method! if (UserDefined != null) { if (isConstructor) { // Generate code to produce the "this" value. Library.Prototype proto = UserDefined.GetInstancePrototype(optimizationInfo.Engine); // Create the object now: generator.NewObject(proto.TypeConstructor); // Duplicate (which will act as our return value): if (optimizationInfo.RootExpression != this) { generator.Duplicate(); } } else { // There are three cases for non-constructor calls. if (this.Target is NameExpression) { // 1. The function is a name expression (e.g. "parseInt()"). // In this case this = scope.ImplicitThisValue, if there is one, otherwise undefined. ((NameExpression)this.Target).GenerateThis(generator); } else if (this.Target is MemberAccessExpression) { // 2. The function is a member access expression (e.g. "Math.cos()"). // In this case this = Math. var baseExpression = ((MemberAccessExpression)this.Target).Base; baseExpression.GenerateCode(generator, optimizationInfo); EmitConversion.ToAny(generator, baseExpression.GetResultType(optimizationInfo)); } else { // 3. Neither of the above (e.g. "(function() { return 5 })()") // In this case this = undefined. EmitHelpers.EmitUndefined(generator); } } } // Emit the rest of the args: EmitArguments(generator, optimizationInfo); // Got a return type? Type returnType = GetResultType(optimizationInfo); // Then the call! if (typeof(System.Reflection.ConstructorInfo).IsAssignableFrom(ResolvedMethod.GetType())) { // Actual constructor call: generator.NewObject(ResolvedMethod as System.Reflection.ConstructorInfo); } else { // Ordinary method: generator.Call(ResolvedMethod); } if (isConstructor) { // Always a returned value here. Needed? if (optimizationInfo.RootExpression == this) { // Remove the return value: generator.Pop(); } } else { if (returnType == typeof(Nitrassic.Undefined)) { if (optimizationInfo.RootExpression != this) { // Put undef on the stack: EmitHelpers.EmitUndefined(generator); } } else if (optimizationInfo.RootExpression == this) { // Remove the return value: generator.Pop(); } } } else { // Either runtime resolve it or it's not actually a callable function throw new NotImplementedException("A function was called which was not supported (" + ToString() + ")"); } }