This commit is contained in:
2026-02-02 22:46:07 -06:00
parent ddbdd00496
commit 8e166b8f98
2 changed files with 171 additions and 6 deletions

View File

@@ -1765,7 +1765,7 @@ static int JS_GetOwnPropertyInternal (JSContext *ctx,
static __exception int js_get_length32 (JSContext *ctx, uint32_t *pres, JSValue obj);
static __exception int js_get_length64 (JSContext *ctx, int64_t *pres, JSValue obj);
static void free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len);
static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_arg);
static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue *parray_arg);
static BOOL js_get_fast_array (JSContext *ctx, JSValue obj, JSValue **arrpp, uint32_t *countp);
static JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, JSValue *argv);
@@ -18786,13 +18786,13 @@ static void free_arg_list (JSContext *ctx, JSValue *tab, uint32_t len) {
}
/* XXX: should use ValueArray */
static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_arg) {
static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue *parray_arg) {
uint32_t len, i;
JSValue *tab;
/* Fast path for intrinsic arrays */
if (JS_IsArray (array_arg)) {
JSArray *arr = JS_VALUE_GET_ARRAY (array_arg);
if (JS_IsArray (*parray_arg)) {
JSArray *arr = JS_VALUE_GET_ARRAY (*parray_arg);
len = arr->len;
if (len > JS_MAX_LOCAL_VARS) {
JS_ThrowRangeError (
@@ -18801,6 +18801,7 @@ static JSValue *build_arg_list (JSContext *ctx, uint32_t *plen, JSValue array_ar
}
tab = js_mallocz (ctx, sizeof (tab[0]) * max_uint32 (1, len));
if (!tab) return NULL;
arr = JS_VALUE_GET_ARRAY (*parray_arg); /* re-chase after malloc via argv */
for (i = 0; i < len; i++) {
tab[i] = arr->values[i];
}
@@ -18832,7 +18833,7 @@ static JSValue js_function_apply (JSContext *ctx, JSValue this_val, int argc, JS
if (unlikely (arr->len > f->length))
return JS_ThrowTypeError (ctx, "too many arguments");
}
tab = build_arg_list (ctx, &len, array_arg);
tab = build_arg_list (ctx, &len, &argv[1]);
if (!tab) return JS_EXCEPTION;
ret = JS_Call (ctx, this_val, this_arg, len, (JSValue *)tab);
free_arg_list (ctx, tab, len);
@@ -22089,6 +22090,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
/* Copy */
JSValue result = JS_NewArrayLen (ctx, len);
if (JS_IsException (result)) return result;
arr = JS_VALUE_GET_ARRAY (argv[0]); /* re-chase after allocation via argv */
JSArray *out = JS_VALUE_GET_ARRAY (result);
for (int i = 0; i < len; i++) {
out->values[i] = arr->values[i];
@@ -23015,6 +23017,8 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
int len = keys->len;
for (int i = 0; i < len; i++) {
keys = JS_VALUE_GET_ARRAY (argv[1]); /* re-chase each iteration */
if (i >= (int)keys->len) break;
JSValue key = keys->values[i];
int key_tag = JS_VALUE_GET_TAG (key);
if (key_tag == JS_TAG_STRING || key_tag == JS_TAG_STRING_IMM) {
@@ -23043,10 +23047,13 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
JSValue result = JS_NewObject (ctx);
if (JS_IsException (result)) return result;
JSGCRef result_ref;
int is_func = argc >= 2 && JS_IsFunction (argv[1]);
for (int i = 0; i < len; i++) {
keys = JS_VALUE_GET_ARRAY (argv[0]); /* re-chase each iteration via argv */
if (i >= (int)keys->len) break;
JSValue key = keys->values[i];
int key_tag = JS_VALUE_GET_TAG (key);
if (key_tag == JS_TAG_STRING || key_tag == JS_TAG_STRING_IMM) {
@@ -23057,7 +23064,9 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
val = JS_TRUE;
} else if (is_func) {
JSValue arg_key = key;
JS_PUSH_VALUE (ctx, result);
val = JS_CallInternal (ctx, argv[1], JS_NULL, 1, &arg_key, 0);
JS_POP_VALUE (ctx, result);
if (JS_IsException (val)) {
return JS_EXCEPTION;
}
@@ -23103,6 +23112,7 @@ static JSValue js_cell_fn_apply (JSContext *ctx, JSValue this_val, int argc, JSV
JSValue *args = js_malloc (ctx, sizeof (JSValue) * len);
if (!args) return JS_EXCEPTION;
arr = JS_VALUE_GET_ARRAY (argv[1]); /* re-chase after malloc via argv */
for (int i = 0; i < len; i++) {
args[i] = arr->values[i];
@@ -23723,6 +23733,7 @@ static JSValue js_cell_reverse (JSContext *ctx, JSValue this_val, int argc, JSVa
JSValue result = JS_NewArrayLen (ctx, len);
if (JS_IsException (result)) return result;
arr = JS_VALUE_GET_ARRAY (argv[0]); /* re-chase after allocation via argv */
JSArray *out = JS_VALUE_GET_ARRAY (result);
for (int i = len - 1, j = 0; i >= 0; i--, j++) {
out->values[j] = arr->values[i];
@@ -24354,7 +24365,7 @@ static JSValue js_cell_call (JSContext *ctx, JSValue this_val, int argc, JSValue
return JS_ThrowTypeError (ctx, "third argument must be an array");
uint32_t len;
JSValue *tab = build_arg_list (ctx, &len, argv[2]);
JSValue *tab = build_arg_list (ctx, &len, &argv[2]);
if (!tab) return JS_EXCEPTION;
JSValue ret = JS_CallInternal (ctx, func, this_arg, len, tab, 0);