This commit is contained in:
2026-02-12 18:53:06 -06:00
parent 73bfa8d7b1
commit de4b3079d4
4 changed files with 339 additions and 240 deletions

View File

@@ -36,48 +36,28 @@ static inline JS_BOOL JS_IsInteger (JSValue v) {
return d == (double)(int64_t)d;
}
static inline JS_BOOL JS_IsGCObject (JSValue v) {
return JS_IsPtr (v);
}
JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT;
/* === Function definitions from header region (non-inline) === */
/* === Public API wrappers (non-inline, for quickjs.h declarations) ===
These delegate to the static inline versions in quickjs-internal.h. */
JS_BOOL JS_IsStone(JSValue v) {
return !JS_IsGCObject(v) || objhdr_s(*chase(v));
JS_BOOL JS_IsStone(JSValue v) { return mist_is_stone(v); }
JS_BOOL JS_IsArray(JSValue v) { return mist_is_array(v); }
JS_BOOL JS_IsRecord(JSValue v) { return mist_is_record(v); }
JS_BOOL JS_IsFunction(JSValue v) { return mist_is_function(v); }
JS_BOOL JS_IsBlob(JSValue v) { return mist_is_blob(v); }
JS_BOOL JS_IsText(JSValue v) { return mist_is_text(v); }
JS_BOOL JS_IsCode(JSValue v) {
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_CODE;
}
JS_BOOL JS_IsArray(JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_ARRAY;
JS_BOOL JS_IsForwarded(JSValue v) {
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_FORWARD;
}
JS_BOOL JS_IsRecord (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_RECORD;
}
JS_BOOL JS_IsFunction (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_FUNCTION;
}
JS_BOOL JS_IsCode (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_CODE;
}
JS_BOOL JS_IsForwarded (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_FORWARD;
}
JS_BOOL JS_IsFrame (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_FRAME;
}
JS_BOOL JS_IsBlob (JSValue v) {
return JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_BLOB;
}
JS_BOOL JS_IsText(JSValue v) {
return MIST_IsImmediateASCII(v) || (JS_IsGCObject(v) && objhdr_type(*chase(v)) == OBJ_TEXT);
JS_BOOL JS_IsFrame(JSValue v) {
return mist_is_gc_object(v) && objhdr_type(*chase(v)) == OBJ_FRAME;
}
uint64_t get_text_hash (JSText *text) {
@@ -3093,7 +3073,7 @@ static BOOL js_object_has_name (JSContext *ctx, JSValue obj) {
}
int JS_DefineObjectName (JSContext *ctx, JSValue obj, JSValue name) {
if (!JS_IsNull (name) && JS_IsGCObject (obj)
if (!JS_IsNull (name) && mist_is_gc_object (obj)
&& !js_object_has_name (ctx, obj)) {
JSValue name_key = MIST_TryNewImmediateASCII ("name", 4);
if (JS_SetPropertyInternal (ctx, obj, name_key, name)
@@ -3104,7 +3084,7 @@ int JS_DefineObjectName (JSContext *ctx, JSValue obj, JSValue name) {
}
int JS_DefineObjectNameComputed (JSContext *ctx, JSValue obj, JSValue str) {
if (JS_IsGCObject (obj) && !js_object_has_name (ctx, obj)) {
if (mist_is_gc_object (obj) && !js_object_has_name (ctx, obj)) {
JSValue name_key = MIST_TryNewImmediateASCII ("name", 4);
if (JS_SetPropertyInternal (ctx, obj, name_key, str)
< 0)
@@ -4685,7 +4665,7 @@ static JSRegExp *js_get_regexp (JSContext *ctx, JSValue obj, BOOL throw_error) {
static int js_is_regexp (JSContext *ctx, JSValue obj) {
JSValue m;
if (!JS_IsGCObject (obj)) return FALSE;
if (!mist_is_gc_object (obj)) return FALSE;
m = JS_GetPropertyStr (ctx, obj, "Symbol.match");
if (JS_IsException (m)) return -1;
if (!JS_IsNull (m)) return JS_ToBool (ctx, m);
@@ -4828,7 +4808,7 @@ fail:
JSValue js_regexp_toString (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
JSValue pattern, flags;
if (!JS_IsGCObject (this_val)) return JS_ThrowTypeErrorNotAnObject (ctx);
if (!mist_is_gc_object (this_val)) return JS_ThrowTypeErrorNotAnObject (ctx);
JSText *b = pretext_init (ctx, 0);
if (!b) return JS_EXCEPTION;
@@ -5227,7 +5207,7 @@ static JSValue js_json_check (JSContext *ctx, JSONStringifyContext *jsc, JSValue
/* check for object.toJSON method */
/* ECMA specifies this is done only for Object and BigInt */
if (JS_IsGCObject (val)) {
if (mist_is_gc_object (val)) {
JSValue f = JS_GetProperty (ctx, val, JS_KEY_toJSON);
if (JS_IsException (f)) goto exception;
if (JS_IsFunction (f)) {
@@ -5299,7 +5279,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho
goto concat_value;
}
if (JS_IsGCObject (
if (mist_is_gc_object (
val_ref.val)) { /* includes arrays (OBJ_ARRAY) since they have JS_TAG_PTR */
v = js_array_includes (ctx, jsc->stack, 1, &val_ref.val);
if (JS_IsException (v)) goto exception;
@@ -5487,7 +5467,7 @@ JSValue JS_JSONStringify (JSContext *ctx, JSValue obj, JSValue replacer, JSValue
JSValue present;
v = JS_GetPropertyNumber (ctx, replacer, i);
if (JS_IsException (v)) goto exception;
if (JS_IsGCObject (v)) {
if (mist_is_gc_object (v)) {
/* Objects are not valid property list items */
continue;
} else if (JS_IsNumber (v)) {
@@ -6726,7 +6706,7 @@ static JSValue make_replacement (JSContext *ctx, int argc, JSValue *argv, int fo
}
static int JS_IsRegExp (JSContext *ctx, JSValue v) {
if (!JS_IsGCObject (v)) return 0;
if (!mist_is_gc_object (v)) return 0;
JSValue exec = JS_GetPropertyStr (ctx, v, "exec");
if (JS_IsException (exec)) return -1;
@@ -6760,7 +6740,7 @@ static JSValue js_cell_text_replace (JSContext *ctx, JSValue this_val, int argc,
{
if (JS_IsText (argv[1])) {
target_is_regex = 0;
} else if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
} else if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
target_is_regex = 1;
} else {
return JS_NULL;
@@ -7042,7 +7022,7 @@ static JSValue js_cell_text_search (JSContext *ctx, JSValue this_val, int argc,
int target_is_regex = 0;
if (JS_IsText (argv[1])) {
target_is_regex = 0;
} else if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
} else if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
target_is_regex = 1;
} else {
return JS_NULL;
@@ -7180,7 +7160,7 @@ static JSValue js_cell_text_extract (JSContext *ctx, JSValue this_val, int argc,
if (from > to) return JS_NULL;
/* RegExp path: convert new exec result record -> classic array */
if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
/* Root rx, str, out across allocating calls */
JSGCRef rx_ref, str_ref, out_ref;
JS_PushGCRef (ctx, &rx_ref);
@@ -7901,7 +7881,7 @@ static JSValue js_cell_array (JSContext *ctx, JSValue this_val, int argc, JSValu
return result;
}
if (JS_IsGCObject (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
if (mist_is_gc_object (argv[1]) && JS_IsRegExp (ctx, argv[1])) {
/* Split by regex (manual "global" iteration; ignore g flag semantics) */
/* Root rx, result, arg across allocating calls */
JSGCRef rx_ref, res_ref, arg_ref;
@@ -8561,7 +8541,7 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
JSValue arg = argv[0];
/* object(object) - shallow mutable copy */
if (JS_IsGCObject (arg) && !JS_IsArray (arg) && !JS_IsFunction (arg)) {
if (mist_is_gc_object (arg) && !JS_IsArray (arg) && !JS_IsFunction (arg)) {
if (argc < 2 || JS_IsNull (argv[1])) {
/* Shallow copy - root arg, result, keys across allocating calls */
JSGCRef arg_ref, res_ref, keys_ref;
@@ -8603,7 +8583,7 @@ static JSValue js_cell_object (JSContext *ctx, JSValue this_val, int argc, JSVal
#undef OBJ_COPY_CLEANUP
/* object(object, another_object) - combine */
if (JS_IsGCObject (argv[1]) && !JS_IsArray (argv[1])) {
if (mist_is_gc_object (argv[1]) && !JS_IsArray (argv[1])) {
JSGCRef arg_ref, arg2_ref, res_ref, keys_ref;
JS_PushGCRef (ctx, &arg_ref);
arg_ref.val = arg;
@@ -8925,7 +8905,7 @@ static JSValue js_blob_constructor (JSContext *ctx, JSValue this_val, int argc,
}
}
/* blob(blob, from, to) - copy from another blob */
else if (argc >= 1 && JS_IsGCObject (argv[0]) && !JS_IsText (argv[0])) {
else if (argc >= 1 && mist_is_gc_object (argv[0]) && !JS_IsText (argv[0])) {
blob *src = js_get_blob (ctx, argv[0]);
if (!src)
return JS_ThrowTypeError (ctx,
@@ -9404,7 +9384,7 @@ static JSValue js_mach_load (JSContext *ctx, JSValue this_val, int argc, JSValue
if (!mc)
return JS_ThrowSyntaxError (ctx, "mach_load: failed to deserialize bytecode");
JSValue env = (argc >= 2 && JS_IsGCObject (argv[1])) ? argv[1] : JS_NULL;
JSValue env = (argc >= 2 && mist_is_gc_object (argv[1])) ? argv[1] : JS_NULL;
JSGCRef env_ref;
JS_PushGCRef (ctx, &env_ref);
@@ -9452,7 +9432,7 @@ static JSValue js_mach_eval_mcode (JSContext *ctx, JSValue this_val, int argc, J
return JS_ThrowInternalError (ctx, "mach_eval_mcode: compilation failed");
}
JSValue env = (argc >= 3 && JS_IsGCObject (argv[2])) ? argv[2] : JS_NULL;
JSValue env = (argc >= 3 && mist_is_gc_object (argv[2])) ? argv[2] : JS_NULL;
JSGCRef env_ref;
JS_PushGCRef (ctx, &env_ref);
@@ -9499,7 +9479,7 @@ static JSValue js_mach_dump_mcode (JSContext *ctx, JSValue this_val, int argc, J
return JS_ThrowInternalError (ctx, "mach_dump_mcode: compilation failed");
}
JSValue env = (argc >= 3 && JS_IsGCObject (argv[2])) ? argv[2] : JS_NULL;
JSValue env = (argc >= 3 && mist_is_gc_object (argv[2])) ? argv[2] : JS_NULL;
JSGCRef env_ref;
JS_PushGCRef (ctx, &env_ref);
@@ -9579,7 +9559,7 @@ static JSValue js_cell_stone (JSContext *ctx, JSValue this_val, int argc, JSValu
return obj;
}
if (JS_IsGCObject (obj)) {
if (mist_is_gc_object (obj)) {
JSRecord *rec = JS_VALUE_GET_RECORD (obj);
obj_set_stone (rec);
return obj;
@@ -10087,15 +10067,15 @@ static JSValue js_cell_proto (JSContext *ctx, JSValue this_val, int argc, JSValu
return JS_ThrowTypeError (ctx, "arrays do not have prototypes");
}
if (!JS_IsGCObject (obj)) return JS_NULL;
if (!mist_is_gc_object (obj)) return JS_NULL;
JSValue proto = JS_GetPrototype (ctx, obj);
if (JS_IsException (proto)) return JS_NULL;
/* If prototype is Object.prototype, return null */
if (JS_IsGCObject (proto)) {
if (mist_is_gc_object (proto)) {
JSValue obj_proto = ctx->class_proto[JS_CLASS_OBJECT];
if (JS_IsGCObject (obj_proto)
if (mist_is_gc_object (obj_proto)
&& JS_VALUE_GET_OBJ (proto) == JS_VALUE_GET_OBJ (obj_proto)) {
return JS_NULL;
}
@@ -10121,7 +10101,7 @@ static JSValue js_cell_meme (JSContext *ctx, JSValue this_val, int argc, JSValue
/* Helper function to apply a single mixin */
#define APPLY_MIXIN(mix_val) \
do { \
if (!JS_IsGCObject (mix_val) || JS_IsNull (mix_val) || JS_IsArray (mix_val)) \
if (!mist_is_gc_object (mix_val) || JS_IsNull (mix_val) || JS_IsArray (mix_val)) \
break; \
JSGCRef _mix_ref; \
JS_PushGCRef (ctx, &_mix_ref); \
@@ -10177,7 +10157,7 @@ static JSValue js_cell_meme (JSContext *ctx, JSValue this_val, int argc, JSValue
APPLY_MIXIN (mix);
}
JS_PopGCRef (ctx, &mixins_ref);
} else if (JS_IsGCObject (mixins) && !JS_IsNull (mixins)) {
} else if (mist_is_gc_object (mixins) && !JS_IsNull (mixins)) {
/* Single mixin object */
APPLY_MIXIN (mixins);
}
@@ -10199,7 +10179,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
if (argc < 1) return JS_NULL;
JSValue obj = argv[0];
if (!JS_IsGCObject (obj) || JS_IsNull (obj)) return JS_NULL;
if (!mist_is_gc_object (obj) || JS_IsNull (obj)) return JS_NULL;
/* Root obj, result, current, keys across allocating calls */
JSGCRef obj_ref, res_ref, cur_ref, keys_ref;
@@ -10243,7 +10223,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
return JS_EXCEPTION;
}
int tag = JS_VALUE_GET_TAG (val);
if (JS_IsGCObject (val) || JS_IsNumber (val) || tag == JS_TAG_STRING
if (mist_is_gc_object (val) || JS_IsNumber (val) || tag == JS_TAG_STRING
|| tag == JS_TAG_STRING_IMM || tag == JS_TAG_BOOL) {
JS_SetProperty (ctx, res_ref.val, key, val);
}
@@ -10258,7 +10238,7 @@ static JSValue js_cell_splat (JSContext *ctx, JSValue this_val, int argc, JSValu
if (JS_IsFunction (to_data)) {
JSValue args[1] = { res_ref.val };
JSValue extra = JS_Call (ctx, to_data, obj_ref.val, 1, args);
if (!JS_IsException (extra) && JS_IsGCObject (extra)) {
if (!JS_IsException (extra) && mist_is_gc_object (extra)) {
keys_ref.val = JS_GetOwnPropertyNames (ctx, extra);
if (!JS_IsException (keys_ref.val)) {
uint32_t len;
@@ -10318,7 +10298,7 @@ static JSValue js_cell_length (JSContext *ctx, JSValue this_val, int argc, JSVal
}
/* Objects with length property */
if (JS_IsGCObject (val)) {
if (mist_is_gc_object (val)) {
JSValue len = JS_GetPropertyStr (ctx, val, "length");
if (!JS_IsException (len) && !JS_IsNull (len)) {
if (JS_IsFunction (len)) {
@@ -10412,7 +10392,7 @@ 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 (!JS_IsGCObject (val)) return JS_FALSE;
if (!mist_is_gc_object (val)) return JS_FALSE;
if (JS_IsArray (val)) return JS_FALSE;
if (JS_IsFunction (val)) return JS_FALSE;
if (js_get_blob (ctx, val)) return JS_FALSE;
@@ -10461,7 +10441,7 @@ static JSValue js_cell_is_number (JSContext *ctx, JSValue this_val, int argc, JS
static JSValue js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) {
if (argc < 1) return JS_FALSE;
JSValue val = argv[0];
if (!JS_IsGCObject (val)) return JS_FALSE;
if (!mist_is_gc_object (val)) return JS_FALSE;
if (JS_IsArray (val)) return JS_FALSE;
return JS_TRUE;
}
@@ -10495,7 +10475,7 @@ static JSValue js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, JSV
JSValue val = argv[0];
JSValue master = argv[1];
if (!JS_IsGCObject (val) || JS_IsNull (master)) return JS_FALSE;
if (!mist_is_gc_object (val) || JS_IsNull (master)) return JS_FALSE;
/* Walk prototype chain */
JSValue proto = JS_GetPrototype (ctx, val);
@@ -10513,7 +10493,7 @@ static JSValue js_cell_is_proto (JSContext *ctx, JSValue this_val, int argc, JSV
}
}
/* Also check if proto == master directly */
if (JS_IsGCObject (master)) {
if (mist_is_gc_object (master)) {
JSRecord *p1 = JS_VALUE_GET_OBJ (proto);
JSRecord *p2 = JS_VALUE_GET_OBJ (master);
if (p1 == p2) {
@@ -10956,7 +10936,7 @@ static int nota_stack_has (NotaEncodeContext *enc, JSValueConst val) {
int len = nota_get_arr_len (ctx, enc->visitedStack_ref->val);
for (int i = 0; i < len; i++) {
JSValue elem = JS_GetPropertyNumber (ctx, enc->visitedStack_ref->val, i);
if (JS_IsGCObject (elem) && JS_IsGCObject (val)) {
if (mist_is_gc_object (elem) && mist_is_gc_object (val)) {
if (JS_StrictEq (ctx, elem, val)) {
JS_FreeValue (ctx, elem);
return 1;