1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[quickjs] nodelist ref|unref

This commit is contained in:
Witold Filipczyk 2024-06-19 18:38:14 +02:00
parent 8d6f26c1d8
commit 6663e06981

View File

@ -67,11 +67,14 @@ js_nodeList_get_property_length(JSContext *ctx, JSValueConst this_val)
if (!nl) { if (!nl) {
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
dom_nodelist_ref(nl);
err = dom_nodelist_get_length(nl, &size); err = dom_nodelist_get_length(nl, &size);
if (err != DOM_NO_ERR) { if (err != DOM_NO_ERR) {
dom_nodelist_unref(nl);
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
dom_nodelist_unref(nl);
return JS_NewInt32(ctx, size); return JS_NewInt32(ctx, size);
} }
@ -92,13 +95,16 @@ js_nodeList_item2(JSContext *ctx, JSValueConst this_val, int idx)
if (!nl) { if (!nl) {
return JS_UNDEFINED; return JS_UNDEFINED;
} }
dom_nodelist_ref(nl);
err = dom_nodelist_item(nl, idx, (void *)&element); err = dom_nodelist_item(nl, idx, (void *)&element);
if (err != DOM_NO_ERR || !element) { if (err != DOM_NO_ERR || !element) {
dom_nodelist_unref(nl);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
ret = getElement(ctx, element); ret = getElement(ctx, element);
dom_node_unref(element); dom_node_unref(element);
dom_nodelist_unref(nl);
return ret; return ret;
} }
@ -136,9 +142,11 @@ js_nodeList_set_items(JSContext *ctx, JSValue this_val, void *node)
if (!nl) { if (!nl) {
return; return;
} }
dom_nodelist_ref(nl);
err = dom_nodelist_get_length(nl, &length); err = dom_nodelist_get_length(nl, &length);
if (err != DOM_NO_ERR) { if (err != DOM_NO_ERR) {
dom_nodelist_unref(nl);
return; return;
} }
@ -158,6 +166,7 @@ js_nodeList_set_items(JSContext *ctx, JSValue this_val, void *node)
JS_FreeValue(ctx, obj); JS_FreeValue(ctx, obj);
dom_node_unref(element); dom_node_unref(element);
} }
dom_nodelist_unref(nl);
} }
static JSValue static JSValue