better errors

This commit is contained in:
2026-02-16 21:52:11 -06:00
parent 5a7169654a
commit 2051677679
4 changed files with 227 additions and 31 deletions

View File

@@ -2124,41 +2124,45 @@ JSValue JS_CallRegisterVM(JSContext *ctx, JSCodeRegister *code,
if (code->disruption_pc > 0 && frame_pc < code->disruption_pc) {
env = fn->u.reg.env_record;
pc = code->disruption_pc;
ctx->disruption_reported = FALSE;
break;
}
if (JS_IsNull(frame->caller)) {
const char *fn_name = code->name_cstr ? code->name_cstr : "<anonymous>";
const char *file = code->filename_cstr ? code->filename_cstr : "<unknown>";
uint16_t line = 0, col = 0;
if (code->line_table && frame_pc > 0 && frame_pc - 1 < code->instr_count) {
line = code->line_table[frame_pc - 1].line;
col = code->line_table[frame_pc - 1].col;
}
fprintf(stderr, "unhandled disruption in %s (%s:%u:%u)\n", fn_name, file, line, col);
/* Walk and print the frame chain as a stack trace */
{
JSFrameRegister *trace_frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
int first = 1;
while (trace_frame) {
if (!mist_is_function(trace_frame->function)) break;
JSFunction *trace_fn = JS_VALUE_GET_FUNCTION(trace_frame->function);
if (trace_fn->kind == JS_FUNC_KIND_REGISTER && trace_fn->u.reg.code) {
JSCodeRegister *tc = trace_fn->u.reg.code;
uint32_t tpc = first ? (frame_pc > 0 ? frame_pc - 1 : 0)
: (uint32_t)(JS_VALUE_GET_INT(trace_frame->address) >> 16);
uint16_t tl = 0, tcol = 0;
if (tc->line_table && tpc < tc->instr_count) {
tl = tc->line_table[tpc].line;
tcol = tc->line_table[tpc].col;
}
fprintf(stderr, " at %s (%s:%u:%u)\n",
tc->name_cstr ? tc->name_cstr : "<anonymous>",
tc->filename_cstr ? tc->filename_cstr : "<unknown>", tl, tcol);
}
if (JS_IsNull(trace_frame->caller)) break;
trace_frame = (JSFrameRegister *)JS_VALUE_GET_PTR(trace_frame->caller);
first = 0;
if (!ctx->disruption_reported) {
const char *fn_name = code->name_cstr ? code->name_cstr : "<anonymous>";
const char *file = code->filename_cstr ? code->filename_cstr : "<unknown>";
uint16_t line = 0, col = 0;
if (code->line_table && frame_pc > 0 && frame_pc - 1 < code->instr_count) {
line = code->line_table[frame_pc - 1].line;
col = code->line_table[frame_pc - 1].col;
}
fprintf(stderr, "unhandled disruption in %s (%s:%u:%u)\n", fn_name, file, line, col);
/* Walk and print the frame chain as a stack trace */
{
JSFrameRegister *trace_frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
int first = 1;
while (trace_frame) {
if (!mist_is_function(trace_frame->function)) break;
JSFunction *trace_fn = JS_VALUE_GET_FUNCTION(trace_frame->function);
if (trace_fn->kind == JS_FUNC_KIND_REGISTER && trace_fn->u.reg.code) {
JSCodeRegister *tc = trace_fn->u.reg.code;
uint32_t tpc = first ? (frame_pc > 0 ? frame_pc - 1 : 0)
: (uint32_t)(JS_VALUE_GET_INT(trace_frame->address) >> 16);
uint16_t tl = 0, tcol = 0;
if (tc->line_table && tpc < tc->instr_count) {
tl = tc->line_table[tpc].line;
tcol = tc->line_table[tpc].col;
}
fprintf(stderr, " at %s (%s:%u:%u)\n",
tc->name_cstr ? tc->name_cstr : "<anonymous>",
tc->filename_cstr ? tc->filename_cstr : "<unknown>", tl, tcol);
}
if (JS_IsNull(trace_frame->caller)) break;
trace_frame = (JSFrameRegister *)JS_VALUE_GET_PTR(trace_frame->caller);
first = 0;
}
}
ctx->disruption_reported = TRUE;
}
result = JS_Throw(ctx, JS_NULL);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);