fix intrinsics and env

This commit is contained in:
2026-02-16 23:05:00 -06:00
parent 63955e45ff
commit c9dad91ea1
13 changed files with 94696 additions and 86771 deletions

View File

@@ -1688,6 +1688,34 @@ int ctx_gc (JSContext *ctx, int allow_grow, size_t alloc_size) {
scan += obj_size;
}
#ifdef VALIDATE_GC
{
JSRecord *grec = JS_VALUE_GET_RECORD(ctx->global_obj);
uint32_t mask = (uint32_t)objhdr_cap56(grec->mist_hdr);
for (uint32_t i = 1; i <= mask; i++) {
JSValue k = grec->slots[i].key;
if (!rec_key_is_empty(k) && !rec_key_is_tomb(k)) {
if (!JS_IsPtr(k)) {
fprintf(stderr, "VALIDATE_GC: global slot[%u] key is not a pointer (tag=0x%llx)\n",
i, (unsigned long long)k);
} else {
void *kp = JS_VALUE_GET_PTR(k);
if (!ptr_in_range(kp, to_base, to_free) && !is_ct_ptr(ctx, kp)) {
fprintf(stderr, "VALIDATE_GC: global slot[%u] key=%p outside valid ranges\n", i, kp);
}
}
JSValue v = grec->slots[i].val;
if (JS_IsPtr(v)) {
void *vp = JS_VALUE_GET_PTR(v);
if (!ptr_in_range(vp, to_base, to_free) && !is_ct_ptr(ctx, vp)) {
fprintf(stderr, "VALIDATE_GC: global slot[%u] val=%p outside valid ranges\n", i, vp);
}
}
}
}
}
#endif
/* Return old block (in poison mode, just poison it and leak) */
heap_block_free (rt, from_base, old_heap_size);
@@ -1960,6 +1988,7 @@ JSContext *JS_NewContext (JSRuntime *rt) {
if (!ctx) return NULL;
JS_AddIntrinsicBaseObjects (ctx);
JS_AddIntrinsicRegExp (ctx);
obj_set_stone (JS_VALUE_GET_RECORD (ctx->global_obj));
return ctx;
}
@@ -1967,7 +1996,8 @@ JSContext *JS_NewContextWithHeapSize (JSRuntime *rt, size_t heap_size) {
JSContext *ctx = JS_NewContextRawWithHeapSize (rt, heap_size);
if (!ctx) return NULL;
JS_AddIntrinsicBaseObjects (ctx);
JS_AddIntrinsicRegExp (ctx);
JS_AddIntrinsicRegExp (ctx);
obj_set_stone (JS_VALUE_GET_RECORD (ctx->global_obj));
return ctx;
}