зеркало из https://github.com/mozilla/pjs.git
Get filename and line number into uncaught exception reports.
This commit is contained in:
Родитель
f5d74f8077
Коммит
272cd30a80
|
@ -51,9 +51,13 @@ public class EcmaError extends RuntimeException {
|
|||
*
|
||||
* @param nativeError the NativeError object constructed for this error
|
||||
*/
|
||||
public EcmaError(NativeError nativeError) {
|
||||
public EcmaError(NativeError nativeError, String sourceName,
|
||||
int lineNumber)
|
||||
{
|
||||
super("EcmaError");
|
||||
errorObject = nativeError;
|
||||
this.sourceName = sourceName;
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +95,14 @@ public class EcmaError extends RuntimeException {
|
|||
return errorObject.getMessage();
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error object corresponding to this exception.
|
||||
*/
|
||||
|
@ -99,4 +111,6 @@ public class EcmaError extends RuntimeException {
|
|||
}
|
||||
|
||||
private NativeError errorObject;
|
||||
private String sourceName;
|
||||
private int lineNumber;
|
||||
}
|
||||
|
|
|
@ -454,6 +454,24 @@ public class NativeGlobal {
|
|||
String error,
|
||||
String message,
|
||||
Object scope)
|
||||
{
|
||||
int[] linep = { 0 };
|
||||
String filename = cx.getSourcePositionFromStack(linep);
|
||||
return constructError(cx, error, message, scope,
|
||||
filename, linep[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The NativeError functions
|
||||
*
|
||||
* See ECMA 15.11.6
|
||||
*/
|
||||
public static EcmaError constructError(Context cx,
|
||||
String error,
|
||||
String message,
|
||||
Object scope,
|
||||
String sourceName,
|
||||
int lineNumber)
|
||||
{
|
||||
Scriptable scopeObject;
|
||||
try {
|
||||
|
@ -466,7 +484,8 @@ public class NativeGlobal {
|
|||
Object args[] = { message };
|
||||
try {
|
||||
Object errorObject = cx.newObject(scopeObject, error, args);
|
||||
return new EcmaError((NativeError)errorObject);
|
||||
return new EcmaError((NativeError)errorObject, sourceName,
|
||||
lineNumber);
|
||||
}
|
||||
catch (PropertyException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
|
|
|
@ -1305,8 +1305,8 @@ public class TokenStream {
|
|||
if (scope != null) {
|
||||
throw NativeGlobal.constructError(
|
||||
Context.getContext(), "SyntaxError",
|
||||
message,
|
||||
scope);
|
||||
message, scope, getSourceName(),
|
||||
getLineno());
|
||||
} else {
|
||||
flags |= TSF_ERROR;
|
||||
Context.reportError(message, getSourceName(),
|
||||
|
|
|
@ -89,6 +89,9 @@ msg.format3 =\
|
|||
msg.uncaughtJSException =\
|
||||
uncaught JavaScript exception: {0}
|
||||
|
||||
msg.uncaughtJSExceptionLine =\
|
||||
uncaught JavaScript exception ("{0}", line {1}): {2}
|
||||
|
||||
msg.jsc.usage =\
|
||||
Didn''t understand "{0}". \n\
|
||||
Valid arguments are: \n\
|
||||
|
|
|
@ -360,9 +360,17 @@ public class Main {
|
|||
we.printStackTrace();
|
||||
}
|
||||
catch (EcmaError ee) {
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSException",
|
||||
ee.toString()));
|
||||
if (ee.getSourceName() != null) {
|
||||
Object[] args = { ee.getSourceName(),
|
||||
new Integer(ee.getLineNumber()),
|
||||
ee.toString() };
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSExceptionLine", args));
|
||||
} else {
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSException",
|
||||
ee.toString()));
|
||||
}
|
||||
}
|
||||
catch (EvaluatorException ee) {
|
||||
// Already printed message, so just fall through.
|
||||
|
|
|
@ -51,9 +51,13 @@ public class EcmaError extends RuntimeException {
|
|||
*
|
||||
* @param nativeError the NativeError object constructed for this error
|
||||
*/
|
||||
public EcmaError(NativeError nativeError) {
|
||||
public EcmaError(NativeError nativeError, String sourceName,
|
||||
int lineNumber)
|
||||
{
|
||||
super("EcmaError");
|
||||
errorObject = nativeError;
|
||||
this.sourceName = sourceName;
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +95,14 @@ public class EcmaError extends RuntimeException {
|
|||
return errorObject.getMessage();
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error object corresponding to this exception.
|
||||
*/
|
||||
|
@ -99,4 +111,6 @@ public class EcmaError extends RuntimeException {
|
|||
}
|
||||
|
||||
private NativeError errorObject;
|
||||
private String sourceName;
|
||||
private int lineNumber;
|
||||
}
|
||||
|
|
|
@ -454,6 +454,24 @@ public class NativeGlobal {
|
|||
String error,
|
||||
String message,
|
||||
Object scope)
|
||||
{
|
||||
int[] linep = { 0 };
|
||||
String filename = cx.getSourcePositionFromStack(linep);
|
||||
return constructError(cx, error, message, scope,
|
||||
filename, linep[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The NativeError functions
|
||||
*
|
||||
* See ECMA 15.11.6
|
||||
*/
|
||||
public static EcmaError constructError(Context cx,
|
||||
String error,
|
||||
String message,
|
||||
Object scope,
|
||||
String sourceName,
|
||||
int lineNumber)
|
||||
{
|
||||
Scriptable scopeObject;
|
||||
try {
|
||||
|
@ -466,7 +484,8 @@ public class NativeGlobal {
|
|||
Object args[] = { message };
|
||||
try {
|
||||
Object errorObject = cx.newObject(scopeObject, error, args);
|
||||
return new EcmaError((NativeError)errorObject);
|
||||
return new EcmaError((NativeError)errorObject, sourceName,
|
||||
lineNumber);
|
||||
}
|
||||
catch (PropertyException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
|
|
|
@ -1305,8 +1305,8 @@ public class TokenStream {
|
|||
if (scope != null) {
|
||||
throw NativeGlobal.constructError(
|
||||
Context.getContext(), "SyntaxError",
|
||||
message,
|
||||
scope);
|
||||
message, scope, getSourceName(),
|
||||
getLineno());
|
||||
} else {
|
||||
flags |= TSF_ERROR;
|
||||
Context.reportError(message, getSourceName(),
|
||||
|
|
|
@ -89,6 +89,9 @@ msg.format3 =\
|
|||
msg.uncaughtJSException =\
|
||||
uncaught JavaScript exception: {0}
|
||||
|
||||
msg.uncaughtJSExceptionLine =\
|
||||
uncaught JavaScript exception ("{0}", line {1}): {2}
|
||||
|
||||
msg.jsc.usage =\
|
||||
Didn''t understand "{0}". \n\
|
||||
Valid arguments are: \n\
|
||||
|
|
|
@ -360,9 +360,17 @@ public class Main {
|
|||
we.printStackTrace();
|
||||
}
|
||||
catch (EcmaError ee) {
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSException",
|
||||
ee.toString()));
|
||||
if (ee.getSourceName() != null) {
|
||||
Object[] args = { ee.getSourceName(),
|
||||
new Integer(ee.getLineNumber()),
|
||||
ee.toString() };
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSExceptionLine", args));
|
||||
} else {
|
||||
Context.reportError(ToolErrorReporter.getMessage(
|
||||
"msg.uncaughtJSException",
|
||||
ee.toString()));
|
||||
}
|
||||
}
|
||||
catch (EvaluatorException ee) {
|
||||
// Already printed message, so just fall through.
|
||||
|
|
Загрузка…
Ссылка в новой задаче