implement appendChild so wikipedia lcm script works

This commit is contained in:
Vincent Sanders 2012-11-08 17:22:29 +00:00
parent 9006a96119
commit 28ac5fe9c1
5 changed files with 68 additions and 4 deletions

View File

@ -62,6 +62,9 @@
/* arguments */
#define JSAPI_ARGV(cx, vp) (vp)
/* check if a jsval is an object */
#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v)
/* The object instance in a native call */
/* "this" JSObject getter */
JSObject * js_ComputeThis(JSContext *cx, JSObject *thisp, void *argv);
@ -150,6 +153,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
/* arguments */
#define JSAPI_ARGV(cx, vp) (vp)
/* check if a jsval is an object */
#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v)
/* The object instance in a native call */
#define JSAPI_THIS_OBJECT(cx,vp) jsapi_this
@ -233,6 +239,14 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
/* arguments */
#define JSAPI_ARGV(cx, vp) JS_ARGV(cx,vp)
/* check if a jsval is an object */
#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v)
/* The docuemntation says this is obsolete and should be
* ((JSVAL_IS_NULL(v)) || (JSVAL_IS_PRIMITIVE(v)))
* which doesnt work
*/
/* The object instance in a native call */
#define JSAPI_THIS_OBJECT(cx,vp) JS_THIS_OBJECT(cx,vp)

View File

@ -125,6 +125,8 @@ JSObject *jsapi_new_NodeList(JSContext *cx,
struct html_content *htmlc);
extern JSClass JSClass_Text;
JSObject *jsapi_InitClass_Text(JSContext *cx, JSObject *parent);
/** Create a new javascript text object
*
@ -136,6 +138,7 @@ JSObject *jsapi_InitClass_Text(JSContext *cx, JSObject *parent);
JSObject *jsapi_new_Text(JSContext *cx,
JSObject *prototype,
JSObject *parent,
dom_text *node);
dom_text *node,
struct html_content *htmlc);
#endif

View File

@ -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");
}
%}

View File

@ -91,6 +91,8 @@ getter body %{
dom_node *body;
dom_exception exc;
JSLOG("Getting your body");
/* document (html) element */
exc = dom_document_get_document_element(private->node, &element);
if (exc != DOM_NO_ERR) {
@ -104,6 +106,9 @@ getter body %{
}
dom_node_unref(element);
}
JSLOG("returning jsobject %p",jsret);
%}
operation getElementById %{
@ -176,6 +181,7 @@ operation createTextNode %{
dom_exception exc;
dom_text *text;
JSLOG("Creating text node for string \"%s\"", data);
exc = dom_string_create((unsigned char*)data, data_len, &data_dom);
if (exc != DOM_NO_ERR) {
return JS_FALSE;
@ -187,6 +193,8 @@ operation createTextNode %{
return JS_FALSE;
}
jsret = jsapi_new_Text(cx, NULL, NULL, text);
jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc);
JSLOG("returning jsobject %p",jsret);
%}

View File

@ -35,6 +35,7 @@ binding text {
interface Text; /* Web IDL interface to generate */
private "dom_text *" node;
private "struct html_content *" htmlc;
}
api finalise %{