private JsRuntimeException ConvertJavaScriptExceptionToJsRuntimeException( OriginalJsException jsException) { string category = string.Empty; int lineNumber = jsException.LineNumber; int columnNumber = jsException.Column + 1; string message = jsException.Message; OriginalJsValue errorValue = jsException.Error; if (errorValue.IsObject()) { OriginalObjectInstance errorObject = errorValue.AsObject(); OriginalJsValue categoryPropertyValue = errorObject.Get("name"); if (categoryPropertyValue.IsString()) { category = categoryPropertyValue.AsString(); } message = GenerateErrorMessageWithLocation(category, message, jsException.Location.Source, lineNumber, columnNumber); } var jsRuntimeException = new JsRuntimeException(message, EngineName, EngineVersion, jsException) { Category = category, LineNumber = lineNumber, ColumnNumber = columnNumber }; return(jsRuntimeException); }
private JsRuntimeException ConvertJavaScriptExceptionToJsRuntimeException( OriginalJsException jsException) { string category = string.Empty; OriginalJsValue errorValue = jsException.Error; if (errorValue.IsObject()) { OriginalObjectInstance errorObject = errorValue.AsObject(); OriginalJsValue categoryPropertyValue = errorObject.Get("name"); if (categoryPropertyValue.IsString()) { category = categoryPropertyValue.AsString(); } } var jsRuntimeException = new JsRuntimeException(jsException.Message, ENGINE_NAME, ENGINE_VERSION, jsException) { Category = category, LineNumber = jsException.LineNumber, ColumnNumber = jsException.Column, Source = jsException.Source, HelpLink = jsException.HelpLink }; return(jsRuntimeException); }
private static WrapperException WrapJavaScriptException( OriginalJavaScriptException originalJavaScriptException) { WrapperException wrapperException; string message = originalJavaScriptException.Message; if (string.IsNullOrWhiteSpace(message)) { message = "An unknown error occurred"; } string description = message; string type = string.Empty; string documentName = originalJavaScriptException.Location.Source; int lineNumber = originalJavaScriptException.LineNumber; int columnNumber = originalJavaScriptException.Column + 1; OriginalValue errorValue = originalJavaScriptException.Error; if (errorValue.IsObject()) { OriginalObjectInstance errorObject = errorValue.AsObject(); OriginalValue namePropertyValue = errorObject.Get("name"); if (namePropertyValue.IsString()) { type = namePropertyValue.AsString(); } } if (!string.IsNullOrEmpty(type)) { message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName, lineNumber, columnNumber); var wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalJavaScriptException) { Type = type, DocumentName = documentName, LineNumber = lineNumber, ColumnNumber = columnNumber }; wrapperException = wrapperRuntimeException; } else { wrapperException = new WrapperException(message, EngineName, EngineVersion, originalJavaScriptException); } wrapperException.Description = description; return(wrapperException); }
private WrapperRuntimeException WrapRuntimeException(OriginalRuntimeException originalRuntimeException) { WrapperRuntimeException wrapperRuntimeException; string message = originalRuntimeException.Message; if (string.IsNullOrWhiteSpace(message)) { message = "An unknown error occurred"; } string description = message; string type = string.Empty; string documentName = string.Empty; int lineNumber = 0; int columnNumber = 0; string callStack = string.Empty; if (originalRuntimeException is OriginalJavaScriptException) { var originalJavaScriptException = (OriginalJavaScriptException)originalRuntimeException; documentName = originalJavaScriptException.Location.Source; lineNumber = originalJavaScriptException.LineNumber; columnNumber = originalJavaScriptException.Column + 1; OriginalValue errorValue = originalJavaScriptException.Error; if (errorValue.IsObject()) { OriginalObjectInstance errorObject = errorValue.AsObject(); OriginalValue namePropertyValue = errorObject.Get("name"); if (namePropertyValue.IsString()) { type = namePropertyValue.AsString(); } } if (string.IsNullOrEmpty(type)) { type = JsErrorType.Common; } message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName, lineNumber, columnNumber); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalJavaScriptException); } else if (originalRuntimeException is OriginalMemoryLimitExceededException) { type = JsErrorType.Common; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } else if (originalRuntimeException is OriginalRecursionDepthOverflowException) { var originalRecursionException = (OriginalRecursionDepthOverflowException)originalRuntimeException; string[] callChainItems = originalRecursionException.CallChain .Split(new string[] { "->" }, StringSplitOptions.None) ; if (callChainItems.Length > 0) { var stringBuilderPool = StringBuilderPool.Shared; StringBuilder stackBuilder = stringBuilderPool.Rent(); for (int chainItemIndex = callChainItems.Length - 1; chainItemIndex >= 0; chainItemIndex--) { string chainItem = callChainItems[chainItemIndex]; if (chainItem == "anonymous function") { chainItem = "Anonymous function"; } JsErrorHelpers.WriteErrorLocationLine(stackBuilder, chainItem, string.Empty, 0, 0); if (chainItemIndex > 0) { stackBuilder.AppendLine(); } } callStack = stackBuilder.ToString(); stringBuilderPool.Return(stackBuilder); } type = JsErrorType.Range; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, callStack); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRecursionException); } else if (originalRuntimeException is OriginalStatementsCountOverflowException) { type = JsErrorType.Range; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } else if (originalRuntimeException is OriginalExecutionCanceledException) { _cancellationTokenSource = new CancellationTokenSource(); _cancellationConstraint.Reset(_cancellationTokenSource.Token); type = JsErrorType.Common; message = CoreStrings.Runtime_ScriptInterrupted; description = message; wrapperRuntimeException = new WrapperInterruptedException(message, EngineName, EngineVersion, originalRuntimeException); } else { type = JsErrorType.Common; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } wrapperRuntimeException.Description = description; wrapperRuntimeException.Type = type; wrapperRuntimeException.DocumentName = documentName; wrapperRuntimeException.LineNumber = lineNumber; wrapperRuntimeException.ColumnNumber = columnNumber; wrapperRuntimeException.CallStack = callStack; return(wrapperRuntimeException); }
private WrapperRuntimeException WrapRuntimeException(OriginalRuntimeException originalRuntimeException) { WrapperRuntimeException wrapperRuntimeException; string message = originalRuntimeException.Message; if (string.IsNullOrWhiteSpace(message)) { message = "An unknown error occurred"; } string description = message; string type = string.Empty; string documentName = string.Empty; int lineNumber = 0; int columnNumber = 0; string callStack = string.Empty; if (originalRuntimeException is OriginalJavaScriptException) { var originalJavaScriptException = (OriginalJavaScriptException)originalRuntimeException; documentName = originalJavaScriptException.Location.Source; lineNumber = originalJavaScriptException.LineNumber; columnNumber = originalJavaScriptException.Column + 1; ErrorLocationItem[] callStackItems = JintJsErrorHelpers.ParseErrorLocation( originalJavaScriptException.StackTrace); if (callStackItems.Length > 0) { JintJsErrorHelpers.FixErrorLocationItems(callStackItems); callStack = JsErrorHelpers.StringifyErrorLocationItems(callStackItems, true); } OriginalValue errorValue = originalJavaScriptException.Error; if (errorValue.IsObject()) { OriginalObjectInstance errorObject = errorValue.AsObject(); OriginalValue namePropertyValue = errorObject.Get("name"); if (namePropertyValue.IsString()) { type = namePropertyValue.AsString(); } } if (string.IsNullOrEmpty(type)) { type = JsErrorType.Common; } message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, callStack); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalJavaScriptException); } else if (originalRuntimeException is OriginalMemoryLimitExceededException) { type = JsErrorType.Common; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } else if (originalRuntimeException is OriginalRecursionDepthOverflowException) { var originalRecursionException = (OriginalRecursionDepthOverflowException)originalRuntimeException; callStack = JintJsErrorHelpers.ConvertCallChainToStack(originalRecursionException.CallChain); type = JsErrorType.Range; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, callStack); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRecursionException); } else if (originalRuntimeException is OriginalStatementsCountOverflowException) { type = JsErrorType.Range; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } else if (originalRuntimeException is OriginalExecutionCanceledException) { _cancellationTokenSource = new CancellationTokenSource(); _cancellationConstraint.Reset(_cancellationTokenSource.Token); type = JsErrorType.Common; message = CoreStrings.Runtime_ScriptInterrupted; description = message; wrapperRuntimeException = new WrapperInterruptedException(message, EngineName, EngineVersion, originalRuntimeException); } else { type = JsErrorType.Common; message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, string.Empty); wrapperRuntimeException = new WrapperRuntimeException(message, EngineName, EngineVersion, originalRuntimeException); } wrapperRuntimeException.Description = description; wrapperRuntimeException.Type = type; wrapperRuntimeException.DocumentName = documentName; wrapperRuntimeException.LineNumber = lineNumber; wrapperRuntimeException.ColumnNumber = columnNumber; wrapperRuntimeException.CallStack = callStack; return(wrapperRuntimeException); }