summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2018-08-03 12:03:20 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2018-08-03 12:03:20 +0100
commit4e75ebae52fc71336141f95dc83971b51002a104 (patch)
tree281d6b9b3364a375e2b8af8e71391aec9c2315d9 /src
parentf09983f45ee5f22e0df44a7c1d7ea85f7336efe2 (diff)
downloadlibdom-4e75ebae52fc71336141f95dc83971b51002a104.tar.gz
libdom-4e75ebae52fc71336141f95dc83971b51002a104.tar.bz2
HTMLTableElement.insertRow: Fix lifetimes and error handling.
Diffstat (limited to 'src')
-rw-r--r--src/html/html_table_element.c126
1 files changed, 74 insertions, 52 deletions
diff --git a/src/html/html_table_element.c b/src/html/html_table_element.c
index 7e8a508..82dbca0 100644
--- a/src/html/html_table_element.c
+++ b/src/html/html_table_element.c
@@ -726,6 +726,7 @@ static dom_exception dom_html_table_element_create_t_body(
dom_html_collection_unref(t_bodies);
return exp;
}
+
/**
* Insert a new Row into the table
*
@@ -736,39 +737,22 @@ static dom_exception dom_html_table_element_create_t_body(
dom_exception dom_html_table_element_insert_row(
dom_html_table_element *element,
int32_t index,
- dom_html_element **row)
+ dom_html_element **row_out)
{
dom_exception exp;
+ dom_html_table_row_element *row;
dom_html_collection* rows;
uint32_t len;
dom_html_document *doc = (dom_html_document *)
((dom_node_internal *) element)->owner;
- struct dom_html_element_create_params params = {
- .type = DOM_HTML_ELEMENT_TYPE_TR,
- .doc = doc,
- .name = doc->elements[DOM_HTML_ELEMENT_TYPE_TR],
- .namespace = ((dom_node_internal *)element)->namespace,
- .prefix = ((dom_node_internal *)element)->prefix
- };
-
- exp = dom_html_table_element_get_rows(element,
- &rows);
+ exp = dom_html_table_element_get_rows(element, &rows);
if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
return exp;
}
- exp = dom_html_collection_get_length(rows,
- &len);
- if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
- return exp;
- }
- exp = _dom_html_table_row_element_create(&params,
- (dom_html_table_row_element **)row);
+ exp = dom_html_collection_get_length(rows, &len);
+ dom_html_collection_unref(rows);
if(exp != DOM_NO_ERR) {
- dom_node_unref(*row);
- dom_html_collection_unref(rows);
return exp;
}
@@ -777,19 +761,31 @@ dom_exception dom_html_table_element_insert_row(
} else if(len == 0) {
dom_html_table_section_element *new_body;
dom_node *new_row;
- exp = dom_html_table_element_create_t_body(element,
- &new_body);
+
+ struct dom_html_element_create_params params = {
+ .type = DOM_HTML_ELEMENT_TYPE_TR,
+ .doc = doc,
+ .name = doc->elements[DOM_HTML_ELEMENT_TYPE_TR],
+ .namespace = ((dom_node_internal *)element)->namespace,
+ .prefix = ((dom_node_internal *)element)->prefix
+ };
+
+ exp = _dom_html_table_row_element_create(&params, &row);
if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
- dom_node_unref(new_body);
return exp;
}
- exp = dom_node_append_child(new_body, *row,
- &new_row);
+ exp = dom_html_table_element_create_t_body(element, &new_body);
+ if(exp != DOM_NO_ERR) {
+ dom_node_unref(row);
+ return exp;
+ }
+
+ exp = dom_node_append_child(new_body, row, &new_row);
+ dom_node_unref(new_body);
+ dom_node_unref(row);
if(exp == DOM_NO_ERR) {
- dom_node_unref(*row);
- *row = (dom_html_element *)new_row;
+ *row_out = (dom_html_element *)new_row;
}
} else {
uint32_t window_len = 0, section_len;
@@ -802,83 +798,109 @@ dom_exception dom_html_table_element_insert_row(
}
exp = dom_html_table_element_get_t_head(element, &t_head);
- if (exp != DOM_NO_ERR)
+ if (exp != DOM_NO_ERR) {
return exp;
-
- dom_html_collection_unref(rows);
+ }
exp = dom_html_table_section_element_get_rows(t_head, &rows);
if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
+ dom_node_unref(t_head);
return exp;
}
- dom_html_collection_get_length(rows, &section_len);
+ exp = dom_html_collection_get_length(rows, &section_len);
+ dom_html_collection_unref(rows);
if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
+ dom_node_unref(t_head);
return exp;
}
if(window_len + section_len > (uint32_t)index ||
window_len + section_len == len) {
- dom_html_collection_unref(rows);
- return dom_html_table_section_element_insert_row(t_head,
- index-window_len, row);
+ exp = dom_html_table_section_element_insert_row(t_head,
+ index-window_len,
+ (struct dom_html_element **)&row);
+ dom_node_unref(t_head);
+ if (exp == DOM_NO_ERR) {
+ *row_out = (dom_html_element *)row;
+ }
+ return exp;
}
+ dom_node_unref(t_head);
window_len += section_len;
n = (dom_node_internal *)element;
- dom_html_collection_unref(rows);
-
for (n = n->first_child; n != NULL; n = n->next) {
if((n->type == DOM_ELEMENT_NODE) &&
dom_string_caseless_isequal(
doc->elements[DOM_HTML_ELEMENT_TYPE_TBODY],
n->name)) {
- exp = dom_html_table_section_element_get_rows((dom_html_table_section_element *)n, &rows);
+ exp = dom_html_table_section_element_get_rows(
+ (dom_html_table_section_element *)n,
+ &rows);
+ if (exp != DOM_NO_ERR) {
+ return exp;
+ }
exp = dom_html_collection_get_length(rows, &section_len);
dom_html_collection_unref(rows);
+ if (exp != DOM_NO_ERR) {
+ return exp;
+ }
if(window_len + section_len > (uint32_t)index ||
window_len + section_len == len) {
- return dom_html_table_section_element_insert_row(
+ exp = dom_html_table_section_element_insert_row(
(dom_html_table_section_element *)n,
- index-window_len, row);
+ index-window_len,
+ (struct dom_html_element **)&row);
+ if (exp == DOM_NO_ERR) {
+ *row_out = (dom_html_element *)row;
+ }
+ return exp;
}
window_len += section_len;
}
}
exp = dom_html_table_element_get_t_foot(element, &t_foot);
- if(exp != DOM_NO_ERR)
+ if(exp != DOM_NO_ERR) {
return exp;
+ }
exp = dom_html_table_section_element_get_rows(t_foot, &rows);
if(exp != DOM_NO_ERR) {
- dom_html_collection_unref(rows);
+ dom_node_unref(t_foot);
return exp;
}
exp = dom_html_collection_get_length(rows, &section_len);
-
dom_html_collection_unref(rows);
-
- if(exp != DOM_NO_ERR)
+ if(exp != DOM_NO_ERR) {
+ dom_node_unref(t_foot);
return exp;
+ }
if(window_len + section_len > (uint32_t)index ||
window_len +section_len == len) {
- return dom_html_table_section_element_insert_row(t_foot,
- index-window_len, row);
+ exp = dom_html_table_section_element_insert_row(t_foot,
+ index-window_len,
+ (struct dom_html_element **)&row);
+ dom_node_unref(t_foot);
+ if (exp == DOM_NO_ERR) {
+ *row_out = (dom_html_element *)row;
+ }
+ return exp;
}
+ dom_node_unref(t_foot);
exp = DOM_INDEX_SIZE_ERR;
}
- dom_html_collection_unref(rows);
+
return exp;
}
+
/**
* Delete the table Head, if one exists
*