Esempio n. 1
0
        private JsRuntimeException ConvertJavascriptExceptionToJsRuntimeException(
            OriginalJsException jsException)
        {
            var jsRuntimeException = new JsRuntimeException(jsException.Message, ENGINE_NAME, ENGINE_VERSION,
                                                            jsException)
            {
                Category       = jsException.Name,
                LineNumber     = jsException.LineNumber,
                ColumnNumber   = 0,
                SourceFragment = jsException.SourcePath,
                Source         = jsException.Source,
                HelpLink       = jsException.HelpLink
            };

            return(jsRuntimeException);
        }
        private JsRuntimeException ConvertJavascriptExceptionToJsRuntimeException(
            OriginalJsException jsException)
        {
            var    jsError = jsException.ErrorObject as OriginalErrorInstance;
            string message = jsException.Message;

            if (jsError != null)
            {
                message = !string.IsNullOrEmpty(jsError.Stack) ? jsError.Stack : jsError.Message;
            }

            var jsRuntimeException = new JsRuntimeException(message, EngineName, EngineVersion,
                                                            jsException)
            {
                Category       = jsException.Name,
                LineNumber     = jsException.LineNumber,
                ColumnNumber   = 0,
                SourceFragment = string.Empty
            };

            return(jsRuntimeException);
        }
        private static WrapperException WrapJavaScriptException(
            OriginalJavaScriptException originalJavaScriptException)
        {
            WrapperException wrapperException;
            string           message = originalJavaScriptException.Message;
            string           messageWithCallStack = string.Empty;
            string           description          = message;
            string           type         = originalJavaScriptException.Name;
            string           documentName = originalJavaScriptException.SourcePath ?? string.Empty;
            int    lineNumber             = originalJavaScriptException.LineNumber;
            string callStack = string.Empty;

            var errorValue = originalJavaScriptException.ErrorObject as OriginalErrorInstance;

            if (errorValue != null)
            {
                messageWithCallStack = errorValue.Stack;
                description          = !string.IsNullOrEmpty(errorValue.Message) ?
                                       errorValue.Message : description;
            }

            if (!string.IsNullOrEmpty(type))
            {
                WrapperScriptException wrapperScriptException;
                if (type == JsErrorType.Syntax)
                {
                    message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, documentName,
                                                                        lineNumber, 0);

                    wrapperScriptException = new WrapperCompilationException(message, EngineName, EngineVersion,
                                                                             originalJavaScriptException);
                }
                else
                {
                    if (message.Length < messageWithCallStack.Length)
                    {
                        string rawCallStack = messageWithCallStack
                                              .TrimStart(message)
                                              .TrimStart(new char[] { '\n', '\r' })
                        ;
                        ErrorLocationItem[] callStackItems = JsErrorHelpers.ParseErrorLocation(rawCallStack);

                        if (callStackItems.Length > 0)
                        {
                            FixCallStackItems(callStackItems);
                            callStack = JsErrorHelpers.StringifyErrorLocationItems(callStackItems);

                            if (string.IsNullOrWhiteSpace(documentName))
                            {
                                documentName = callStackItems[0].DocumentName;
                            }
                        }
                    }

                    message = JsErrorHelpers.GenerateScriptErrorMessage(type, description, callStack);

                    wrapperScriptException = new WrapperRuntimeException(message, EngineName, EngineVersion,
                                                                         originalJavaScriptException)
                    {
                        CallStack = callStack
                    };
                }
                wrapperScriptException.Type         = type;
                wrapperScriptException.DocumentName = documentName;
                wrapperScriptException.LineNumber   = lineNumber;

                wrapperException = wrapperScriptException;
            }
            else
            {
                wrapperException = new WrapperException(message, EngineName, EngineVersion,
                                                        originalJavaScriptException);
            }

            wrapperException.Description = description;

            return(wrapperException);
        }