Example #1
0
        /// <summary>
        /// Creates a new compile or evaluation error
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="ex"></param>
        internal ScriptError(ScriptEngine engine, JScriptException ex)
        {
            if (ex.Line == 0)
            {
                m_Description = ex.Description;

                string[] lines = ex.StackTrace.Replace("\r\n", "\n").Split('\n');

                int    idx  = 0;
                string line = string.Empty;
                for (int i = 1; i < lines.Length; i++)
                {
                    line = lines[i];
                    line = line.Trim();
                    idx  = line.IndexOf(" in " + engine.Id);
                    if (idx != -1)
                    {
                        break;
                    }
                }
                if (line == string.Empty)
                {
                    return;
                }

                line = line.Substring(idx + (" in " + engine.Id).Length + 1);

                idx = line.IndexOf(":");
                if (idx == -1)
                {
                    return;
                }
                string sourceCodeId = line.Substring(0, idx);

                idx = line.IndexOf(" ");
                if (idx == -1)
                {
                    return;
                }
                int lineNo = int.Parse(line.Substring(idx + 1));

                m_LineNo      = lineNo;
                m_Description = m_Description + " in " + sourceCodeId;

                SetSource(engine.GetCodeBlock(sourceCodeId), m_LineNo);
            }
            else
            {
                m_Severity    = ex.Severity;
                m_Description = ex.Description;
                m_LineNo      = ex.Line;
                m_ColumnNo    = ex.Column;

                SetSource(ex.LineText, m_LineNo);
            }
        }
Example #2
0
        private string GetJSErrorMessage(JScriptException jse)//нужно ускорить работу с генерацией сообщение
        {
            if (jse.LineText.IsEmpty())
            {
                return(jse.Message);
            }
            var line  = jse.LineText.Split('\n')[jse.Line - 1];
            var end   = Math.Min(Math.Max(jse.EndColumn, jse.StartColumn), line.Length + 1);
            var start = Math.Max(1, Math.Min(end, jse.StartColumn));

            return(jse.GetFullExceptionText() + " line {0} : '{1}!->{2}<-!{3}'".FormatStr(jse.Line, line.Substring(0, start - 1).TrimStart(), line.Substring(start - 1, end - start), line.Substring(end - 1).TrimEnd()));
        }
Example #3
0
        internal void HandleError(JSError errorId, IndexSpan span, LocationResolver resolver, bool forceToError = false) {
            var error = new JScriptException(errorId, span, resolver);

            if (forceToError) {
                error.IsError = true;
            } else {
                error.IsError = error.Severity < 2;
            }

            if (!OnCompilerError(error)) {

            }
        }
Example #4
0
    /// <summary>
    /// Returns a minified version of a given JavaScript.
    /// </summary>
    /// <param name="resource">JavaScript to be minified</param>
    /// <returns>Minified JavaScript</returns>
    public string Minify(string resource)
    {
        if (String.IsNullOrEmpty(resource))
        {
            return(resource);
        }

        // Reset error
        minificationError = null;
        canRecover        = true;

        try
        {
            JSParser parser = new JSParser(resource);
            parser.CompilerError += parser_CompilerError;

            // Parse the resource
            Block scriptBlock = parser.Parse(null);

            // Get minified code if no error occurs or parser was able to recover
            if ((scriptBlock != null) && ((minificationError == null) || ((minificationError != null) && canRecover)))
            {
                resource = scriptBlock.ToCode();
            }
        }
        catch (JScriptException ex)
        {
            minificationError = ex;
            canRecover        = false;
        }

        if (minificationError != null)
        {
            if (LogMinifierParseError)
            {
                // Log exception to event log if allowed
                EventLogProvider.LogException("JS Compression", "MINIFYJS", minificationError);
            }

            if (!canRecover)
            {
                // Add error info in front of non-minified resource
                resource += "\r\n\r\n// Minification failed (line " + minificationError.Line.ToString() + "): " + minificationError.Message;
            }
        }

        return(resource);
    }
Example #5
0
        internal bool OnCompilerError(JScriptException se) {
            // format the error code
            OnError(
                new JScriptExceptionEventArgs(
                    se,
                    new ContextError(
                        se.IsError,
                        se.Severity,
                        GetSeverityString(se.Severity),
                        se.ErrorCode,
                        se.HelpLink,
                        se.Line,
                        se.Column,
                        se.EndLine,
                        se.EndColumn,
                        se.Message
                    )
                )
            );

            //true means carry on with compilation.
            return se.CanRecover;
        }
 public JScriptExceptionEventArgs(JScriptException exception, ContextError error)
 {
     Error = error;
     Exception = exception;
 }
 private void parser_CompilerError(object sender, JScriptExceptionEventArgs e)
 {
     // Store exception and info if the compiler can recover
     minificationError = e.Exception;
     canRecover = e.Exception.CanRecover;
 }
    /// <summary>
    /// Returns a minified version of a given JavaScript.
    /// </summary>
    /// <param name="resource">JavaScript to be minified</param>
    /// <returns>Minified JavaScript</returns>
    public string Minify(string resource)
    {
        if (String.IsNullOrEmpty(resource))
        {
            return resource;
        }

        // Reset error
        minificationError = null;
        canRecover = true;

        try
        {
            JSParser parser = new JSParser(resource);
            parser.CompilerError += parser_CompilerError;

            // Parse the resource
            Block scriptBlock = parser.Parse(null);

            // Get minified code if no error occurs or parser was able to recover
            if ((scriptBlock != null) && ((minificationError == null) || ((minificationError != null) && canRecover)))
            {
                resource = scriptBlock.ToCode();
            }
        }
        catch (JScriptException ex)
        {
            minificationError = ex;
            canRecover = false;
        }

        if (minificationError != null)
        {
            if (LogMinifierParseError)
            {
                // Log exception to event log if allowed
                EventLogProvider.LogException("JS Compression", "MINIFYJS", minificationError);
            }

            if (!canRecover)
            {
                // Add error info in front of non-minified resource
                resource += "\r\n\r\n// Minification failed (line " + minificationError.Line.ToString() + "): " + minificationError.Message;
            }
        }

        return resource;
    }
Example #9
0
 private void parser_CompilerError(object sender, JScriptExceptionEventArgs e)
 {
     // Store exception and info if the compiler can recover
     minificationError = e.Exception;
     canRecover        = e.Exception.CanRecover;
 }