summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javascript/jsapi.h14
-rw-r--r--javascript/jsapi/binding.h5
-rw-r--r--javascript/jsapi/dom.bnd42
-rw-r--r--javascript/jsapi/htmldocument.bnd10
-rw-r--r--javascript/jsapi/text.bnd1
5 files changed, 68 insertions, 4 deletions
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index c8902ad8e..b7e91948e 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -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)
diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h
index 446fb0c51..d58dfe0c9 100644
--- a/javascript/jsapi/binding.h
+++ b/javascript/jsapi/binding.h
@@ -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
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");
+ }
%}
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 272bbd2a9..6205ce01d 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -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);
%}
diff --git a/javascript/jsapi/text.bnd b/javascript/jsapi/text.bnd
index 53e93803d..42791d081 100644
--- a/javascript/jsapi/text.bnd
+++ b/javascript/jsapi/text.bnd
@@ -35,6 +35,7 @@ binding text {
interface Text; /* Web IDL interface to generate */
private "dom_text *" node;
+ private "struct html_content *" htmlc;
}
api finalise %{