diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-10-21 18:55:39 +0200 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-10-21 18:55:39 +0200 |
commit | c752c85618a57f8c82dc2e939ba2bf735e6c8372 (patch) | |
tree | c4040c3838a22169043927577f0ae8cd3793708f | |
parent | 2f52338328e694e3ba1141424cbf3f413bcfbaf9 (diff) | |
download | netsurf-c752c85618a57f8c82dc2e939ba2bf735e6c8372.tar.gz netsurf-c752c85618a57f8c82dc2e939ba2bf735e6c8372.tar.bz2 |
Correct some incorrect error case handling and add tests to demonstrate fix
-rw-r--r-- | javascript/duktape/Node.bnd | 14 | ||||
-rw-r--r-- | test/js/dom-node-parentNode.html | 23 | ||||
-rw-r--r-- | test/js/index.html | 1 |
3 files changed, 31 insertions, 7 deletions
diff --git a/javascript/duktape/Node.bnd b/javascript/duktape/Node.bnd index 0b1bfe390..a610afaf7 100644 --- a/javascript/duktape/Node.bnd +++ b/javascript/duktape/Node.bnd @@ -73,7 +73,6 @@ getter Node::parentNode() dom_node *pnode = NULL; exc = dom_node_get_parent_node(priv->node, &pnode); if (exc != DOM_NO_ERR) return 0; - if (pnode == NULL) return 0; dukky_push_node(ctx, pnode); dom_node_unref(pnode); return 1; @@ -83,15 +82,16 @@ getter Node::parentElement() %{ dom_exception exc; dom_node *pnode = NULL; - dom_node_type ntype; + dom_node_type ntype = DOM_NODE_TYPE_COUNT + 1; exc = dom_node_get_parent_node(priv->node, &pnode); if (exc != DOM_NO_ERR) return 0; - if (pnode == NULL) return 0; - exc = dom_node_get_node_type(pnode, &ntype); - if (exc != DOM_NO_ERR) { dom_node_unref(pnode); return 0; } - dukky_push_node(ctx, pnode); + if (pnode != NULL) { + exc = dom_node_get_node_type(pnode, &ntype); + if (exc != DOM_NO_ERR) { dom_node_unref(pnode); return 0; } + } + dukky_push_node(ctx, (ntype == DOM_ELEMENT_NODE) ? pnode : NULL); dom_node_unref(pnode); - return (ntype == DOM_ELEMENT_NODE) ? 1 : 0; + return 1; %} method Node::hasChildNodes() diff --git a/test/js/dom-node-parentNode.html b/test/js/dom-node-parentNode.html new file mode 100644 index 000000000..927a3701b --- /dev/null +++ b/test/js/dom-node-parentNode.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html> +<head><title>DOM Node::nodeType</title></head> +<body> +<h1>Node::ParentNode</h1> +<h2>These should all resolve to nodes of some kind.</h2> +<script> +document.write("<p>document is: ", + document, "</p>"); +document.write("<p>document.body is: ", + document.body, "</p>"); +document.write("<p>document.body.parentNode: ", + document.body.parentNode, "</p>"); +</script> +<h2>These should all resolve to null.</h2> +<script> +document.write("<p>document.parentNode is: ", + document.parentNode, "</p>"); +document.write("<p>document.createElement('foo').parentNode is: ", + document.createElement('foo').parentNode, "</p>"); +</script> +</body> +</html> diff --git a/test/js/index.html b/test/js/index.html index 8602a8159..c12f32360 100644 --- a/test/js/index.html +++ b/test/js/index.html @@ -66,6 +66,7 @@ <h3>DOM node tests</h3> <ul> <li><a href="dom-node-nodetype.html">Node::nodeType support</a></li> +<li><a href="dom-node-parentNode.html">Node::parentNode support</a></li> </ul> <h3>Document element specific</h3> |