fix tests

This commit is contained in:
2026-02-24 16:55:07 -06:00
parent 7bd17c6476
commit c2f57d1dae
10 changed files with 1179 additions and 96 deletions

View File

@@ -8375,7 +8375,15 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
/* Map - GC-safe: root result throughout, use rooted refs for func and array */
int arity = ((JSFunction *)JS_VALUE_GET_FUNCTION (arg1_ref.val))->length;
int reverse = argc > 2 && JS_ToBool (ctx, argv[2]);
int reverse = 0;
if (argc > 2 && !JS_IsNull (argv[2])) {
if (!JS_IsBool (argv[2])) {
JS_PopGCRef (ctx, &arg1_ref);
JS_PopGCRef (ctx, &arg0_ref);
return JS_RaiseDisrupt (ctx, "array: reverse must be a logical");
}
reverse = JS_VALUE_GET_BOOL (argv[2]);
}
JSValue exit_val = argc > 3 ? argv[3] : JS_NULL;
JSGCRef result_ref;
@@ -8505,7 +8513,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
if (!JS_IsInteger (argv[1])) {
JS_PopGCRef (ctx, &arg1_ref);
JS_PopGCRef (ctx, &arg0_ref);
return JS_NULL;
return JS_RaiseDisrupt (ctx, "array slice: from must be an integer");
}
int from = JS_VALUE_GET_INT (argv[1]);
int to;
@@ -8513,7 +8521,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
if (!JS_IsNumber (argv[2]) || !JS_IsInteger (argv[2])) {
JS_PopGCRef (ctx, &arg1_ref);
JS_PopGCRef (ctx, &arg0_ref);
return JS_NULL;
return JS_RaiseDisrupt (ctx, "array slice: to must be an integer");
}
to = JS_VALUE_GET_INT (argv[2]);
} else {
@@ -8550,7 +8558,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
JS_PopGCRef (ctx, &arg1_ref);
JS_PopGCRef (ctx, &arg0_ref);
return JS_NULL;
return JS_RaiseDisrupt (ctx, "array: invalid argument combination");
}
/* array(object) - keys */
@@ -8822,7 +8830,12 @@ static JSValue js_cell_array_reduce (JSContext *ctx, JSValue this_val, int argc,
word_t len = arr->len;
JSValue fn = argv[1];
int reverse = argc > 3 && JS_ToBool (ctx, argv[3]);
int reverse = 0;
if (argc > 3 && !JS_IsNull (argv[3])) {
if (!JS_IsBool (argv[3]))
return JS_RaiseDisrupt (ctx, "reduce: reverse must be a logical");
reverse = JS_VALUE_GET_BOOL (argv[3]);
}
JSGCRef acc_ref;
JSValue acc;
@@ -8898,7 +8911,12 @@ static JSValue js_cell_array_for (JSContext *ctx, JSValue this_val, int argc, JS
word_t len = arr->len;
if (len == 0) return JS_NULL;
int reverse = argc > 2 && JS_ToBool (ctx, argv[2]);
int reverse = 0;
if (argc > 2 && !JS_IsNull (argv[2])) {
if (!JS_IsBool (argv[2]))
return JS_RaiseDisrupt (ctx, "arrfor: reverse must be a logical");
reverse = JS_VALUE_GET_BOOL (argv[2]);
}
JSValue exit_val = argc > 3 ? argv[3] : JS_NULL;
if (reverse) {
@@ -8938,7 +8956,12 @@ static JSValue js_cell_array_find (JSContext *ctx, JSValue this_val, int argc, J
JSArray *arr = JS_VALUE_GET_ARRAY (argv[0]);
word_t len = arr->len;
int reverse = argc > 2 && JS_ToBool (ctx, argv[2]);
int reverse = 0;
if (argc > 2 && !JS_IsNull (argv[2])) {
if (!JS_IsBool (argv[2]))
return JS_RaiseDisrupt (ctx, "find: reverse must be a logical");
reverse = JS_VALUE_GET_BOOL (argv[2]);
}
int32_t from;
if (argc > 3 && !JS_IsNull (argv[3])) {
if (JS_ToInt32 (ctx, &from, argv[3])) return JS_NULL;
@@ -9416,7 +9439,7 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
/* Use text directly as key */
JSValue prop_key = js_key_from_string (ctx, key);
JSValue val;
if (argc < 2 || JS_IsNull (func_ref.val)) {
if (argc < 2) {
val = JS_TRUE;
} else if (is_func) {
JSValue arg_key = key;
@@ -11336,11 +11359,9 @@ static JSValue js_cell_is_blob (JSContext *ctx, JSValue this_val, int argc, JSVa
static JSValue js_cell_is_data (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
if (argc < 1) return JS_FALSE;
JSValue val = argv[0];
if (!mist_is_gc_object (val)) return JS_FALSE;
if (JS_IsArray (val)) return JS_FALSE;
/* data is text, number, logical, array, blob, or record — not function, null */
if (JS_IsNull (val)) return JS_FALSE;
if (JS_IsFunction (val)) return JS_FALSE;
if (mist_is_blob (val)) return JS_FALSE;
/* Check if it's a plain object (prototype is Object.prototype or null) */
return JS_TRUE;
}