summaryrefslogtreecommitdiff
path: root/javascript/jsapi/dom.bnd
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-11-08 17:22:29 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-11-08 17:22:29 +0000
commit28ac5fe9c1991c57d0a72d22377340b01ab6564b (patch)
tree7d395d9913739cb775a55f70dd69a3a04e578e51 /javascript/jsapi/dom.bnd
parent9006a96119854e6975a66025bfaf9bf63767fec7 (diff)
downloadnetsurf-28ac5fe9c1991c57d0a72d22377340b01ab6564b.tar.gz
netsurf-28ac5fe9c1991c57d0a72d22377340b01ab6564b.tar.bz2
implement appendChild so wikipedia lcm script works
Diffstat (limited to 'javascript/jsapi/dom.bnd')
-rw-r--r--javascript/jsapi/dom.bnd42
1 files changed, 40 insertions, 2 deletions
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index bf3b44ea3..50dc6af1c 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -22,7 +22,45 @@ getter textContent %{
%}
-
operation appendChild %{
-/* void * JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv); */
+ struct dom_node *result = NULL;
+ dom_exception exc;
+
+ struct jsclass_private *node_private;
+ dom_node_type node_type;
+
+ JSLOG("appending %p", node);
+
+ /* CAUTION this expects all Node objects private pointers to
+ * have private->node in the same place
+ */
+ node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL);
+ if (node_private != NULL) {
+ exc = dom_node_append_child(private->node, node_private->node, &result);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+ }
+
+ if (result != NULL) {
+ exc = dom_node_get_node_type(result, &node_type);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+ switch (node_type) {
+ case DOM_ELEMENT_NODE:
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, result, private->htmlc);
+ break;
+
+ case DOM_TEXT_NODE:
+ jsret = jsapi_new_Text(cx, NULL, NULL, result, private->htmlc);
+ break;
+
+ default:
+ JSLOG("Unsupported result node type %d", node_type);
+ }
+
+ } else {
+ JSLOG("No result");
+ }
%}