diff --git a/source/cell.c b/source/cell.c index 56367f2b..931841dc 100644 --- a/source/cell.c +++ b/source/cell.c @@ -635,7 +635,12 @@ int cell_init(int argc, char **argv) if (JS_IsException(result)) { JSValue exc = JS_GetException(ctx); - const char *str = JS_ToCString(ctx, exc); + const char *str = NULL; + if (JS_IsObject(exc)) { + JSValue msg = JS_GetPropertyStr(ctx, exc, "message"); + str = JS_ToCString(ctx, msg); + } + if (!str) str = JS_ToCString(ctx, exc); if (str) { printf("Error: %s\n", str); JS_FreeCString(ctx, str); } cJSON *stack = JS_GetStack(ctx); if (stack) { @@ -775,7 +780,12 @@ int cell_init(int argc, char **argv) int exit_code = 0; if (JS_IsException(result)) { JSValue exc = JS_GetException(ctx); - const char *err_str = JS_ToCString(ctx, exc); + const char *err_str = NULL; + if (JS_IsObject(exc)) { + JSValue msg = JS_GetPropertyStr(ctx, exc, "message"); + err_str = JS_ToCString(ctx, msg); + } + if (!err_str) err_str = JS_ToCString(ctx, exc); if (err_str) { printf("Error: %s\n", err_str); JS_FreeCString(ctx, err_str); diff --git a/source/mach.c b/source/mach.c index 52e2cf26..82e82d2e 100644 --- a/source/mach.c +++ b/source/mach.c @@ -2919,7 +2919,12 @@ JSValue JS_CallRegisterVM(JSContext *ctx, JSCodeRegister *code, break; } if (JS_IsNull(frame->caller)) { - result = JS_Throw(ctx, JS_NewString(ctx, "unhandled disruption")); + /* Re-throw the original exception so the caller sees the real message */ + JSValue exc = JS_GetException(ctx); + if (JS_IsNull(exc)) + result = JS_ThrowInternalError(ctx, "unhandled disruption"); + else + result = JS_Throw(ctx, exc); frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val); goto done; } diff --git a/source/mcode.c b/source/mcode.c index 34f933ee..704c31f2 100644 --- a/source/mcode.c +++ b/source/mcode.c @@ -3406,7 +3406,12 @@ JSValue mcode_exec(JSContext *ctx, JSMCode *code, JSValue this_obj, break; } if (JS_IsNull(frame->caller)) { - result = JS_Throw(ctx, JS_NewString(ctx, "unhandled disruption")); + /* Re-throw the original exception so the caller sees the real message */ + JSValue exc = JS_GetException(ctx); + if (JS_IsNull(exc)) + result = JS_ThrowInternalError(ctx, "unhandled disruption"); + else + result = JS_Throw(ctx, exc); frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val); goto done; } diff --git a/source/runtime.c b/source/runtime.c index 324df6ce..c3b9227d 100644 --- a/source/runtime.c +++ b/source/runtime.c @@ -11799,7 +11799,7 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) { /* Core functions - using GC-safe helper */ js_set_global_cfunc(ctx, "eval", js_cell_eval, 2); - js_set_global_cfunc(ctx, "mach_eval", js_mach_eval, 2); + js_set_global_cfunc(ctx, "mach_eval", js_mach_eval, 3); js_set_global_cfunc(ctx, "stone", js_cell_stone, 1); js_set_global_cfunc(ctx, "length", js_cell_length, 1); js_set_global_cfunc(ctx, "call", js_cell_call, 3);