Inheritance: System.Exception
Exemplo n.º 1
0
		private static string GetExceptionMessage(RhinoException ex)
		{
			string msg;
			if (ex is JavaScriptException)
			{
				msg = GetMessage("msg.uncaughtJSException", ex.Details());
			}
			else
			{
				if (ex is EcmaError)
				{
					msg = GetMessage("msg.uncaughtEcmaError", ex.Details());
				}
				else
				{
					if (ex is EvaluatorException)
					{
						msg = ex.Details();
					}
					else
					{
						msg = ex.ToString();
					}
				}
			}
			return msg;
		}
Exemplo n.º 2
0
		public static void ReportException(ErrorReporter er, RhinoException ex)
		{
			if (er is Rhino.Tools.ToolErrorReporter)
			{
				((Rhino.Tools.ToolErrorReporter)er).ReportException(ex);
			}
			else
			{
				string msg = GetExceptionMessage(ex);
				er.Error(msg, ex.SourceName(), ex.LineNumber(), ex.LineSource(), ex.ColumnNumber());
			}
		}
Exemplo n.º 3
0
		public virtual void ReportException(RhinoException ex)
		{
			if (ex is WrappedException)
			{
				WrappedException we = (WrappedException)ex;
				Sharpen.Runtime.PrintStackTrace(we, err);
			}
			else
			{
				string lineSeparator = SecurityUtilities.GetSystemProperty("line.separator");
				string msg = GetExceptionMessage(ex) + lineSeparator + ex.GetScriptStackTrace();
				ReportErrorMessage(msg, ex.SourceName(), ex.LineNumber(), ex.LineSource(), ex.ColumnNumber(), false);
			}
		}
Exemplo n.º 4
0
		public IList<string> GetScriptStack(RhinoException ex)
		{
			ScriptStackElement[][] stack = GetScriptStackElements(ex);
			IList<string> list = new List<string>(stack.Length);
			string lineSeparator = SecurityUtilities.GetSystemProperty("line.separator");
			foreach (ScriptStackElement[] group in stack)
			{
				StringBuilder sb = new StringBuilder();
				foreach (ScriptStackElement elem in group)
				{
					elem.RenderJavaStyle(sb);
					sb.Append(lineSeparator);
				}
				list.Add(sb.ToString());
			}
			return list;
		}
Exemplo n.º 5
0
		public ScriptStackElement[][] GetScriptStackElements(RhinoException ex)
		{
			if (ex.interpreterStackInfo == null)
			{
				return null;
			}
			IList<ScriptStackElement[]> list = new List<ScriptStackElement[]>();
			Interpreter.CallFrame[] array = (Interpreter.CallFrame[])ex.interpreterStackInfo;
			int[] linePC = ex.interpreterLineData;
			int arrayIndex = array.Length;
			int linePCIndex = linePC.Length;
			while (arrayIndex != 0)
			{
				--arrayIndex;
				Interpreter.CallFrame frame = array[arrayIndex];
				IList<ScriptStackElement> group = new List<ScriptStackElement>();
				while (frame != null)
				{
					if (linePCIndex == 0)
					{
						Kit.CodeBug();
					}
					--linePCIndex;
					InterpreterData idata = frame.idata;
					string fileName = idata.itsSourceFile;
					string functionName = null;
					int lineNumber = -1;
					int pc = linePC[linePCIndex];
					if (pc >= 0)
					{
						lineNumber = GetIndex(idata.itsICode, pc);
					}
					if (idata.itsName != null && idata.itsName.Length != 0)
					{
						functionName = idata.itsName;
					}
					frame = frame.parentFrame;
					group.Add(new ScriptStackElement(fileName, functionName, lineNumber));
				}
				list.Add(Sharpen.Collections.ToArray(group, new ScriptStackElement[group.Count]));
			}
			return Sharpen.Collections.ToArray(list, new ScriptStackElement[list.Count][]);
		}
