void sj_print_exception(struct v7 *v7, v7_val_t exc, const char *msg) { /* * TOD(mkm) add some API to hal to fetch the current debug mode * and avoid logging to stdout if according no error messages should go * there (e.g. because it's used to implement a serial protocol). */ FILE *fs[] = {stdout, stderr}; size_t i; /* * own because the exception could be a string, * and if not owned here, print_stack_trace could get * an unrelocated argument an ASN violation. */ v7_own(v7, &exc); for (i = 0; i < sizeof(fs) / sizeof(fs[0]); i++) { fprintf(fs[i], "%s: ", msg); v7_fprintln(fs[i], v7, exc); #if V7_ENABLE__StackTrace v7_fprint_stack_trace(fs[i], v7, exc); #endif } v7_disown(v7, &exc); }
static void process_js(char *cmd) { s_sjp.char_processor = interrupt_char_processor; v7_val_t v; int res = v7_exec(s_sjp.v7, &v, cmd); if (res == V7_SYNTAX_ERROR) { printf("Syntax error: %s\n", v7_get_parser_error(s_sjp.v7)); } else if (res == V7_STACK_OVERFLOW) { printf("Stack overflow: %s\n", v7_get_parser_error(s_sjp.v7)); } else { if (res == V7_EXEC_EXCEPTION) { printf("Exec error:"); } v7_println(s_sjp.v7, v); #if V7_ENABLE__StackTrace if (res == V7_EXEC_EXCEPTION) { v7_fprint_stack_trace(stdout, s_sjp.v7, v); } #endif } v7_gc(s_sjp.v7, 0 /* full */); }
void _sj_invoke_cb(struct v7 *v7, v7_val_t func, v7_val_t this_obj, v7_val_t args) { v7_val_t res; if (v7_apply(v7, &res, func, this_obj, args) == V7_EXEC_EXCEPTION) { fprintf(stderr, "cb threw exception: "); v7_fprintln(stderr, v7, res); #if V7_ENABLE__StackTrace v7_fprint_stack_trace(stderr, v7, res); #endif } }