fixes
This commit is contained in:
@@ -82,6 +82,19 @@ static JSValue *mach_materialize_cpool(JSContext *ctx, MachCPoolEntry *entries,
|
||||
return cpool;
|
||||
}
|
||||
|
||||
static int mach_check_call_arity(JSContext *ctx, JSFunction *fn, int argc) {
|
||||
if (unlikely(fn->length >= 0 && argc > fn->length)) {
|
||||
char buf[KEY_GET_STR_BUF_SIZE];
|
||||
fprintf(stderr, "[arity-mach] callee=%s expected=%d got=%d\n",
|
||||
JS_KeyGetStr(ctx, buf, KEY_GET_STR_BUF_SIZE, fn->name),
|
||||
fn->length, argc);
|
||||
JS_RaiseDisrupt(ctx, "too many arguments for %s: expected %d, got %d",
|
||||
JS_KeyGetStr(ctx, buf, KEY_GET_STR_BUF_SIZE, fn->name), fn->length, argc);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ---- Link pass: resolve GETNAME to GETINTRINSIC or GETENV ---- */
|
||||
|
||||
static void mach_link_code(JSContext *ctx, JSCodeRegister *code, JSValue env) {
|
||||
@@ -2170,6 +2183,13 @@ vm_dispatch:
|
||||
int c_argc = (nr >= 2) ? nr - 2 : 0;
|
||||
JSValue fn_val = fr->function;
|
||||
JSFunction *fn = JS_VALUE_GET_FUNCTION(fn_val);
|
||||
if (!mach_check_call_arity(ctx, fn, c_argc)) {
|
||||
fprintf(stderr, "[arity-mach] caller=%s file=%s pc=%u op=invoke argc=%d\n",
|
||||
code->name_cstr ? code->name_cstr : "?",
|
||||
code->filename_cstr ? code->filename_cstr : "?",
|
||||
(unsigned)(pc > 0 ? pc - 1 : 0), c_argc);
|
||||
goto disrupt;
|
||||
}
|
||||
|
||||
if (fn->kind == JS_FUNC_KIND_REGISTER) {
|
||||
/* Register function: switch frames inline (fast path) */
|
||||
@@ -2241,6 +2261,13 @@ vm_dispatch:
|
||||
int c_argc = (nr >= 2) ? nr - 2 : 0;
|
||||
JSValue fn_val = fr->function;
|
||||
JSFunction *fn = JS_VALUE_GET_FUNCTION(fn_val);
|
||||
if (!mach_check_call_arity(ctx, fn, c_argc)) {
|
||||
fprintf(stderr, "[arity-mach] caller=%s file=%s pc=%u op=goinvoke argc=%d\n",
|
||||
code->name_cstr ? code->name_cstr : "?",
|
||||
code->filename_cstr ? code->filename_cstr : "?",
|
||||
(unsigned)(pc > 0 ? pc - 1 : 0), c_argc);
|
||||
goto disrupt;
|
||||
}
|
||||
|
||||
if (fn->kind == JS_FUNC_KIND_REGISTER) {
|
||||
JSCodeRegister *fn_code = JS_VALUE_GET_CODE(fn->u.cell.code)->u.reg.code;
|
||||
|
||||
Reference in New Issue
Block a user