1 38 package com.gargoylesoftware.htmlunit.javascript; 39 40 import com.gargoylesoftware.htmlunit.Assert; 41 import org.apache.commons.logging.Log; 42 import org.mozilla.javascript.ErrorReporter; 43 import org.mozilla.javascript.EvaluatorException; 44 45 51 public class StrictErrorReporter implements ErrorReporter { 52 private final Log log_; 53 54 59 public StrictErrorReporter( final Log log ) { 60 Assert.notNull("log", log); 61 log_ = log; 62 } 63 64 65 74 public void warning( 75 final String message, final String sourceName, final int line, 76 final String lineSource, final int lineOffset) { 77 log_.warn(format( "warning", message, sourceName, line, lineSource, lineOffset )); 78 } 79 80 81 90 public void error( 91 final String message, final String sourceName, final int line, 92 final String lineSource, final int lineOffset) { 93 94 log_.error(format( "error", message, sourceName, line, lineSource, lineOffset)); 95 throw new EvaluatorException(message, sourceName, line, lineSource, lineOffset); 96 } 97 98 99 109 public EvaluatorException runtimeError( 110 final String message, final String sourceName, final int line, 111 final String lineSource, final int lineOffset) { 112 113 log_.error(format( "runtimeError", message, sourceName, line, lineSource, lineOffset )); 114 return new EvaluatorException(message, sourceName, line, lineSource, lineOffset); 115 } 116 117 118 private String format( 119 final String prefix, final String message, final String sourceName, 120 final int line, final String lineSource, final int lineOffset) { 121 122 return prefix+": message=["+message+"] sourceName=["+sourceName+"] line=["+line 123 +"] lineSource=["+lineSource+"] lineOffset=["+lineOffset+"]"; 124 } 125 } 126 | Popular Tags |