Exemplo n.º 6
0
		public void CaptureStackInfo(RhinoException ex)
		{
			Context cx = Context.GetCurrentContext();
			if (cx == null || cx.lastInterpreterFrame == null)
			{
				// No interpreter invocations
				ex.interpreterStackInfo = null;
				ex.interpreterLineData = null;
				return;
			}
			// has interpreter frame on the stack
			Interpreter.CallFrame[] array;
			if (cx.previousInterpreterInvocations == null || cx.previousInterpreterInvocations.Size() == 0)
			{
				array = new Interpreter.CallFrame[1];
			}
			else
			{
				int previousCount = cx.previousInterpreterInvocations.Size();
				if (cx.previousInterpreterInvocations.Peek() == cx.lastInterpreterFrame)
				{
					// It can happen if exception was generated after
					// frame was pushed to cx.previousInterpreterInvocations
					// but before assignment to cx.lastInterpreterFrame.
					// In this case frames has to be ignored.
					--previousCount;
				}
				array = new Interpreter.CallFrame[previousCount + 1];
				cx.previousInterpreterInvocations.ToArray(array);
			}
			array[array.Length - 1] = (Interpreter.CallFrame)cx.lastInterpreterFrame;
			int interpreterFrameCount = 0;
			for (int i = 0; i != array.Length; ++i)
			{
				interpreterFrameCount += 1 + array[i].frameIndex;
			}
			int[] linePC = new int[interpreterFrameCount];
			// Fill linePC with pc positions from all interpreter frames.
			// Start from the most nested frame
			int linePCIndex = interpreterFrameCount;
			for (int i_1 = array.Length; i_1 != 0; )
			{
				--i_1;
				Interpreter.CallFrame frame = array[i_1];
				while (frame != null)
				{
					--linePCIndex;
					linePC[linePCIndex] = frame.pcSourceLineStart;
					frame = frame.parentFrame;
				}
			}
			if (linePCIndex != 0)
			{
				Kit.CodeBug();
			}
			ex.interpreterStackInfo = array;
			ex.interpreterLineData = linePC;
		}
Exemplo n.º 7
0
		public string GetPatchedStack(RhinoException ex, string nativeStackTrace)
		{
			string tag = "org.mozilla.javascript.Interpreter.interpretLoop";
			StringBuilder sb = new StringBuilder(nativeStackTrace.Length + 1000);
			string lineSeparator = SecurityUtilities.GetSystemProperty("line.separator");
			Interpreter.CallFrame[] array = (Interpreter.CallFrame[])ex.interpreterStackInfo;
			int[] linePC = ex.interpreterLineData;
			int arrayIndex = array.Length;
			int linePCIndex = linePC.Length;
			int offset = 0;
			while (arrayIndex != 0)
			{
				--arrayIndex;
				int pos = nativeStackTrace.IndexOf(tag, offset);
				if (pos < 0)
				{
					break;
				}
				// Skip tag length
				pos += tag.Length;
				// Skip until the end of line
				for (; pos != nativeStackTrace.Length; ++pos)
				{
					char c = nativeStackTrace[pos];
					if (c == '\n' || c == '\r')
					{
						break;
					}
				}
				sb.Append(Sharpen.Runtime.Substring(nativeStackTrace, offset, pos));
				offset = pos;
				Interpreter.CallFrame frame = array[arrayIndex];
				while (frame != null)
				{
					if (linePCIndex == 0)
					{
						Kit.CodeBug();
					}
					--linePCIndex;
					InterpreterData idata = frame.idata;
					sb.Append(lineSeparator);
					sb.Append("\tat script");
					if (idata.itsName != null && idata.itsName.Length != 0)
					{
						sb.Append('.');
						sb.Append(idata.itsName);
					}
					sb.Append('(');
					sb.Append(idata.itsSourceFile);
					int pc = linePC[linePCIndex];
					if (pc >= 0)
					{
						// Include line info only if available
						sb.Append(':');
						sb.Append(GetIndex(idata.itsICode, pc));
					}
					sb.Append(')');
					frame = frame.parentFrame;
				}
			}
			sb.Append(Sharpen.Runtime.Substring(nativeStackTrace, offset));
			return sb.ToString();
		}
Exemplo n.º 8
0
		public void SetStack(object value)
		{
			if (stackProvider != null)
			{
				stackProvider = null;
				Delete("stack");
			}
			Put("stack", this, value);
		}
Exemplo n.º 9
0
		public void SetStackProvider(RhinoException re)
		{
			// We go some extra miles to make sure the stack property is only
			// generated on demand, is cached after the first access, and is
			// overwritable like an ordinary property. Hence this setup with
			// the getter and setter below.
			if (stackProvider == null)
			{
				stackProvider = re;
				try
				{
					DefineProperty("stack", null, typeof(NativeError).GetMethod("getStack"), typeof(NativeError).GetMethod("setStack", typeof(object)), 0);
				}
				catch (MissingMethodException nsm)
				{
					// should not happen
					throw new Exception(nsm);
				}
			}
		}
Exemplo n.º 10
0
		public virtual IList<string> GetScriptStack(RhinoException ex)
		{
			throw new NotSupportedException();
		}
Exemplo n.º 11
0
		public virtual string GetPatchedStack(RhinoException ex, string nativeStackTrace)
		{
			throw new NotSupportedException();
		}
Exemplo n.º 12
0
		public virtual void CaptureStackInfo(RhinoException ex)
		{
			throw new NotSupportedException();
		}