summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2015-08-02 15:22:46 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2015-08-03 21:30:20 (GMT)
commitf771b7e090d1d289c7c60885a8639b58f2e7ad66 (patch)
treec628cb0fa64b5035fda358604733411ffe3088c8
parent17b7bca264ccbe32a921d7286186dd303cecfcba (diff)
downloadlibnslayout-f771b7e090d1d289c7c60885a8639b58f2e7ad66.tar.gz
libnslayout-f771b7e090d1d289c7c60885a8639b58f2e7ad66.tar.bz2
Error handling.
-rw-r--r--src/dom/event.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/dom/event.c b/src/dom/event.c
index 6217e7a..cc5596d 100644
--- a/src/dom/event.c
+++ b/src/dom/event.c
@@ -99,6 +99,7 @@ fail:
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
{
+ nslayout_error err;
dom_exception exc;
/* TODO: LibDOM even listeners are really slow. Need to find a better
@@ -108,52 +109,56 @@ nslayout_error nsl_dom_event_layout_init(nslayout_layout *layout)
exc = dom_event_listener_create(layout->doc, nsl__dom_event_handler,
layout, &layout->listener);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ return NSL_DOM_ERR(exc);
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
exc = dom_event_target_add_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to register event handler!\n");
- return NSLAYOUT_NO_MEM;
+ (void) dom_event_target_remove_event_listener(
+ layout->doc, nsl_dom_str_node_inserted,
+ layout->listener, false);
+ err = NSL_DOM_ERR(exc);
+ goto fail;
}
return NSLAYOUT_OK;
+
+fail:
+ dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
+
+ return err;
}
/* Exported function, documented in src/dom/event.h */
nslayout_error nsl_dom_event_layout_fini(nslayout_layout *layout)
{
- dom_exception exc;
+ dom_exception exc1, exc2;
- exc = dom_event_target_remove_event_listener(
+ exc1 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_node_inserted,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
- }
- exc = dom_event_target_remove_event_listener(
+ exc2 = dom_event_target_remove_event_listener(
layout->doc, nsl_dom_str_subtree_modified,
layout->listener, false);
- if (exc != DOM_NO_ERR) {
- /* TODO: free stuff, return value */
- printf("Failed to remove event handler!\n");
- return NSLAYOUT_NO_MEM;
+
+ if (exc1 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc1);
+ }
+ if (exc2 != DOM_NO_ERR) {
+ return NSL_DOM_ERR(exc2);
}
+
dom_event_listener_unref(layout->listener);
+ layout->listener = NULL;
return NSLAYOUT_OK;
}