Thursday, 20 February 2025

[netsurf-dev] import node and owner

Hello,

I'm trying to implement replaceWith.
Code like this:

dom_node *el; // current node to be replaced
dom_node *new_child; // from other document
dom_node *imported_node;

dom_document *doc;

exc = dom_node_get_owner_document(el, &doc);
if (exc != DOM_NO_ERR) {
fprintf(stderr, "!doc\n");
fprintf(stderr, "exc=%d\n", exc);
return;
}

exc = dom_node_import_node(doc, new_child, true, &imported_node);
if (exc != DOM_NO_ERR) {
fprintf(stderr, "!imported\n");
fprintf(stderr, "exc=%d\n", exc);
return;
}

dom_node *parent = NULL;
exc = dom_node_get_parent_node(el, &parent);

if (exc != DOM_NO_ERR) {
fprintf(stderr, "!parent\n");
fprintf(stderr, "exc=%d\n", exc);
return;
}
dom_node *res = NULL;
exc = dom_node_replace_child(parent, imported_node, el, &res);

if (exc != DOM_NO_ERR) {
fprintf(stderr, "!replace\n");
fprintf(stderr, "exc=%d\n", exc);
return;
}

I tried various combinations, but the last exc is 4.

In code of libdom there is the dom_node_set_owner macro, but it is never called.
Is there a trick to make it work?
Or could you confirm that, there is a bug in the libdom library?
How to fix it?

Regards,
Witold Filipczyk

No comments:

Post a Comment