Subject: | Error messages |
In the routine ErrorReporter:
/* ---------------------------------------------------------------------
*/
static void
ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
{
/* ---------------------------------------------------------------------
*/
char msg[400];
snprintf(msg, sizeof(msg),
"Error: %s at line %d: %s", message, report->lineno,
report->linebuf);
sv_setpv(get_sv("@", TRUE), msg);
}
report->linebuf is only set for compilation errors. See
http://groups.google.com/group/netscape.public.mozilla.jseng/tree/browse
_frm/month/2000-07?
_done=/group/netscape.public.mozilla.jseng/browse_frm/month/2000-07%3F&
(scroll down to the bottom of the page for comment by Brendan Eich.)
At runtime, report->linebuf is a null pointer, so a runtime error like
this:
function Donkey ()
{
this.value = random ();
}
creates an error message like this:
Error: ReferenceError: random is not defined at line 2: (null)
Also, at the compilation stage, report->linebuf actually contains a
newline, so a compile time error adds an extra newline to the end of the
error message.
It would be nice if the newline could be stripped out of the error
message.
The above post by Brendan Eich mentions that the documentation on the
Mozilla Developer Network/Centre should be fixed, but unfortunately the
incorrect documentation is still there, ten years later:
https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JSErrorRep
ort
(scroll down to bottom of the page)
If you want a patch for this, please let me know. As per my email (to
Thomas Busch) I'm continuing to patch a "personal fork" of this module
with this and many other bug fixes and improvements & would be happy to
share it.