1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

[quickjs] document ref|unref

This commit is contained in:
Witold Filipczyk 2024-06-19 17:34:17 +02:00
parent d67e8ce58b
commit 7c18364e9a

View File

@ -95,14 +95,17 @@ js_document_get_property_anchors(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_collection *anchors = NULL; dom_html_collection *anchors = NULL;
dom_exception exc = dom_html_document_get_anchors(doc, &anchors); dom_exception exc = dom_html_document_get_anchors(doc, &anchors);
if (exc != DOM_NO_ERR || !anchors) { if (exc != DOM_NO_ERR || !anchors) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
JSValue rr = getCollection(ctx, anchors); JSValue rr = getCollection(ctx, anchors);
JS_FreeValue(ctx, rr); JS_FreeValue(ctx, rr);
dom_node_unref(doc);
RETURN_JS(rr); RETURN_JS(rr);
} }
@ -155,12 +158,16 @@ js_document_get_property_body(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_element *body = NULL; dom_html_element *body = NULL;
dom_exception exc = dom_html_document_get_body(doc, &body); dom_exception exc = dom_html_document_get_body(doc, &body);
if (exc != DOM_NO_ERR || !body) { if (exc != DOM_NO_ERR || !body) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, body); return getElement(ctx, body);
} }
@ -283,10 +290,13 @@ js_document_get_property_childNodes(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_element *root = NULL; dom_element *root = NULL;
dom_exception exc = dom_document_get_document_element(doc, &root); dom_exception exc = dom_document_get_document_element(doc, &root);
if (exc != DOM_NO_ERR || !root) { if (exc != DOM_NO_ERR || !root) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_nodelist *nodes = NULL; dom_nodelist *nodes = NULL;
@ -294,8 +304,10 @@ js_document_get_property_childNodes(JSContext *ctx, JSValueConst this_val)
dom_node_unref(root); dom_node_unref(root);
if (exc != DOM_NO_ERR || !nodes) { if (exc != DOM_NO_ERR || !nodes) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getNodeList(ctx, nodes); return getNodeList(ctx, nodes);
} }
@ -325,8 +337,11 @@ js_document_get_property_doctype(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_document_type *dtd; dom_document_type *dtd;
dom_document_get_doctype(doc, &dtd); dom_document_get_doctype(doc, &dtd);
dom_node_unref(doc);
return getDoctype(ctx, dtd); return getDoctype(ctx, dtd);
} }
@ -345,12 +360,16 @@ js_document_get_property_documentElement(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_element *root = NULL; dom_html_element *root = NULL;
dom_exception exc = dom_document_get_document_element(doc, &root); dom_exception exc = dom_document_get_document_element(doc, &root);
if (exc != DOM_NO_ERR || !root) { if (exc != DOM_NO_ERR || !root) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, root); return getElement(ctx, root);
} }
@ -434,14 +453,18 @@ js_document_get_property_forms(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_collection *forms = NULL; dom_html_collection *forms = NULL;
dom_exception exc = dom_html_document_get_forms(doc, &forms); dom_exception exc = dom_html_document_get_forms(doc, &forms);
if (exc != DOM_NO_ERR || !forms) { if (exc != DOM_NO_ERR || !forms) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
JSValue rr = getForms(ctx, forms); JSValue rr = getForms(ctx, forms);
JS_FreeValue(ctx, rr); JS_FreeValue(ctx, rr);
dom_node_unref(doc);
RETURN_JS(rr); RETURN_JS(rr);
} }
@ -475,14 +498,18 @@ js_document_get_property_images(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_collection *images = NULL; dom_html_collection *images = NULL;
dom_exception exc = dom_html_document_get_images(doc, &images); dom_exception exc = dom_html_document_get_images(doc, &images);
if (exc != DOM_NO_ERR || !images) { if (exc != DOM_NO_ERR || !images) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
JSValue rr = getCollection(ctx, images); JSValue rr = getCollection(ctx, images);
JS_FreeValue(ctx, rr); JS_FreeValue(ctx, rr);
dom_node_unref(doc);
RETURN_JS(rr); RETURN_JS(rr);
} }
@ -512,14 +539,17 @@ js_document_get_property_links(JSContext *ctx, JSValueConst this_val)
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_html_collection *links = NULL; dom_html_collection *links = NULL;
dom_exception exc = dom_html_document_get_links(doc, &links); dom_exception exc = dom_html_document_get_links(doc, &links);
if (exc != DOM_NO_ERR || !links) { if (exc != DOM_NO_ERR || !links) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
JSValue rr = getCollection(ctx, links); JSValue rr = getCollection(ctx, links);
JS_FreeValue(ctx, rr); JS_FreeValue(ctx, rr);
dom_node_unref(doc);
RETURN_JS(rr); RETURN_JS(rr);
} }
@ -1006,8 +1036,10 @@ js_document_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JS
return JS_NULL; return JS_NULL;
} }
dom_document *doc = doc_private->node; dom_document *doc = doc_private->node;
dom_node_ref(doc);
if (argc < 2) { if (argc < 2) {
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
const char *str; const char *str;
@ -1015,6 +1047,7 @@ js_document_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JS
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
char *method = stracpy(str); char *method = stracpy(str);
@ -1033,12 +1066,14 @@ js_document_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JS
if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) { if (JS_VALUE_GET_PTR(l->fun) == JS_VALUE_GET_PTR(fun)) {
mem_free(method); mem_free(method);
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
} }
struct document_listener *n = (struct document_listener *)mem_calloc(1, sizeof(*n)); struct document_listener *n = (struct document_listener *)mem_calloc(1, sizeof(*n));
if (!n) { if (!n) {
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
n->fun = fun; n->fun = fun;
@ -1052,6 +1087,7 @@ js_document_addEventListener(JSContext *ctx, JSValueConst this_val, int argc, JS
exc = dom_event_listener_create(document_event_handler, doc_private, &doc_private->listener); exc = dom_event_listener_create(document_event_handler, doc_private, &doc_private->listener);
if (exc != DOM_NO_ERR || !doc_private->listener) { if (exc != DOM_NO_ERR || !doc_private->listener) {
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
} }
@ -1072,6 +1108,7 @@ ex:
dom_string_unref(typ); dom_string_unref(typ);
} }
dom_event_listener_unref(doc_private->listener); dom_event_listener_unref(doc_private->listener);
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
@ -1094,15 +1131,26 @@ js_document_dispatchEvent(JSContext *ctx, JSValueConst this_val, int argc, JSVal
if (!doc) { if (!doc) {
return JS_FALSE; return JS_FALSE;
} }
dom_node_ref(doc);
if (argc < 1) { if (argc < 1) {
dom_node_unref(doc);
return JS_FALSE; return JS_FALSE;
} }
JSValue eve = argv[0]; JSValue eve = argv[0];
dom_event *event = (dom_event *)(JS_GetOpaque(eve, js_event_class_id)); dom_event *event = (dom_event *)(JS_GetOpaque(eve, js_event_class_id));
if (event) {
dom_event_ref(event);
}
bool result = false; bool result = false;
dom_exception exc = dom_event_target_dispatch_event(doc, event, &result); dom_exception exc = dom_event_target_dispatch_event(doc, event, &result);
if (event) {
dom_event_unref(event);
}
dom_node_unref(doc);
return JS_NewBool(ctx, result); return JS_NewBool(ctx, result);
} }
@ -1120,8 +1168,10 @@ js_document_removeEventListener(JSContext *ctx, JSValueConst this_val, int argc,
return JS_NULL; return JS_NULL;
} }
dom_document *doc = (dom_document *)doc_private->node; dom_document *doc = (dom_document *)doc_private->node;
dom_node_ref(doc);
if (argc < 2) { if (argc < 2) {
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
const char *str; const char *str;
@ -1129,12 +1179,14 @@ js_document_removeEventListener(JSContext *ctx, JSValueConst this_val, int argc,
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
char *method = stracpy(str); char *method = stracpy(str);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (!method) { if (!method) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
JSValue fun = argv[1]; JSValue fun = argv[1];
@ -1159,11 +1211,13 @@ js_document_removeEventListener(JSContext *ctx, JSValueConst this_val, int argc,
mem_free_set(&l->typ, NULL); mem_free_set(&l->typ, NULL);
mem_free(l); mem_free(l);
mem_free(method); mem_free(method);
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
} }
mem_free(method); mem_free(method);
dom_node_unref(doc);
return JS_UNDEFINED; return JS_UNDEFINED;
} }
@ -1185,6 +1239,8 @@ js_document_createComment(JSContext *ctx, JSValueConst this_val, int argc, JSVal
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_string *data = NULL; dom_string *data = NULL;
dom_exception exc; dom_exception exc;
const char *str; const char *str;
@ -1193,12 +1249,14 @@ js_document_createComment(JSContext *ctx, JSValueConst this_val, int argc, JSVal
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
exc = dom_string_create((const uint8_t *)str, len, &data); exc = dom_string_create((const uint8_t *)str, len, &data);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (exc != DOM_NO_ERR || !data) { if (exc != DOM_NO_ERR || !data) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_comment *comment = NULL; dom_comment *comment = NULL;
@ -1206,8 +1264,10 @@ js_document_createComment(JSContext *ctx, JSValueConst this_val, int argc, JSVal
dom_string_unref(data); dom_string_unref(data);
if (exc != DOM_NO_ERR || !comment) { if (exc != DOM_NO_ERR || !comment) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, comment); return getElement(ctx, comment);
} }
@ -1229,12 +1289,16 @@ js_document_createDocumentFragment(JSContext *ctx, JSValueConst this_val, int ar
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_document_fragment *fragment = NULL; dom_document_fragment *fragment = NULL;
dom_exception exc = dom_document_create_document_fragment(doc, &fragment); dom_exception exc = dom_document_create_document_fragment(doc, &fragment);
if (exc != DOM_NO_ERR || !fragment) { if (exc != DOM_NO_ERR || !fragment) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, fragment); return getElement(ctx, fragment);
} }
@ -1256,6 +1320,8 @@ js_document_createElement(JSContext *ctx, JSValueConst this_val, int argc, JSVal
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_string *tag_name = NULL; dom_string *tag_name = NULL;
dom_exception exc; dom_exception exc;
const char *str; const char *str;
@ -1264,12 +1330,14 @@ js_document_createElement(JSContext *ctx, JSValueConst this_val, int argc, JSVal
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
exc = dom_string_create((const uint8_t *)str, len, &tag_name); exc = dom_string_create((const uint8_t *)str, len, &tag_name);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (exc != DOM_NO_ERR || !tag_name) { if (exc != DOM_NO_ERR || !tag_name) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_element *element = NULL; dom_element *element = NULL;
@ -1277,8 +1345,10 @@ js_document_createElement(JSContext *ctx, JSValueConst this_val, int argc, JSVal
dom_string_unref(tag_name); dom_string_unref(tag_name);
if (exc != DOM_NO_ERR || !element) { if (exc != DOM_NO_ERR || !element) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, element); return getElement(ctx, element);
} }
@ -1300,6 +1370,8 @@ js_document_createTextNode(JSContext *ctx, JSValueConst this_val, int argc, JSVa
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_string *data = NULL; dom_string *data = NULL;
dom_exception exc; dom_exception exc;
const char *str; const char *str;
@ -1308,12 +1380,14 @@ js_document_createTextNode(JSContext *ctx, JSValueConst this_val, int argc, JSVa
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
exc = dom_string_create((const uint8_t *)str, len, &data); exc = dom_string_create((const uint8_t *)str, len, &data);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (exc != DOM_NO_ERR || !data) { if (exc != DOM_NO_ERR || !data) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_text *text_node = NULL; dom_text *text_node = NULL;
@ -1321,8 +1395,10 @@ js_document_createTextNode(JSContext *ctx, JSValueConst this_val, int argc, JSVa
dom_string_unref(data); dom_string_unref(data);
if (exc != DOM_NO_ERR || !text_node) { if (exc != DOM_NO_ERR || !text_node) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, text_node); return getElement(ctx, text_node);
} }
@ -1344,6 +1420,8 @@ js_document_getElementById(JSContext *ctx, JSValueConst this_val, int argc, JSVa
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_string *id = NULL; dom_string *id = NULL;
dom_exception exc; dom_exception exc;
const char *str; const char *str;
@ -1352,12 +1430,14 @@ js_document_getElementById(JSContext *ctx, JSValueConst this_val, int argc, JSVa
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
exc = dom_string_create((const uint8_t *)str, len, &id); exc = dom_string_create((const uint8_t *)str, len, &id);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (exc != DOM_NO_ERR || !id) { if (exc != DOM_NO_ERR || !id) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_element *element = NULL; dom_element *element = NULL;
@ -1365,8 +1445,10 @@ js_document_getElementById(JSContext *ctx, JSValueConst this_val, int argc, JSVa
dom_string_unref(id); dom_string_unref(id);
if (exc != DOM_NO_ERR || !element) { if (exc != DOM_NO_ERR || !element) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, element); return getElement(ctx, element);
} }
@ -1482,6 +1564,8 @@ js_document_getElementsByTagName(JSContext *ctx, JSValueConst this_val, int argc
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_string *tagname = NULL; dom_string *tagname = NULL;
dom_exception exc; dom_exception exc;
const char *str; const char *str;
@ -1490,12 +1574,14 @@ js_document_getElementsByTagName(JSContext *ctx, JSValueConst this_val, int argc
str = JS_ToCStringLen(ctx, &len, argv[0]); str = JS_ToCStringLen(ctx, &len, argv[0]);
if (!str) { if (!str) {
dom_node_unref(doc);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
exc = dom_string_create((const uint8_t *)str, len, &tagname); exc = dom_string_create((const uint8_t *)str, len, &tagname);
JS_FreeCString(ctx, str); JS_FreeCString(ctx, str);
if (exc != DOM_NO_ERR || !tagname) { if (exc != DOM_NO_ERR || !tagname) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_nodelist *nodes = NULL; dom_nodelist *nodes = NULL;
@ -1503,9 +1589,11 @@ js_document_getElementsByTagName(JSContext *ctx, JSValueConst this_val, int argc
dom_string_unref(tagname); dom_string_unref(tagname);
if (exc != DOM_NO_ERR || !nodes) { if (exc != DOM_NO_ERR || !nodes) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
JSValue rr = getNodeList(ctx, nodes); JSValue rr = getNodeList(ctx, nodes);
dom_node_unref(doc);
RETURN_JS(rr); RETURN_JS(rr);
} }
@ -1527,17 +1615,21 @@ js_document_querySelector(JSContext *ctx, JSValueConst this_val, int argc, JSVal
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_node *root = NULL; /* root element of document */ dom_node *root = NULL; /* root element of document */
/* Get root element */ /* Get root element */
dom_exception exc = dom_document_get_document_element(doc, &root); dom_exception exc = dom_document_get_document_element(doc, &root);
if (exc != DOM_NO_ERR) { if (exc != DOM_NO_ERR) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
size_t len; size_t len;
const char *selector = JS_ToCStringLen(ctx, &len, argv[0]); const char *selector = JS_ToCStringLen(ctx, &len, argv[0]);
if (!selector) { if (!selector) {
dom_node_unref(doc);
dom_node_unref(root); dom_node_unref(root);
return JS_NULL; return JS_NULL;
} }
@ -1546,8 +1638,11 @@ js_document_querySelector(JSContext *ctx, JSValueConst this_val, int argc, JSVal
dom_node_unref(root); dom_node_unref(root);
if (!ret) { if (!ret) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getElement(ctx, ret); return getElement(ctx, ret);
} }
@ -1568,17 +1663,20 @@ js_document_querySelectorAll(JSContext *ctx, JSValueConst this_val, int argc, JS
if (!doc) { if (!doc) {
return JS_NULL; return JS_NULL;
} }
dom_node_ref(doc);
dom_node *doc_root = NULL; /* root element of document */ dom_node *doc_root = NULL; /* root element of document */
/* Get root element */ /* Get root element */
dom_exception exc = dom_document_get_document_element(doc, &doc_root); dom_exception exc = dom_document_get_document_element(doc, &doc_root);
if (exc != DOM_NO_ERR) { if (exc != DOM_NO_ERR) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
size_t len; size_t len;
const char *selector = JS_ToCStringLen(ctx, &len, argv[0]); const char *selector = JS_ToCStringLen(ctx, &len, argv[0]);
if (!selector) { if (!selector) {
dom_node_unref(doc);
dom_node_unref(doc_root); dom_node_unref(doc_root);
return JS_NULL; return JS_NULL;
} }
@ -1587,6 +1685,7 @@ js_document_querySelectorAll(JSContext *ctx, JSValueConst this_val, int argc, JS
exc = dom_string_create((const uint8_t *)"B", 1, &tag_name); exc = dom_string_create((const uint8_t *)"B", 1, &tag_name);
if (exc != DOM_NO_ERR || !tag_name) { if (exc != DOM_NO_ERR || !tag_name) {
dom_node_unref(doc);
dom_node_unref(doc_root); dom_node_unref(doc_root);
JS_FreeCString(ctx, selector); JS_FreeCString(ctx, selector);
return JS_NULL; return JS_NULL;
@ -1596,6 +1695,7 @@ js_document_querySelectorAll(JSContext *ctx, JSValueConst this_val, int argc, JS
dom_string_unref(tag_name); dom_string_unref(tag_name);
if (exc != DOM_NO_ERR || !element) { if (exc != DOM_NO_ERR || !element) {
dom_node_unref(doc);
dom_node_unref(doc_root); dom_node_unref(doc_root);
JS_FreeCString(ctx, selector); JS_FreeCString(ctx, selector);
return JS_NULL; return JS_NULL;
@ -1609,8 +1709,11 @@ js_document_querySelectorAll(JSContext *ctx, JSValueConst this_val, int argc, JS
dom_node_unref(element); dom_node_unref(element);
if (exc != DOM_NO_ERR || !nodes) { if (exc != DOM_NO_ERR || !nodes) {
dom_node_unref(doc);
return JS_NULL; return JS_NULL;
} }
dom_node_unref(doc);
return getNodeList(ctx, nodes); return getNodeList(ctx, nodes);
} }