quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Add JS_DumpObjects support

Open HarlonWang opened this issue 1 year ago • 3 comments

To analyze memory leaks and usage more accurately, it would be great to expose JS_DumpObjects . image

HarlonWang avatar Sep 19 '24 02:09 HarlonWang

It would be nice if the function got a FILE *f parameter so it would work with any stream other than stdout too.

saghul avatar Sep 19 '24 08:09 saghul

I also think that's better, but the changes to the original logic will be quite extensive. The following methods will all need adjustments(add a FILE *f parameter).

static __maybe_unused void JS_DumpAtoms(JSRuntime *rt);
static __maybe_unused void JS_DumpString(JSRuntime *rt, const JSString *p);
static __maybe_unused void JS_DumpObjectHeader(JSRuntime *rt);
static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p);
static __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHeader *p);
static __maybe_unused void JS_DumpValueShort(JSRuntime *rt, JSValueConst val);
static __maybe_unused void JS_DumpValue(JSContext *ctx, JSValueConst val);

I can try making these changes, but I'm not sure if they'll be accepted.

Do you have any better suggestions? @saghul

By the way, I often use this method to analyze leaked objects. in my use case, I achieved writing to a file by proxying stdout, so it would be great if this could be officially supported.

HarlonWang avatar Sep 19 '24 09:09 HarlonWang

I'd accept the change in the friendly fork though ;-)

saghul avatar Sep 19 '24 09:09 saghul