summaryrefslogtreecommitdiff
path: root/javascript/jsapi/dom.bnd
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2013-01-02 22:43:29 +0000
committerVincent Sanders <vince@kyllikki.org>2013-01-02 23:14:31 +0000
commitbb10e7131f615b9266d7a1996f561637286e2839 (patch)
tree734ba083b57047fd047fe20074db4de5d0f27b73 /javascript/jsapi/dom.bnd
parent1b8f9daa51c901119d4dc27f82fb993fc8378bd0 (diff)
downloadnetsurf-bb10e7131f615b9266d7a1996f561637286e2839.tar.gz
netsurf-bb10e7131f615b9266d7a1996f561637286e2839.tar.bz2
use a prologue section in the node binding to abstract out javascrip dom node to libdom node conversion
Diffstat (limited to 'javascript/jsapi/dom.bnd')
-rw-r--r--javascript/jsapi/dom.bnd74
1 files changed, 51 insertions, 23 deletions
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index b6f7cf440..3fc7f9ed1 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -16,6 +16,51 @@ preamble %{
#include "htmlelement.h"
%}
+
+prologue %{
+/* CAUTION this expects all javascript Node objects private pointers
+ * to have private->node in the same place.
+ */
+static struct dom_node *jsnode_to_domnode(JSContext *cx, JSObject *jsnode)
+{
+ struct jsclass_private *jsnode_private;
+
+ if (jsnode == NULL) {
+ return NULL;
+ }
+
+ /* element */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_HTMLElement,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ /* text */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_Text,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ /* comment */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_Comment,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ return NULL;
+}
+
+%}
+
/* interface Node members */
getter nodeType %{
@@ -82,41 +127,24 @@ getter textContent %{
/* interface Node { Node appendChild(Node node); } */
operation appendChild %{
+ struct dom_node *domnode; /* dom node from js input node */
struct dom_node *result = NULL;
dom_exception exc;
-
- struct jsclass_private *node_private;
dom_node_type node_type;
- /* @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
- */
- 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) {
+ domnode = jsnode_to_domnode(cx, node);
+ if (domnode == NULL) {
/* should cause Error: NOT_FOUND_ERR: DOM Exception 8 */
JSLOG("Error: NOT_FOUND_ERR: DOM Exception 8");
return JS_FALSE;
}
- JSLOG("appending %p", node);
+ JSLOG("appending js node %p (dom %p)", node, domnode);
/* append the found element */
- exc = dom_node_append_child(private->node, node_private->node, &result);
+ exc = dom_node_append_child(private->node, domnode, &result);
if (exc != DOM_NO_ERR) {
+ JSLOG("Error: DOM Exception (libdom append child)");
return JS_FALSE;
}