From 41aeb86714988e04ee15f17e8aad71bc2abf3986 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Tue, 24 Jan 2023 19:18:36 +0100 Subject: [PATCH] [quickjs] gc_mark in element --- src/ecmascript/quickjs/element.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/quickjs/element.cpp b/src/ecmascript/quickjs/element.cpp index fed204bd6..e6a9a6a0f 100644 --- a/src/ecmascript/quickjs/element.cpp +++ b/src/ecmascript/quickjs/element.cpp @@ -2096,9 +2096,32 @@ void js_element_finalizer(JSRuntime *rt, JSValue val) } } +static void +js_element_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + REF_JS(val); + + struct js_element_private *el_private = (struct js_element_private *)JS_GetOpaque(val, js_element_class_id); + + if (el_private) { + JS_MarkValue(rt, el_private->thisval, mark_func); + + struct listener *l; + + foreach(l, el_private->listeners) { + JS_MarkValue(rt, l->fun, mark_func); + } + } +} + + static JSClassDef js_element_class = { "Element", - js_element_finalizer + .finalizer = js_element_finalizer, + .gc_mark = js_element_mark, }; int @@ -2170,7 +2193,7 @@ getElement(JSContext *ctx, void *node) map_privates[node] = el_private; JSValue rr = JS_DupValue(ctx, element_obj); - el_private->thisval = rr; + el_private->thisval = JS_DupValue(ctx, rr); RETURN_JS(rr); }