1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[smjs] Error Reporting with open_memstream

This commit is contained in:
Witold Filipczyk 2021-09-06 20:36:10 +02:00
parent 024f4f44b6
commit 30d4eb36ff

View File

@ -42,43 +42,28 @@ alert_smjs_error(char *msg)
static void static void
error_reporter(JSContext *ctx, JSErrorReport *report) error_reporter(JSContext *ctx, JSErrorReport *report)
{ {
#if 0 char *ptr;
char *warning; size_t size;
struct string msg;
JS::UniqueChars prefix;
if (!init_string(&msg)) goto reported; FILE *f = open_memstream(&ptr, &size);
warning = report->isWarning() ? " warning" : " error"; if (f) {
#endif struct string msg;
JS::PrintError(ctx, f, report, true/*reportWarnings*/);
fclose(f);
JS::PrintError(ctx, stderr, report, true/*reportWarnings*/); if (!init_string(&msg)) {
#if 0 free(ptr);
add_format_to_string(&msg, "A client script raised the following%s", return;
warning); }
add_to_string(&msg, "A client script raised the following:\n");
add_to_string(&msg, ":\n\n"); add_bytes_to_string(&msg, ptr, size);
free(ptr);
add_format_to_string(&msg, "\n\n%d:%d ", report->lineno, report->column); alert_smjs_error(msg.source);
done_string(&msg);
if (report->filename) {
prefix = JS_smprintf("%s:", report->filename);
} }
if (report->lineno) {
prefix = JS_smprintf("%s%u:%u ", prefix, report->lineno, report->column);
}
if (prefix) {
add_to_string(&msg, prefix.get());
}
alert_smjs_error(msg.source);
done_string(&msg);
reported:
JS_ClearPendingException(ctx); JS_ClearPendingException(ctx);
#endif
} }
static int static int