diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd index 3b533ebef..898f78188 100644 --- a/javascript/jsapi/htmlelement.bnd +++ b/javascript/jsapi/htmlelement.bnd @@ -89,6 +89,37 @@ getter firstElementChild %{ %} getter lastElementChild %{ + dom_node *element; + dom_exception exc; + dom_node_type node_type; + dom_node *sib_node; + + exc = dom_node_get_last_child(private->node, &element); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + while (element != NULL) { + exc = dom_node_get_node_type(element, &node_type); + if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { + /* found it */ + jsret = jsapi_new_HTMLElement(cx, + NULL, + NULL, + (dom_element *)element, + private->htmlc); + break; + } + + exc = dom_node_get_previous_sibling(element, &sib_node); + dom_node_unref(element); + if (exc == DOM_NO_ERR) { + element = sib_node; + } else { + element = NULL; + } + + } %} getter previousElementSibling %{ diff --git a/test/js/doc-dom1.html b/test/js/dom-element-firstElementChild.html similarity index 100% rename from test/js/doc-dom1.html rename to test/js/dom-element-firstElementChild.html diff --git a/test/js/dom-element-lastElementChild.html b/test/js/dom-element-lastElementChild.html new file mode 100644 index 000000000..e4e9f11cb --- /dev/null +++ b/test/js/dom-element-lastElementChild.html @@ -0,0 +1,11 @@ + + + +DOM lastElementChild reference + + +

DOM lastElementChild reference

+

head.lastElementChild:

+

body.lastElementChild:

+ + diff --git a/test/js/index.html b/test/js/index.html index f02c4df32..70e4088cf 100644 --- a/test/js/index.html +++ b/test/js/index.html @@ -24,7 +24,8 @@

DOM tests

Reference method tests