Get filename and line number into uncaught exception reports.

This commit is contained in:
norris%netscape.com 1999-10-26 17:06:12 +00:00
Родитель f5d74f8077
Коммит 272cd30a80
10 изменённых файлов: 102 добавлений и 14 удалений

Просмотреть файл

@ -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.