diff options
author | Vincent Sanders <vince@kyllikki.org> | 2013-01-02 17:19:32 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2013-01-02 23:14:30 +0000 |
commit | 1b8f9daa51c901119d4dc27f82fb993fc8378bd0 (patch) | |
tree | a96ae02f5f17bf1fe1a134fb372c59859bed9598 /javascript/jsapi/dom.bnd | |
parent | 3f33f5327e783b3f4d7474007672c2c60a2969ea (diff) | |
download | netsurf-1b8f9daa51c901119d4dc27f82fb993fc8378bd0.tar.gz netsurf-1b8f9daa51c901119d4dc27f82fb993fc8378bd0.tar.bz2 |
Initial implementation of document.createComment
Improve robustness of jsobject to libdom object conversion in appendChild
Diffstat (limited to 'javascript/jsapi/dom.bnd')
-rw-r--r-- | javascript/jsapi/dom.bnd | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd index e781b330c..b6f7cf440 100644 --- a/javascript/jsapi/dom.bnd +++ b/javascript/jsapi/dom.bnd @@ -10,6 +10,12 @@ webidlfile "dom.idl"; +preamble %{ +#include "comment.h" +#include "text.h" +#include "htmlelement.h" +%} + /* interface Node members */ getter nodeType %{ @@ -74,7 +80,7 @@ getter textContent %{ } %} - +/* interface Node { Node appendChild(Node node); } */ operation appendChild %{ struct dom_node *result = NULL; dom_exception exc; @@ -82,23 +88,32 @@ operation appendChild %{ struct jsclass_private *node_private; dom_node_type node_type; - JSLOG("appending %p", node); - + /* @todo: make this a distinct function jsapiobject_to_domnode() */ /* CAUTION this expects all Node objects private pointers to * have private->node in the same place */ - /* text */ - node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL); - if (node_private == NULL) { + if (node == NULL) { + node_private = NULL; + } else { /* element */ node_private = JS_GetInstancePrivate(cx, node, &JSClass_HTMLElement, NULL); + if (node_private == NULL) { + /* text */ + node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL); + if (node_private == NULL) { + /* comment */ + node_private = JS_GetInstancePrivate(cx, node, &JSClass_Comment, NULL); + } + } } - if (node_private == NULL) { - /* type error? */ + /* should cause Error: NOT_FOUND_ERR: DOM Exception 8 */ + JSLOG("Error: NOT_FOUND_ERR: DOM Exception 8"); return JS_FALSE; } + JSLOG("appending %p", node); + /* append the found element */ exc = dom_node_append_child(private->node, node_private->node, &result); if (exc != DOM_NO_ERR) { |