This commit is contained in:
2026-02-19 03:12:58 -06:00
parent ab43ab0d2c
commit 65fa37cc03
7 changed files with 886 additions and 54 deletions

View File

@@ -150,7 +150,10 @@ int JS_IsPretext (JSValue v) {
}
JSValue *JS_PushGCRef (JSContext *ctx, JSGCRef *ref) {
assert(ref != ctx->top_gc_ref && "JS_ROOT used in a loop — same address pushed twice");
if (ref == ctx->top_gc_ref) {
fprintf(stderr, "[warn] JS_PushGCRef duplicate top ref (non-fatal)\n");
return &ref->val;
}
ref->prev = ctx->top_gc_ref;
ctx->top_gc_ref = ref;
ref->val = JS_NULL;
@@ -158,13 +161,20 @@ JSValue *JS_PushGCRef (JSContext *ctx, JSGCRef *ref) {
}
JSValue JS_PopGCRef (JSContext *ctx, JSGCRef *ref) {
assert(ctx->top_gc_ref == ref && "JS_PopGCRef: not popping top of stack — mismatched push/pop");
ctx->top_gc_ref = ref->prev;
if (ctx->top_gc_ref == ref) {
ctx->top_gc_ref = ref->prev;
return ref->val;
}
fprintf(stderr, "[warn] JS_PopGCRef mismatched pop (non-fatal)\n");
return ref->val;
}
JSValue *JS_AddGCRef (JSContext *ctx, JSGCRef *ref) {
assert(ref != ctx->last_gc_ref && "JS_AddGCRef: same address added twice — cycle in GC ref list");
if (ref == ctx->last_gc_ref) {
fprintf(stderr, "[warn] JS_AddGCRef duplicate tail ref (non-fatal)\n");
return &ref->val;
}
ref->prev = ctx->last_gc_ref;
ctx->last_gc_ref = ref;
ref->val = JS_NULL;
@@ -10362,6 +10372,8 @@ static JSValue js_cell_pop (JSContext *ctx, JSValue this_val, int argc, JSValue
if (!JS_IsArray (obj)) return JS_NULL;
JSArray *arr = JS_VALUE_GET_ARRAY (obj);
if (objhdr_s (arr->mist_hdr))
return JS_RaiseDisrupt (ctx, "cannot pop from a stoned array");
if (arr->len == 0) return JS_NULL;