wary jumps

This commit is contained in:
2026-02-21 20:58:24 -06:00
parent d27047dd82
commit 7372b80e07
2 changed files with 122 additions and 4 deletions

View File

@@ -639,6 +639,30 @@ static int cell_check_call_arity(JSContext *ctx, JSFunction *fn, int argc) {
return 1;
}
JSValue cell_rt_apply(JSContext *ctx, JSValue fn_val, JSValue arg_val) {
if (!mist_is_function(fn_val))
return fn_val;
JSFunction *fn = JS_VALUE_GET_FUNCTION(fn_val);
if (!mist_is_array(arg_val)) {
if (!cell_check_call_arity(ctx, fn, 1))
return JS_EXCEPTION;
return JS_CallInternal(ctx, fn_val, JS_NULL, 1, &arg_val, 0);
}
JSArray *arr = JS_VALUE_GET_ARRAY(arg_val);
int len = arr->len;
if (!cell_check_call_arity(ctx, fn, len))
return JS_EXCEPTION;
if (len == 0)
return JS_CallInternal(ctx, fn_val, JS_NULL, 0, NULL, 0);
JSValue args[len];
for (int i = 0; i < len; i++)
args[i] = arr->values[i];
return JS_CallInternal(ctx, fn_val, JS_NULL, len, args, 0);
}
static inline void cell_copy_args_0_4(JSValue *fp, JSValue *argv, int copy) {
/* fp[0] is `this`; copy args into fp[1..4] */
switch (copy) {