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

[quickjs] fragment.insertBefore

This commit is contained in:
Witold Filipczyk 2024-09-16 17:28:42 +02:00
parent 62f20202eb
commit 1dc1b8145b

View File

@ -1224,34 +1224,40 @@ js_fragment_insertBefore(JSContext *ctx, JSValueConst this_val, int argc, JSValu
dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id));
if (!el) {
return JS_UNDEFINED;
return JS_EXCEPTION;
}
//dom_node_ref(el);
JSValue next_sibling1 = argv[1];
JSValue child1 = argv[0];
dom_node *next_sibling = (dom_node *)(js_getopaque_fragment(next_sibling1, js_fragment_class_id));
dom_node *next_sibling = NULL;
dom_node *child = NULL;
if (!next_sibling) {
//dom_node_unref(el);
return JS_NULL;
if (!JS_IsNull(next_sibling1)) {
next_sibling = (dom_node *)(js_getopaque_any(next_sibling1));
}
dom_node *child = (dom_node *)(js_getopaque_fragment(child1, js_fragment_class_id));
if (!JS_IsNull(child1)) {
child = (dom_node *)(js_getopaque_any(child1));
}
dom_exception err;
dom_node *spare;
if (!child) {
return JS_EXCEPTION;
}
dom_node *spare = NULL;
dom_exception err = dom_node_insert_before(el, child, next_sibling, &spare);
err = dom_node_insert_before(el, child, next_sibling, &spare);
if (err != DOM_NO_ERR) {
if (err != DOM_NO_ERR || !spare) {
//dom_node_unref(el);
return JS_UNDEFINED;
return JS_EXCEPTION;
}
interpreter->changed = 1;
//dom_node_unref(el);
return getElement(ctx, spare);
JSValue rr = getElement(ctx, spare);
dom_node_unref(spare);
return rr;
}
static JSValue