Added a call to js_ErrorToException to

the compile-error reporting mechanism,
providing a way to associate exceptions
(very likely SyntaxError exceptions)
with compile-time errors.

(Hopefully this is temporary, as I'd
prefer one central place in the
error-reporting process to put the
js_ErrorToException call.)

Also changed the error reporter in js.c
to only ignore error reports marked with
the JSREPORT_EXCEPTION advisory flag when
the error occurs during javascript execution.

If it's at the toplevel compilation
level, then the error is still reported
(and the exception discarded.)

The api is feeling slightly dirtier, but
it still seems like the best
compromise...
This commit is contained in:
mccabe%netscape.com 1998-08-31 08:17:40 +00:00
Родитель a6a41f773e
Коммит 38dfa16122
2 изменённых файлов: 28 добавлений и 3 удалений

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

@ -154,6 +154,12 @@ Process(JSContext *cx, JSObject *obj, char *filename)
}
} while (ok && !(ts->flags & TSF_EOF) && CG_OFFSET(&cg) == 0);
if (ok) {
/*
* Clear any pending exception, either from previous failed
* compiles, or from the last round of execution.
*/
JS_ClearPendingException(cx);
script = js_NewScriptFromCG(cx, &cg, NULL);
if (script) {
if (JS_ExecuteScript(cx, obj, script, &result) &&
@ -186,7 +192,6 @@ Process(JSContext *cx, JSObject *obj, char *filename)
} else {
fprintf(stderr, "Uncaught javascript exception\n");
}
JS_ClearPendingException(cx);
}
JS_DestroyScript(cx, script);
}
@ -1160,10 +1165,11 @@ my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
/*
* Conditionally ignore reported warnings, and ignore error reports for
* which a JavaScript exception has been thrown.
* which a JavaScript exception has been thrown, except when we're in
* a toplevel compile.
*/
if ((JSREPORT_IS_WARNING(report->flags) && !reportWarnings) ||
JSREPORT_IS_EXCEPTION(report->flags)) {
(JSREPORT_IS_EXCEPTION(report->flags) && cx->interpLevel > 0)) {
return;
}

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

@ -38,6 +38,7 @@
#include "jsatom.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsexn.h"
#include "jsnum.h"
#include "jsopcode.h"
#include "jsregexp.h"
@ -580,7 +581,25 @@ js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, uintN flags,
report.uclinebuf = ts->linebuf.base;
report.uctokenptr = ts->token.ptr;
report.flags = flags;
/*
* If there's a runtime exception type associated with this error
* number, set that as the pending exception. For errors occuring at
* compile time, this is very likely to be a JSEXN_SYNTAXERR. If an
* exception is thrown, then the JSREPORT_EXCEPTION flag will be set in
* report.flags. Proper behavior for error reporters is probably to
* ignore this for all but toplevel compilation errors.
* XXXmccabe it's still at issue if there's a public API to distinguish
* between the two.
* XXX it'd probably be best if there was only one call to this
* function, but there seem to be two error reporter call points.
*/
(void)js_ErrorToException(cx, &report);
(*onError)(cx, message, &report);
#if !defined XP_PC || !defined _MSC_VER || _MSC_VER > 800
} else {
if (!(ts->flags & TSF_INTERACTIVE))