summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2017-04-28 00:08:27 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2017-04-28 00:11:10 -0700
commit854a2bcd879f02ec2ff544f48b70fc43a5132914 (patch)
treea7be731812246d3b32cfdb2f18b600b3e99adad1
parent1884a523f6c20b6cbee0b37dde31841a582e20ef (diff)
downloadgjs-854a2bcd879f02ec2ff544f48b70fc43a5132914.tar.gz
modules/console: Update fancy error reporter to mozjs38
It turns out the error reporter was copied almost verbatim from an internal SpiderMonkey function, js::PrintError(). By copying in a newer version from SpiderMonkey 38, we get the latest improvements: along with the line number, the character column of the error is also printed. https://bugzilla.gnome.org/show_bug.cgi?id=781882
-rw-r--r--modules/console.cpp59
1 files changed, 29 insertions, 30 deletions
diff --git a/modules/console.cpp b/modules/console.cpp
index 00db76f0..bbc6b9f1 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -60,25 +60,25 @@
static void
gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *report)
{
- int i, j, k, n;
- char *prefix, *tmp;
- const char *ctmp;
+ /* Code modified from SpiderMonkey js/src/jscntxt.cpp, js::PrintError() */
if (!report) {
fprintf(stderr, "%s\n", message);
+ fflush(stderr);
return;
}
- prefix = NULL;
+ char *prefix = nullptr;
if (report->filename)
prefix = g_strdup_printf("%s:", report->filename);
if (report->lineno) {
- tmp = prefix;
- prefix = g_strdup_printf("%s%u: ", tmp ? tmp : "", report->lineno);
+ char *tmp = prefix;
+ prefix = g_strdup_printf("%s%u:%u ", tmp ? tmp : "", report->lineno,
+ report->column);
g_free(tmp);
}
if (JSREPORT_IS_WARNING(report->flags)) {
- tmp = prefix;
+ char *tmp = prefix;
prefix = g_strdup_printf("%s%swarning: ",
tmp ? tmp : "",
JSREPORT_IS_STRICT(report->flags) ? "strict " : "");
@@ -86,7 +86,8 @@ gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *re
}
/* embedded newlines -- argh! */
- while ((ctmp = strchr(message, '\n')) != NULL) {
+ const char *ctmp;
+ while ((ctmp = strchr(message, '\n')) != 0) {
ctmp++;
if (prefix)
fputs(prefix, stderr);
@@ -99,31 +100,29 @@ gjs_console_error_reporter(JSContext *cx, const char *message, JSErrorReport *re
fputs(prefix, stderr);
fputs(message, stderr);
- if (!report->linebuf) {
- fputc('\n', stderr);
- goto out;
- }
-
- /* report->linebuf usually ends with a newline. */
- n = strlen(report->linebuf);
- fprintf(stderr, ":\n%s%s%s%s",
- prefix,
- report->linebuf,
- (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
- prefix);
- n = ((char*)report->tokenptr) - ((char*) report->linebuf);
- for (i = j = 0; i < n; i++) {
- if (report->linebuf[i] == '\t') {
- for (k = (j + 8) & ~7; j < k; j++) {
- fputc('.', stderr);
+ if (report->linebuf) {
+ /* report->linebuf usually ends with a newline. */
+ int n = strlen(report->linebuf);
+ fprintf(stderr, ":\n%s%s%s%s",
+ prefix,
+ report->linebuf,
+ (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
+ prefix);
+ n = report->tokenptr - report->linebuf;
+ for (int i = 0, j = 0; i < n; i++) {
+ if (report->linebuf[i] == '\t') {
+ for (int k = (j + 8) & ~7; j < k; j++) {
+ fputc('.', stderr);
+ }
+ continue;
}
- continue;
+ fputc('.', stderr);
+ j++;
}
- fputc('.', stderr);
- j++;
+ fputc('^', stderr);
}
- fputs("^\n", stderr);
- out:
+ fputc('\n', stderr);
+ fflush(stderr);
g_free(prefix);
}