add document.createElement

This commit is contained in:
Vincent Sanders 2012-11-09 10:52:32 +00:00
parent e25cb44814
commit 9318e66449
3 changed files with 48 additions and 12 deletions

View File

@ -82,6 +82,8 @@ JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent);
*/ */
JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent); JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent);
extern JSClass JSClass_HTMLElement;
JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent); JSObject *jsapi_InitClass_HTMLElement(JSContext *cx, JSObject *parent);
/** Create a new javascript element object /** Create a new javascript element object
* *

View File

@ -34,13 +34,23 @@ operation appendChild %{
/* CAUTION this expects all Node objects private pointers to /* CAUTION this expects all Node objects private pointers to
* have private->node in the same place * have private->node in the same place
*/ */
/* text */
node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL); node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL);
if (node_private != NULL) { 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); exc = dom_node_append_child(private->node, node_private->node, &result);
if (exc != DOM_NO_ERR) { if (exc != DOM_NO_ERR) {
return JS_FALSE; return JS_FALSE;
} }
}
if (result != NULL) { if (result != NULL) {
exc = dom_node_get_node_type(result, &node_type); exc = dom_node_get_node_type(result, &node_type);

View File

@ -198,3 +198,27 @@ operation createTextNode %{
JSLOG("returning jsobject %p",jsret); 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);
%}