Added more control over the GC events, and callbacks before the event

This commit is contained in:
karurochari 2024-05-16 02:31:15 +00:00
parent 5a7e578482
commit 9b5dda0e76
2 changed files with 7 additions and 0 deletions

View file

@ -241,6 +241,9 @@ struct JSRuntime {
struct list_head tmp_obj_list; /* used during GC */
JSGCPhaseEnum gc_phase : 8;
size_t malloc_gc_threshold;
BOOL malloc_gc_fix_threshold : 8;
BOOL (*malloc_gc_before_callback)();
void (*malloc_gc_after_callback)();
#ifdef DUMP_LEAKS
struct list_head string_list; /* list of JSString.link */
#endif

View file

@ -302,6 +302,10 @@ JS_EXTERN void JS_SetRuntimeInfo(JSRuntime *rt, const char *info);
JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit);
JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags);
JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);
JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt);
JS_EXTERN void JS_SetGCThresholdFixed(JSRuntime *rt, BOOL fixed);
JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, BOOL(*fn)());
JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)());
/* use 0 to disable maximum stack size check */
JS_EXTERN void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size);
/* should be called when changing thread to update the stack top value