mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 20:16:54 +03:00
Make dom node children iterator return nserror.
This commit is contained in:
parent
473738083b
commit
ee7df2761f
@ -629,8 +629,9 @@ static void tree_url_load_entry(dom_node *li, tree_url_load_ctx *ctx)
|
||||
dom_node_unref(a);
|
||||
}
|
||||
|
||||
static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
static nserror tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
{
|
||||
/* TODO: return appropriate errors */
|
||||
tree_url_load_ctx *tctx = ctx;
|
||||
dom_string *name;
|
||||
dom_exception error;
|
||||
@ -641,7 +642,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
|
||||
error = dom_node_get_node_name(node, &name);
|
||||
if (error != DOM_NO_ERR || name == NULL)
|
||||
return false;
|
||||
return NSERROR_NOMEM;
|
||||
|
||||
if (dom_string_caseless_lwc_isequal(name, corestring_lwc_li)) {
|
||||
/* entry */
|
||||
@ -656,7 +657,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
warn_user("TreeLoadError", "(Empty <h4> "
|
||||
"or memory exhausted.)");
|
||||
dom_string_unref(name);
|
||||
return false;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
if (tctx->title != NULL)
|
||||
@ -675,7 +676,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
error = dom_element_get_attribute(node, corestring_dom_id, &id);
|
||||
if (error != DOM_NO_ERR) {
|
||||
dom_string_unref(name);
|
||||
return false;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
if (id != NULL) {
|
||||
@ -691,7 +692,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
dom_string_byte_length(tctx->title));
|
||||
if (title == NULL) {
|
||||
dom_string_unref(name);
|
||||
return false;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
dir = tree_create_folder_node(tctx->tree, tctx->directory,
|
||||
@ -699,7 +700,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
free(title);
|
||||
if (dir == NULL) {
|
||||
dom_string_unref(name);
|
||||
return false;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
if (dir_is_default)
|
||||
@ -732,7 +733,7 @@ static bool tree_url_load_directory_cb(dom_node *node, void *ctx)
|
||||
|
||||
dom_string_unref(name);
|
||||
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,7 +211,8 @@ dom_node *libdom_find_first_element(dom_node *parent, lwc_string *element_name)
|
||||
}
|
||||
|
||||
/* exported interface documented in libdom.h */
|
||||
void libdom_iterate_child_elements(dom_node *parent,
|
||||
/* TODO: return appropriate errors */
|
||||
nserror libdom_iterate_child_elements(dom_node *parent,
|
||||
libdom_iterate_cb cb, void *ctx)
|
||||
{
|
||||
dom_nodelist *children;
|
||||
@ -220,12 +221,12 @@ void libdom_iterate_child_elements(dom_node *parent,
|
||||
|
||||
error = dom_node_get_child_nodes(parent, &children);
|
||||
if (error != DOM_NO_ERR || children == NULL)
|
||||
return;
|
||||
return NSERROR_NOMEM;
|
||||
|
||||
error = dom_nodelist_get_length(children, &num_children);
|
||||
if (error != DOM_NO_ERR) {
|
||||
dom_nodelist_unref(children);
|
||||
return;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
for (index = 0; index < num_children; index++) {
|
||||
@ -235,15 +236,16 @@ void libdom_iterate_child_elements(dom_node *parent,
|
||||
error = dom_nodelist_item(children, index, &child);
|
||||
if (error != DOM_NO_ERR) {
|
||||
dom_nodelist_unref(children);
|
||||
return;
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
|
||||
error = dom_node_get_node_type(child, &type);
|
||||
if (error == DOM_NO_ERR && type == DOM_ELEMENT_NODE) {
|
||||
if (cb(child, ctx) == false) {
|
||||
nserror err = cb(child, ctx);
|
||||
if (err != NSERROR_OK) {
|
||||
dom_node_unref(child);
|
||||
dom_nodelist_unref(children);
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,6 +253,8 @@ void libdom_iterate_child_elements(dom_node *parent,
|
||||
}
|
||||
|
||||
dom_nodelist_unref(children);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/* exported interface documented in libdom.h */
|
||||
|
@ -61,9 +61,9 @@ dom_node *libdom_find_element(dom_node *node, lwc_string *element_name);
|
||||
*/
|
||||
dom_node *libdom_find_first_element(dom_node *parent, lwc_string *element_name);
|
||||
|
||||
typedef bool (*libdom_iterate_cb)(dom_node *node, void *ctx);
|
||||
typedef nserror (*libdom_iterate_cb)(dom_node *node, void *ctx);
|
||||
|
||||
void libdom_iterate_child_elements(dom_node *parent,
|
||||
nserror libdom_iterate_child_elements(dom_node *parent,
|
||||
libdom_iterate_cb cb, void *ctx);
|
||||
|
||||
nserror libdom_parse_file(const char *filename, const char *encoding,
|
||||
|
Loading…
Reference in New Issue
Block a user