internal JScriptException(JSError errorNumber, Context context) { this.errorNumber = errorNumber; this.wrappedException = null; this.context = context; this.message = null; }
internal JScriptException(JSError errorNumber, IndexSpan span, LocationResolver resolver) { m_valueObject = null; _span = span; _resolver = resolver; m_errorCode = errorNumber; SetHResult(); }
internal void HandleError(JSError errorId, bool forceToError = false) { if ((errorId != JSError.UndeclaredVariable && errorId != JSError.UndeclaredFunction) || !Document.HasAlreadySeenErrorFor(Code)) { var severity = GetSeverity(errorId); var errorMessage = GetErrorString(errorId); var context = this.ErrorSegment; if (!context.IsNullOrWhiteSpace()) { errorMessage += CommonStrings.ContextSeparator + context; } var error = new UglifyError() { IsError = forceToError || severity < 2, File = Document.FileContext, Severity = severity, Subcategory = UglifyError.GetSubcategory(severity), ErrorNumber = (int)errorId, ErrorCode = "JS{0}".FormatInvariant((int)errorId), StartLine = this.StartLineNumber, StartColumn = this.StartColumn + 1, EndLine = this.EndLineNumber, EndColumn = this.EndColumn + 1, Message = errorMessage, }; Document.HandleError(error); } }
internal JScriptException(JSError errorNumber, Context context) { m_valueObject = Missing.Value; m_context = (context == null ? null : context.Clone()); m_fileContext = (context == null ? null : context.Document.FileContext); m_code = HResult = unchecked((int)(0x800A0000 + (int)errorNumber)); }
internal JScriptException(JSError errorNumber, Context context) { m_valueObject = Missing.Value; m_context = (context == null ? null : context.Clone()); m_fileContext = (context == null ? null : context.FileContext); m_code = HResult = unchecked ((int)(0x800A0000 + (int)errorNumber)); }
internal JScriptException(JSError errorNumber, Context context) { m_valueObject = null; m_context = (context == null ? null : context.Clone()); m_fileContext = (context == null ? null : context.Document.FileContext); m_errorCode = errorNumber; SetHResult(); }
public JScriptException(string message, Exception innerException) : base(message, innerException) { m_valueObject = message; m_context = null; m_fileContext = null; m_errorCode = JSError.UncaughtException; SetHResult(); }
protected ScannerException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } m_errorId = (JSError)Enum.Parse(typeof(JSError), info.GetString("errorid")); }
protected JScriptException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentException(JScript.InternalCompilerError); } m_valueObject = info.GetString("Value"); m_isError = info.GetBoolean("IsError"); m_errorCode = (JSError)info.GetInt32("JSError"); m_canRecover = info.GetBoolean("CanRecover"); }
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)) { } }
/// <summary> /// Return the default severity for a given JSError value /// guide: 0 == there will be a run-time error if this code executes /// 1 == the programmer probably did not intend to do this /// 2 == this can lead to cross-browser or future problems. /// 3 == this can lead to performance problems /// 4 == this is just not right /// </summary> /// <param name="errorCode">error code</param> /// <returns>severity</returns> private static int GetSeverity(JSError errorCode) { switch (errorCode) { case JSError.AmbiguousCatchVar: case JSError.AmbiguousNamedFunctionExpression: case JSError.ExportNotAtModuleLevel: case JSError.NumericOverflow: case JSError.StrictComparisonIsAlwaysTrueOrFalse: return(1); case JSError.ArrayLiteralTrailingComma: case JSError.DuplicateCatch: case JSError.DuplicateConstantDeclaration: case JSError.DuplicateLexicalDeclaration: case JSError.HighSurrogate: case JSError.KeywordUsedAsIdentifier: case JSError.LowSurrogate: case JSError.MisplacedFunctionDeclaration: case JSError.ObjectLiteralKeyword: return(2); case JSError.ArgumentNotReferenced: case JSError.DuplicateName: case JSError.FunctionNotReferenced: case JSError.UndeclaredFunction: case JSError.UndeclaredVariable: case JSError.VariableDefinedNotReferenced: return(3); case JSError.FunctionNameMustBeIdentifier: case JSError.ObjectConstructorTakesNoArguments: case JSError.OctalLiteralsDeprecated: case JSError.NewLineNotAllowed: case JSError.NoModuleExport: case JSError.NumericMaximum: case JSError.NumericMinimum: case JSError.SemicolonInsertion: case JSError.StatementBlockExpected: case JSError.SuspectAssignment: case JSError.SuspectEquality: case JSError.SuspectSemicolon: case JSError.UnusedLabel: case JSError.WithNotRecommended: return(4); default: // all others return(0); } }
// constructor public ContextError(bool isError, int severity, string subcategory, JSError errorCode, string helpKeyword, int startLine, int startColumn, int endLine, int endColumn, string message) { // transfer the values as-is IsError = isError; Severity = severity; Subcategory = subcategory; ErrorCode = errorCode; HelpKeyword = helpKeyword; StartLine = startLine; StartColumn = startColumn; EndLine = endLine; EndColumn = endColumn; Message = message; }
internal JScriptException(Object value) { this.wrappedException = value; if (value is StackOverflowException) { this.errorNumber = JSError.OutOfStack; } else if (value is OutOfMemoryException) { this.errorNumber = JSError.OutOfMemory; } else { this.errorNumber = JSError.UncaughtException; } this.context = null; this.message = null; }
// Parse an invalid number. private void TestInvalidNum(String value, JSError expected) { JSScanner scanner; Context token; scanner = JSScannerTest.TestCreateScanner(value); token = JSScannerTest.TestGetTokenContext(scanner); try { scanner.GetNextToken(); Fail("TestInvalidNum[" + value + "] (1)"); } catch (Exception e) { AssertEquals("TestNum[" + value + "] (2)", expected, JSScannerTest.TestExtractError(e)); } }
internal JScriptException(Object value) { this.wrappedException = value; if(value is StackOverflowException) { this.errorNumber = JSError.OutOfStack; } else if(value is OutOfMemoryException) { this.errorNumber = JSError.OutOfMemory; } else { this.errorNumber = JSError.UncaughtException; } this.context = null; this.message = null; }
internal void HandleError(JSError errorId, bool forceToError) { if ((errorId != JSError.UndeclaredVariable && errorId != JSError.UndeclaredFunction) || !Document.HasAlreadySeenErrorFor(Code)) { var error = new JScriptException(errorId, this); if (forceToError) { error.IsError = true; } else { error.IsError = error.Severity < 2; } Document.HandleError(error); } }
/// <summary> /// Return the default severity for a given JSError value /// guide: 0 == there will be a run-time error if this code executes /// 1 == the programmer probably did not intend to do this /// 2 == this can lead to cross-browser of future problems. /// 3 == this can lead to performance problems /// 4 == this is just not right /// </summary> /// <param name="errorCode">error code</param> /// <returns>severity</returns> public static int GetSeverity(JSError errorCode) { switch (errorCode) { case JSError.AmbiguousCatchVar: case JSError.AmbiguousNamedFunctionExpression: case JSError.NumericOverflow: case JSError.StrictComparisonIsAlwaysTrueOrFalse: return 1; case JSError.DuplicateCatch: case JSError.DuplicateConstantDeclaration: case JSError.DuplicateLexicalDeclaration: case JSError.KeywordUsedAsIdentifier: case JSError.MisplacedFunctionDeclaration: case JSError.ObjectLiteralKeyword: return 2; case JSError.ArgumentNotReferenced: case JSError.DuplicateName: case JSError.FunctionNotReferenced: case JSError.UndeclaredFunction: case JSError.UndeclaredVariable: case JSError.VariableDefinedNotReferenced: return 3; case JSError.StatementBlockExpected: case JSError.SuspectAssignment: case JSError.SuspectSemicolon: case JSError.SuspectEquality: case JSError.WithNotRecommended: case JSError.ObjectConstructorTakesNoArguments: case JSError.NumericMaximum: case JSError.NumericMinimum: case JSError.OctalLiteralsDeprecated: case JSError.FunctionNameMustBeIdentifier: case JSError.SemicolonInsertion: return 4; default: // all others return 0; } }
internal void HandleError(JSError errorId, string message, bool treatAsError) { if ((errorId != JSError.UndeclaredVariable) || !this.document.HasAlreadySeenErrorFor(this.GetCode())) { JScriptException error = new JScriptException(errorId, this); if (message != null) { error.value = message; } if (treatAsError) { error.isError = treatAsError; } int severity = error.Severity; if (severity < this.errorReported) { this.document.HandleError(error); this.errorReported = severity; } } }
internal void HandleError(JSError errorId, String message, bool treatAsError) { if ((errorId == JSError.UndeclaredVariable || errorId == JSError.UndeclaredFunction) && Document.HasAlreadySeenErrorFor(Code)) { return; } JScriptException error = new JScriptException(errorId, this); if (message != null) { error.Value = message; } if (treatAsError) { error.IsError = treatAsError; } int sev = error.Severity; if (sev < m_errorReported) { Document.HandleError(error); m_errorReported = sev; } }
private int code; // This is same as base.HResult. We have this so that the debuugger can get the // error code without doing a func-eval ( to evaluate the HResult property ) public JScriptException(JSError errorNumber) :this(errorNumber, null){ }
protected JScriptException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentException(JScript.InternalCompilerError); } m_valueObject = info.GetString("Value"); m_isError = info.GetBoolean("IsError"); m_errorCode = (JSError)info.GetInt32("JSError"); m_canRecover = info.GetBoolean("CanRecover"); m_fileContext = info.GetString("FileContext"); }
internal ScannerException(JSError errorId) : base ("Syntax Error"){ m_errorId = errorId; }
public ScannerException() { m_errorId = JSError.SyntaxError; }
internal JScriptException (string user_err) { error_number = JSError.NoError; user_error = user_err; }
public JScriptException (JSError errorNumber) { error_number = errorNumber; }
//--------------------------------------------------------------------------------------- // ForceReportInfo // // Generate a parser error (info), does not change the error state in the parse //--------------------------------------------------------------------------------------- private static void ForceReportInfo(Context context, JSError errorId) { Debug.Assert(context != null); context.HandleError(errorId); }
internal void HandleError(JSError errorId) { HandleError(errorId, null, false); }
public JScriptException(JSError errorNumber) { }
public JScriptException(JSError errorNumber) : this(errorNumber, null) { }
//--------------------------------------------------------------------------------------- // EOFError // // Create a context for EOF error. The created context points to the end of the source // code. Assume the the scanner actually reached the end of file //--------------------------------------------------------------------------------------- private void EOFError(JSError errorId) { Context eofCtx = m_sourceContext.Clone(); eofCtx.StartLineNumber = m_scanner.CurrentLine; eofCtx.EndLineNumber = eofCtx.StartLineNumber; eofCtx.StartLinePosition = m_scanner.StartLinePosition; eofCtx.EndLinePosition = eofCtx.StartLinePosition; eofCtx.StartPosition = m_sourceContext.EndPosition; eofCtx.EndPosition++; eofCtx.HandleError(errorId); }
public JScriptException(JSError errorNumber) {}
//--------------------------------------------------------------------------------------- // ForceReportInfo // // Generate a parser error (info), does not change the error state in the parse //--------------------------------------------------------------------------------------- private void ForceReportInfo(JSError errorId) { ForceReportInfo(m_currentToken.Clone(), errorId); }
private void HandleError(JSError error){ if (!this.IsAuthoring) this.currentToken.HandleError(error); }
public static string GetErrorString(JSError errorCode) { return(JScript.ResourceManager.GetString(errorCode.ToString(), JScript.Culture)); }
internal JScriptException (JSError errorNumber, string extraData) { error_number = errorNumber; extra_data = extraData; }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // The function is told whether or not next call to GetToken() should return the same // token or not //--------------------------------------------------------------------------------------- private void ReportError(JSError errorId, Context context, bool skipToken) { Debug.Assert(context != null); int previousSeverity = m_severity; m_severity = (new JScriptException(errorId)).Severity; // EOF error is special and it's the last error we can possibly get if (JSToken.EndOfFile == context.Token) EOFError(errorId); // EOF context is special else { // report the error if not in error condition and the // error for this token is not worse than the one for the // previous token if (m_goodTokensProcessed > 0 || m_severity < previousSeverity) context.HandleError(errorId); // reset proper info if (skipToken) m_goodTokensProcessed = -1; else { m_errorToken = m_currentToken; m_goodTokensProcessed = 0; } } }
internal ScannerException(JSError errorId) : base(s_syntaxErrorMsg) { m_errorId = errorId; }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // When no context is provided the token is missing so the context is the current position // The function is told whether or not next call to GetToken() should return the same // token or not //--------------------------------------------------------------------------------------- private void ReportError(JSError errorId, bool skipToken) { // get the current position token Context context = m_currentToken.Clone(); context.EndPosition = context.StartPosition + 1; ReportError(errorId, context, skipToken); }
public ScannerException(string message, Exception innerException) : base(message, innerException) { m_errorId = JSError.SyntaxError; }
//--------------------------------------------------------------------------------------- // ReportError // // Generate a parser error. // When no context is provided the token is missing so the context is the current position //--------------------------------------------------------------------------------------- private void ReportError(JSError errorId) { ReportError(errorId, false); }
public ErrorResult(string message, SourceSpan span, JSError errorCode) { _message = message; _span = span; _errorCode = errorCode; }
internal JScriptException(string user_err) { error_number = JSError.NoError; user_error = user_err; }
internal JScriptException(JSError errorNumber, string extraData) { error_number = errorNumber; extra_data = extraData; }
public JScriptException(JSError errorNumber) { error_number = errorNumber; }
internal JScriptException(JSError errorNumber, Context context){ this.value = Missing.Value; this.context = context; this.code = this.HResult = unchecked((int)(0x800A0000 + (int)errorNumber)); }
// Parse an invalid number. private void TestInvalidNum(String value, JSError expected) { JSScanner scanner; Context token; scanner = JSScannerTest.TestCreateScanner(value); token = JSScannerTest.TestGetTokenContext(scanner); try { scanner.GetNextToken(); Fail("TestInvalidNum[" + value + "] (1)"); } catch(Exception e) { AssertEquals("TestNum[" + value + "] (2)", expected, JSScannerTest.TestExtractError(e)); } }
private void HandleError(JSError error) { m_currentToken.EndPosition = m_currentPos; m_currentToken.EndLinePosition = StartLinePosition; m_currentToken.EndLineNumber = CurrentLine; m_currentToken.HandleError(error); }
internal void HandleError(JSError errorId, bool treatAsError) { HandleError(errorId, null, treatAsError); }
public void RunErrorTest(params JSError[] expectedErrorArray) { // open the stack trace for this call StackTrace stackTrace = new StackTrace(); string testClass = null; string testName = null; // save the name of the current method (RunTest) string currentMethodName = MethodInfo.GetCurrentMethod().Name; // loop from the previous frame up until we get a method name that is not the // same as the current method name for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx) { // get the frame StackFrame stackFrame = stackTrace.GetFrame(ndx); // we have different entry points with the same name -- we're interested // in the first one that ISN'T the same name as our method MethodBase methodBase = stackFrame.GetMethod(); if (methodBase.Name != currentMethodName) { // the calling method's name is the test name - we use this as-is for the output file name // and we use any portion before an underscore as the input file testName = methodBase.Name; // get the method's class - we use this as the subfolder under input/output/expected testClass = methodBase.DeclaringType.Name; break; } } // we definitely should be able to find a function on the stack frame that // has a different name than this function, but just in case... Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame"); // the input file is the portion of the test name before the underscore (if any) string inputFile = testName.Split('_')[0]; // get the input path string inputPath = GetJsPath( m_inputFolder, testClass, inputFile, false ); Assert.IsTrue(File.Exists(inputPath), "Input File does not exist: {0}", inputPath); // read the input JS string jsSource; using (StreamReader reader = new StreamReader(inputPath, true)) { jsSource = reader.ReadToEnd(); } Trace.Write("INPUT FILE: "); Trace.WriteLine(inputPath); Trace.WriteLine(jsSource); /*int expectedErrorCode = (int)(0x800A0000 + (int)expectedError); * Trace.WriteLine(string.Empty); * Trace.WriteLine(string.Format("Expecting error 0x{0:X}", expectedErrorCode));*/ bool testPassed = true; List <JSError> expectedErrorList = new List <JSError>(expectedErrorArray); ErrorTrap errorTrap = new ErrorTrap(); string crunchedCode = errorTrap.RunTest(jsSource); JScriptException[] errors = errorTrap.Errors; Trace.WriteLine(string.Empty); Trace.WriteLine("---ERRORS---"); Trace.Indent(); foreach (JScriptException ex in errors) { // log the error Trace.WriteLine(string.Empty); Trace.WriteLine(string.Format("Error 0x{0:X} at Line {1}, Column {2}: {3}", ex.Error, ex.Line, ex.Column, ex.ErrorSegment)); Trace.Indent(); Trace.WriteLine(ex.Message); JSError errorCode = (JSError)(ex.Error & 0xffff); int index = expectedErrorList.IndexOf(errorCode); if (index >= 0) { // expected error -- remove it from the list so we can tell what we're missing later expectedErrorList.RemoveAt(index); } else { // unexpected error testPassed = false; Trace.WriteLine("UNEXPECTED"); } Trace.Unindent(); } Trace.Unindent(); // the list should be empty now -- if it isn't, then there was an expected error that didn't happen if (expectedErrorList.Count > 0) { testPassed = false; Trace.WriteLine(string.Empty); Trace.WriteLine("---MISSING ERRORS---"); Trace.Indent(); foreach (JSError jsError in expectedErrorList) { Trace.WriteLine(jsError.ToString()); } Trace.Unindent(); } if (!testPassed) { Trace.WriteLine("UNEXPECTED ERROR RESULTS"); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Resulting Code---"); Trace.WriteLine(crunchedCode); // compute the path to the expected file string expectedPath = GetJsPath( m_expectedFolder, testClass, testName, false ); if (File.Exists(expectedPath)) { string expectedCode; using (StreamReader reader = new StreamReader(expectedPath, true)) { expectedCode = reader.ReadToEnd(); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Expected Code---"); Trace.WriteLine(expectedCode); if (string.CompareOrdinal(expectedCode, crunchedCode) != 0) { Trace.WriteLine("EXPECTED OUTPUT IS DIFFERENT"); testPassed = false; } } Assert.IsTrue(testPassed, "Test failed"); }