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
parent d7f0896429
commit 75ae8940c1
10 changed files with 102 additions and 14 deletions

View File

@ -51,9 +51,13 @@ public class EcmaError extends RuntimeException {
* *
* @param nativeError the NativeError object constructed for this error * @param nativeError the NativeError object constructed for this error
*/ */
public EcmaError(NativeError nativeError) { public EcmaError(NativeError nativeError, String sourceName,
int lineNumber)
{
super("EcmaError"); super("EcmaError");
errorObject = nativeError; errorObject = nativeError;
this.sourceName = sourceName;
this.lineNumber = lineNumber;
} }
/** /**
@ -91,6 +95,14 @@ public class EcmaError extends RuntimeException {
return errorObject.getMessage(); return errorObject.getMessage();
} }
public String getSourceName() {
return sourceName;
}
public int getLineNumber() {
return lineNumber;
}
/** /**
* Get the error object corresponding to this exception. * Get the error object corresponding to this exception.
*/ */
@ -99,4 +111,6 @@ public class EcmaError extends RuntimeException {
} }
private NativeError errorObject; private NativeError errorObject;
private String sourceName;
private int lineNumber;
} }

View File

@ -454,6 +454,24 @@ public class NativeGlobal {
String error, String error,
String message, String message,
Object scope) 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; Scriptable scopeObject;
try { try {
@ -466,7 +484,8 @@ public class NativeGlobal {
Object args[] = { message }; Object args[] = { message };
try { try {
Object errorObject = cx.newObject(scopeObject, error, args); Object errorObject = cx.newObject(scopeObject, error, args);
return new EcmaError((NativeError)errorObject); return new EcmaError((NativeError)errorObject, sourceName,
lineNumber);
} }
catch (PropertyException x) { catch (PropertyException x) {
throw new RuntimeException(x.toString()); throw new RuntimeException(x.toString());

View File

@ -1305,8 +1305,8 @@ public class TokenStream {
if (scope != null) { if (scope != null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError", Context.getContext(), "SyntaxError",
message, message, scope, getSourceName(),
scope); getLineno());
} else { } else {
flags |= TSF_ERROR; flags |= TSF_ERROR;
Context.reportError(message, getSourceName(), Context.reportError(message, getSourceName(),

View File

@ -89,6 +89,9 @@ msg.format3 =\
msg.uncaughtJSException =\ msg.uncaughtJSException =\
uncaught JavaScript exception: {0} uncaught JavaScript exception: {0}
msg.uncaughtJSExceptionLine =\
uncaught JavaScript exception ("{0}", line {1}): {2}
msg.jsc.usage =\ msg.jsc.usage =\
Didn''t understand "{0}". \n\ Didn''t understand "{0}". \n\
Valid arguments are: \n\ Valid arguments are: \n\

View File

@ -360,9 +360,17 @@ public class Main {
we.printStackTrace(); we.printStackTrace();
} }
catch (EcmaError ee) { catch (EcmaError ee) {
Context.reportError(ToolErrorReporter.getMessage( if (ee.getSourceName() != null) {
"msg.uncaughtJSException", Object[] args = { ee.getSourceName(),
ee.toString())); 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) { catch (EvaluatorException ee) {
// Already printed message, so just fall through. // Already printed message, so just fall through.

View File

@ -51,9 +51,13 @@ public class EcmaError extends RuntimeException {
* *
* @param nativeError the NativeError object constructed for this error * @param nativeError the NativeError object constructed for this error
*/ */
public EcmaError(NativeError nativeError) { public EcmaError(NativeError nativeError, String sourceName,
int lineNumber)
{
super("EcmaError"); super("EcmaError");
errorObject = nativeError; errorObject = nativeError;
this.sourceName = sourceName;
this.lineNumber = lineNumber;
} }
/** /**
@ -91,6 +95,14 @@ public class EcmaError extends RuntimeException {
return errorObject.getMessage(); return errorObject.getMessage();
} }
public String getSourceName() {
return sourceName;
}
public int getLineNumber() {
return lineNumber;
}
/** /**
* Get the error object corresponding to this exception. * Get the error object corresponding to this exception.
*/ */
@ -99,4 +111,6 @@ public class EcmaError extends RuntimeException {
} }
private NativeError errorObject; private NativeError errorObject;
private String sourceName;
private int lineNumber;
} }

View File

@ -454,6 +454,24 @@ public class NativeGlobal {
String error, String error,
String message, String message,
Object scope) 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; Scriptable scopeObject;
try { try {
@ -466,7 +484,8 @@ public class NativeGlobal {
Object args[] = { message }; Object args[] = { message };
try { try {
Object errorObject = cx.newObject(scopeObject, error, args); Object errorObject = cx.newObject(scopeObject, error, args);
return new EcmaError((NativeError)errorObject); return new EcmaError((NativeError)errorObject, sourceName,
lineNumber);
} }
catch (PropertyException x) { catch (PropertyException x) {
throw new RuntimeException(x.toString()); throw new RuntimeException(x.toString());

View File

@ -1305,8 +1305,8 @@ public class TokenStream {
if (scope != null) { if (scope != null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError", Context.getContext(), "SyntaxError",
message, message, scope, getSourceName(),
scope); getLineno());
} else { } else {
flags |= TSF_ERROR; flags |= TSF_ERROR;
Context.reportError(message, getSourceName(), Context.reportError(message, getSourceName(),

View File

@ -89,6 +89,9 @@ msg.format3 =\
msg.uncaughtJSException =\ msg.uncaughtJSException =\
uncaught JavaScript exception: {0} uncaught JavaScript exception: {0}
msg.uncaughtJSExceptionLine =\
uncaught JavaScript exception ("{0}", line {1}): {2}
msg.jsc.usage =\ msg.jsc.usage =\
Didn''t understand "{0}". \n\ Didn''t understand "{0}". \n\
Valid arguments are: \n\ Valid arguments are: \n\

View File

@ -360,9 +360,17 @@ public class Main {
we.printStackTrace(); we.printStackTrace();
} }
catch (EcmaError ee) { catch (EcmaError ee) {
Context.reportError(ToolErrorReporter.getMessage( if (ee.getSourceName() != null) {
"msg.uncaughtJSException", Object[] args = { ee.getSourceName(),
ee.toString())); 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) { catch (EvaluatorException ee) {
// Already printed message, so just fall through. // Already printed message, so just fall through.