diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h index d58dfe0c9..c6a460ccc 100644 --- a/javascript/jsapi/binding.h +++ b/javascript/jsapi/binding.h @@ -82,6 +82,8 @@ JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent); */ JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent); +extern JSClass JSClass_HTMLElement; + JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent); /** Create a new javascript element object * diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd index 5611e8fa7..3a355256f 100644 --- a/javascript/jsapi/dom.bnd +++ b/javascript/jsapi/dom.bnd @@ -6,25 +6,25 @@ webidlfile "dom.idl"; getter textContent %{ - dom_exception exc; - dom_string *content; + dom_exception exc; + dom_string *content; - exc = dom_node_get_text_content(private->node, &content); - if (exc != DOM_NO_ERR) { + exc = dom_node_get_text_content(private->node, &content); + if (exc != DOM_NO_ERR) { return JS_FALSE; } if (content != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content)); + jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content)); dom_string_unref(content); - } + } %} operation appendChild %{ struct dom_node *result = NULL; - dom_exception exc; + dom_exception exc; struct jsclass_private *node_private; dom_node_type node_type; @@ -34,12 +34,22 @@ operation appendChild %{ /* 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) { - exc = dom_node_append_child(private->node, node_private->node, &result); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } + if (node_private == NULL) { + /* element */ + node_private = JS_GetInstancePrivate(cx, node, &JSClass_HTMLElement, NULL); + } + + if (node_private == NULL) { + /* type error? */ + return JS_FALSE; + } + + /* append the found element */ + exc = dom_node_append_child(private->node, node_private->node, &result); + if (exc != DOM_NO_ERR) { + return JS_FALSE; } if (result != NULL) { diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 6205ce01d..cde218450 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -198,3 +198,27 @@ operation createTextNode %{ JSLOG("returning jsobject %p",jsret); %} + +/* in dom Document */ +operation createElement %{ + dom_string *localName_dom; + dom_exception exc; + dom_element *element; + + JSLOG("Creating text node for string \"%s\"", localName); + exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + exc = dom_document_create_element(private->node, localName_dom, &element); + dom_string_unref(localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + + JSLOG("returning jsobject %p",jsret); + +%}