| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class DefaultErrorReporter implements ErrorReporter |
| 15 |
{ |
| 16 |
static final DefaultErrorReporter instance = new DefaultErrorReporter(); |
| 17 |
|
| 18 |
private boolean forEval; |
| 19 |
private ErrorReporter chainedReporter; |
| 20 |
|
| 21 |
private DefaultErrorReporter() { } |
| 22 |
|
| 23 |
static ErrorReporter forEval(ErrorReporter reporter) |
| 24 |
{ |
| 25 |
DefaultErrorReporter r = new DefaultErrorReporter(); |
| 26 |
r.forEval = true; |
| 27 |
r.chainedReporter = reporter; |
| 28 |
return r; |
| 29 |
} |
| 30 |
|
| 31 |
public void warning(String message, String sourceURI, int line, |
| 32 |
String lineText, int lineOffset) |
| 33 |
{ |
| 34 |
if (chainedReporter != null) { |
| 35 |
chainedReporter.warning( |
| 36 |
message, sourceURI, line, lineText, lineOffset); |
| 37 |
} else { |
| 38 |
|
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public void error(String message, String sourceURI, int line, |
| 43 |
String lineText, int lineOffset) |
| 44 |
{ |
| 45 |
if (forEval) { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
String error = "SyntaxError"; |
| 50 |
final String TYPE_ERROR_NAME = "TypeError"; |
| 51 |
final String DELIMETER = ": "; |
| 52 |
final String prefix = TYPE_ERROR_NAME + DELIMETER; |
| 53 |
if (message.startsWith(prefix)) { |
| 54 |
error = TYPE_ERROR_NAME; |
| 55 |
message = message.substring(prefix.length()); |
| 56 |
} |
| 57 |
throw ScriptRuntime.constructError(error, message, sourceURI, |
| 58 |
line, lineText, lineOffset); |
| 59 |
} |
| 60 |
if (chainedReporter != null) { |
| 61 |
chainedReporter.error( |
| 62 |
message, sourceURI, line, lineText, lineOffset); |
| 63 |
} else { |
| 64 |
throw runtimeError( |
| 65 |
message, sourceURI, line, lineText, lineOffset); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public EvaluatorException runtimeError(String message, String sourceURI, |
| 70 |
int line, String lineText, |
| 71 |
int lineOffset) |
| 72 |
{ |
| 73 |
if (chainedReporter != null) { |
| 74 |
return chainedReporter.runtimeError( |
| 75 |
message, sourceURI, line, lineText, lineOffset); |
| 76 |
} else { |
| 77 |
return new EvaluatorException( |
| 78 |
message, sourceURI, line, lineText, lineOffset); |
| 79 |
} |
| 80 |
} |
| 81 |
} |