summaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'javascript')
-rw-r--r--javascript/jsapi/dom.bnd74
-rw-r--r--javascript/jsapi/htmldocument.bnd2
-rw-r--r--javascript/jsapi/window.bnd35
3 files changed, 69 insertions, 42 deletions
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index b6f7cf440..3fc7f9ed1 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -16,6 +16,51 @@ preamble %{
#include "htmlelement.h"
%}
+
+prologue %{
+/* CAUTION this expects all javascript Node objects private pointers
+ * to have private->node in the same place.
+ */
+static struct dom_node *jsnode_to_domnode(JSContext *cx, JSObject *jsnode)
+{
+ struct jsclass_private *jsnode_private;
+
+ if (jsnode == NULL) {
+ return NULL;
+ }
+
+ /* element */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_HTMLElement,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ /* text */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_Text,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ /* comment */
+ jsnode_private = JS_GetInstancePrivate(cx,
+ jsnode,
+ &JSClass_Comment,
+ NULL);
+ if (jsnode_private != NULL) {
+ return (struct dom_node *)jsnode_private->node;
+ }
+
+ return NULL;
+}
+
+%}
+
/* interface Node members */
getter nodeType %{
@@ -82,41 +127,24 @@ getter textContent %{
/* interface Node { Node appendChild(Node node); } */
operation appendChild %{
+ struct dom_node *domnode; /* dom node from js input node */
struct dom_node *result = NULL;
dom_exception exc;
-
- struct jsclass_private *node_private;
dom_node_type node_type;
- /* @todo: make this a distinct function jsapiobject_to_domnode() */
- /* CAUTION this expects all Node objects private pointers to
- * have private->node in the same place
- */
- if (node == NULL) {
- node_private = NULL;
- } else {
- /* element */
- node_private = JS_GetInstancePrivate(cx, node, &JSClass_HTMLElement, NULL);
- if (node_private == NULL) {
- /* text */
- node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL);
- if (node_private == NULL) {
- /* comment */
- node_private = JS_GetInstancePrivate(cx, node, &JSClass_Comment, NULL);
- }
- }
- }
- if (node_private == NULL) {
+ domnode = jsnode_to_domnode(cx, node);
+ if (domnode == NULL) {
/* should cause Error: NOT_FOUND_ERR: DOM Exception 8 */
JSLOG("Error: NOT_FOUND_ERR: DOM Exception 8");
return JS_FALSE;
}
- JSLOG("appending %p", node);
+ JSLOG("appending js node %p (dom %p)", node, domnode);
/* append the found element */
- exc = dom_node_append_child(private->node, node_private->node, &result);
+ exc = dom_node_append_child(private->node, domnode, &result);
if (exc != DOM_NO_ERR) {
+ JSLOG("Error: DOM Exception (libdom append child)");
return JS_FALSE;
}
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 021694e17..8d5c69eb5 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -272,7 +272,7 @@ operation createComment %{
}
JSLOG("Creating comment object for dom string \"%s\"",
- dom_string_data(comment));
+ dom_string_data(data_dom));
exc = dom_document_create_comment(private->node,
data_dom,
&comment);
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index 937c150db..bba1eb7db 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -10,6 +10,7 @@
webidlfile "html.idl";
+webidlfile "dom.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
@@ -19,7 +20,7 @@ hdrcomment " http://www.opensource.org/licenses/mit-license";
preamble %{
#include <dom/dom.h>
-
+
#include "utils/config.h"
#include "utils/log.h"
#include "utils/corestrings.h"
@@ -41,8 +42,6 @@ preamble %{
%}
-#include "dom.bnd"
-
binding window {
type js_libdom; /* the binding type */
@@ -109,7 +108,7 @@ api init %{
return NULL;
/* Initialises all the user javascript classes to make their
- * prototypes available.
+ * prototypes available.
*/
/** @todo should we be managing these prototype objects ourselves */
user_proto = jsapi_InitClass_Document(cx, prototype);
@@ -173,16 +172,16 @@ api new %{
/* @todo sort out windows that are not globals */
assert(parent == NULL);
- /* the window object is the global so its prototype *is* the instance */
- newobject = prototype;
+ /* the window object is the global so its prototype *is* the instance */
+ newobject = prototype;
/* instantiate the subclasses off the window global */
private->document = jsapi_new_Document(cx,
- NULL,
- newobject,
- (dom_document *)dom_node_ref(htmlc->document),
- htmlc);
- if (private->document == NULL) {
+ NULL,
+ newobject,
+ (dom_document *)dom_node_ref(htmlc->document),
+ htmlc);
+ if (private->document == NULL) {
free(private);
return NULL;
}
@@ -219,7 +218,7 @@ operation prompt %{
/* boolean dispatchEvent(Event event); */
operation dispatchEvent %{
/* this implementation is unique to the window object as it is
- * not a "real" dom node.
+ * not a "real" dom node.
*/
/* caution, this must match the struct generated from event.bnd */
@@ -249,7 +248,7 @@ operation dispatchEvent %{
jsret = JS_CallFunctionValue(cx, NULL, eventval, 1, event_argv, &event_rval);
}
}
- }
+ }
%}
getter location %{
@@ -268,18 +267,18 @@ getter self %{
getter EventHandler %{
/* this implementation is unique to the window object as it is
- * not a dom node.
+ * not a dom node.
*/
- JSLOG("propname[%d]=\"%s\"",
+ JSLOG("propname[%d]=\"%s\"",
tinyid,
jsclass_properties[tinyid].name);
%}
setter EventHandler %{
/* this implementation is unique to the window object as it is
- * not a dom node.
+ * not a dom node.
*/
- JSLOG("propname[%d]=\"%s\"",
- tinyid,
+ JSLOG("propname[%d]=\"%s\"",
+ tinyid,
jsclass_properties[tinyid].name);
%}