summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2013-01-02 17:19:32 +0000
committerVincent Sanders <vince@kyllikki.org>2013-01-02 23:14:30 +0000
commit1b8f9daa51c901119d4dc27f82fb993fc8378bd0 (patch)
treea96ae02f5f17bf1fe1a134fb372c59859bed9598
parent3f33f5327e783b3f4d7474007672c2c60a2969ea (diff)
downloadnetsurf-1b8f9daa51c901119d4dc27f82fb993fc8378bd0.tar.gz
netsurf-1b8f9daa51c901119d4dc27f82fb993fc8378bd0.tar.bz2
Initial implementation of document.createComment
Improve robustness of jsobject to libdom object conversion in appendChild
-rw-r--r--Makefile.sources.javascript1
-rw-r--r--javascript/jsapi/comment.bnd47
-rw-r--r--javascript/jsapi/dom.bnd31
-rw-r--r--javascript/jsapi/htmldocument.bnd143
-rw-r--r--javascript/jsapi/htmlelement.bnd4
-rw-r--r--javascript/jsapi/navigator.bnd1
-rw-r--r--javascript/jsapi/text.bnd4
-rw-r--r--javascript/jsapi/window.bnd9
8 files changed, 171 insertions, 69 deletions
diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript
index 4633e9d0d..bcdd68501 100644
--- a/Makefile.sources.javascript
+++ b/Makefile.sources.javascript
@@ -20,6 +20,7 @@ JSAPI_BINDING_location := javascript/jsapi/location.bnd
JSAPI_BINDING_htmlcollection := javascript/jsapi/htmlcollection.bnd
JSAPI_BINDING_nodelist := javascript/jsapi/nodelist.bnd
JSAPI_BINDING_text := javascript/jsapi/text.bnd
+JSAPI_BINDING_comment := javascript/jsapi/comment.bnd
JSAPI_BINDING_node := javascript/jsapi/node.bnd
JSAPI_BINDING_event := javascript/jsapi/event.bnd
diff --git a/javascript/jsapi/comment.bnd b/javascript/jsapi/comment.bnd
new file mode 100644
index 000000000..580f5cbed
--- /dev/null
+++ b/javascript/jsapi/comment.bnd
@@ -0,0 +1,47 @@
+/* Binding to generate Comment interface
+ *
+ * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+
+webidlfile "html.idl";
+
+hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
+hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
+hdrcomment "Released under the terms of the MIT License,";
+hdrcomment " http://www.opensource.org/licenses/mit-license";
+
+preamble %{
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+#include "render/html_internal.h"
+#include "javascript/jsapi.h"
+
+#include "comment.h"
+
+%}
+
+#include "dom.bnd"
+
+binding comment {
+ type js_libdom; /* the binding type */
+
+ interface Comment; /* Web IDL interface to generate */
+
+ private "dom_comment *" node;
+ private "struct html_content *" htmlc;
+}
+
+api finalise %{
+ if (private != NULL) {
+ dom_node_unref(private->node);
+ }
+%}
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index e781b330c..b6f7cf440 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -10,6 +10,12 @@
webidlfile "dom.idl";
+preamble %{
+#include "comment.h"
+#include "text.h"
+#include "htmlelement.h"
+%}
+
/* interface Node members */
getter nodeType %{
@@ -74,7 +80,7 @@ getter textContent %{
}
%}
-
+/* interface Node { Node appendChild(Node node); } */
operation appendChild %{
struct dom_node *result = NULL;
dom_exception exc;
@@ -82,23 +88,32 @@ operation appendChild %{
struct jsclass_private *node_private;
dom_node_type node_type;
- JSLOG("appending %p", node);
-
+ /* @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
*/
- /* text */
- node_private = JS_GetInstancePrivate(cx, node, &JSClass_Text, NULL);
- if (node_private == NULL) {
+ 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) {
- /* type error? */
+ /* should cause Error: NOT_FOUND_ERR: DOM Exception 8 */
+ JSLOG("Error: NOT_FOUND_ERR: DOM Exception 8");
return JS_FALSE;
}
+ JSLOG("appending %p", node);
+
/* append the found element */
exc = dom_node_append_child(private->node, node_private->node, &result);
if (exc != DOM_NO_ERR) {
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index ddf408a9f..021694e17 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -8,8 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
-
webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
@@ -20,7 +18,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"
@@ -38,6 +36,8 @@ preamble %{
%}
+#include "dom.bnd"
+
binding document {
type js_libdom; /* the binding type */
@@ -47,10 +47,10 @@ binding document {
* context structure.
*/
private "dom_document *" node;
- private "struct html_content *" htmlc;
+ private "struct html_content *" htmlc;
/** location instantiated on first use */
- property unshared location;
+ property unshared location;
/* events through a single interface */
property unshared type EventHandler;
@@ -70,9 +70,9 @@ getter location %{
/* already created - return it */
return JS_TRUE;
}
- jsret = jsapi_new_Location(cx,
- NULL,
- NULL,
+ jsret = jsapi_new_Location(cx,
+ NULL,
+ NULL,
llcache_handle_get_url(private->htmlc->base.llcache),
private->htmlc);
%}
@@ -110,7 +110,7 @@ getter documentElement %{
/* document (html) element */
exc = dom_document_get_document_element(private->node, (void *)&element);
- if (exc != DOM_NO_ERR) {
+ if (exc != DOM_NO_ERR) {
return JS_FALSE;
}
@@ -122,11 +122,11 @@ getter documentElement %{
getter head %{
dom_node *element;
dom_node *head;
- dom_exception exc;
+ dom_exception exc;
/* document (html) element */
exc = dom_document_get_document_element(private->node, &element);
- if (exc != DOM_NO_ERR) {
+ if (exc != DOM_NO_ERR) {
return JS_FALSE;
}
@@ -142,13 +142,13 @@ getter head %{
getter body %{
dom_node *element;
dom_node *body;
- dom_exception exc;
+ dom_exception exc;
JSLOG("Getting your body");
/* document (html) element */
exc = dom_document_get_document_element(private->node, &element);
- if (exc != DOM_NO_ERR) {
+ if (exc != DOM_NO_ERR) {
return JS_FALSE;
}
@@ -167,58 +167,58 @@ getter body %{
operation getElementById %{
dom_string *elementId_dom;
dom_element *element;
- dom_exception exc;
+ dom_exception exc;
exc = dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
exc = dom_document_get_element_by_id(private->node, elementId_dom, &element);
- dom_string_unref(elementId_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
-
- if (element != NULL) {
- jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
- }
+ dom_string_unref(elementId_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (element != NULL) {
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
+ }
%}
-/*
+/*
*
* Dom 4 says this should return a htmlcollection, libdom currently
- * returns DOM 3 spec of a nodelist
+ * returns DOM 3 spec of a nodelist
*/
operation getElementsByTagName %{
dom_string *localName_dom;
- /* dom_html_collection *collection;*/
- dom_nodelist *nodelist;
- dom_exception exc;
+ /* dom_html_collection *collection;*/
+ dom_nodelist *nodelist;
+ dom_exception exc;
exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
-
- exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist);
- dom_string_unref(localName_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
-
- if (/*collection*/nodelist != NULL) {
- /*jsret = jsapi_new_HTMLCollection(cx,
- NULL,
- NULL,
- collection,
- private->htmlc);*/
- jsret = jsapi_new_NodeList(cx,
- NULL,
- NULL,
- nodelist,
- private->htmlc);
- }
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist);
+ dom_string_unref(localName_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (/*collection*/nodelist != NULL) {
+ /*jsret = jsapi_new_HTMLCollection(cx,
+ NULL,
+ NULL,
+ collection,
+ private->htmlc);*/
+ jsret = jsapi_new_NodeList(cx,
+ NULL,
+ NULL,
+ nodelist,
+ private->htmlc);
+ }
%}
@@ -228,10 +228,10 @@ operation write %{
}
%}
-/* in dom Document */
+/* interface Document (dom) { Text createTextNode(DOMString data); } */
operation createTextNode %{
dom_string *data_dom;
- dom_exception exc;
+ dom_exception exc;
dom_text *text;
if (data != NULL) {
@@ -255,10 +255,43 @@ operation createTextNode %{
%}
+/* interface Document (dom) { Comment createComment(DOMString data); } */
+operation createComment %{
+ dom_string *data_dom;
+ dom_exception exc;
+ dom_comment *comment;
+
+ if (data != NULL) {
+
+ JSLOG("Creating string \"%s\"", data);
+ exc = dom_string_create((unsigned char*)data,
+ data_len,
+ &data_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ JSLOG("Creating comment object for dom string \"%s\"",
+ dom_string_data(comment));
+ exc = dom_document_create_comment(private->node,
+ data_dom,
+ &comment);
+ dom_string_unref(data_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ jsret = jsapi_new_Comment(cx, NULL, NULL, comment, private->htmlc);
+ }
+
+ JSLOG("returning jsobject %p", jsret);
+
+%}
+
/* in dom Document */
operation createElement %{
dom_string *localName_dom;
- dom_exception exc;
+ dom_exception exc;
dom_element *element;
if (localName != NULL) {
diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd
index 48ebbdb64..5e22f7e7d 100644
--- a/javascript/jsapi/htmlelement.bnd
+++ b/javascript/jsapi/htmlelement.bnd
@@ -8,8 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
-
webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
@@ -34,6 +32,8 @@ preamble %{
%}
+#include "dom.bnd"
+
binding htmlelement {
type js_libdom; /* the binding type */
diff --git a/javascript/jsapi/navigator.bnd b/javascript/jsapi/navigator.bnd
index d040edec2..2fb0c2d0a 100644
--- a/javascript/jsapi/navigator.bnd
+++ b/javascript/jsapi/navigator.bnd
@@ -8,7 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
webidlfile "html.idl";
diff --git a/javascript/jsapi/text.bnd b/javascript/jsapi/text.bnd
index 6b4352116..eb17a943e 100644
--- a/javascript/jsapi/text.bnd
+++ b/javascript/jsapi/text.bnd
@@ -8,7 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
webidlfile "html.idl";
@@ -27,10 +26,11 @@ preamble %{
#include "javascript/jsapi.h"
#include "text.h"
-#include "htmlelement.h"
%}
+#include "dom.bnd"
+
binding text {
type js_libdom; /* the binding type */
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index 288b5b3d8..937c150db 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -8,7 +8,6 @@
* http://www.opensource.org/licenses/mit-license
*/
-#include "dom.bnd"
webidlfile "html.idl";
@@ -35,12 +34,15 @@ preamble %{
#include "nodelist.h"
#include "htmldocument.h"
#include "text.h"
+#include "comment.h"
#include "htmlelement.h"
#include "window.h"
#include "location.h"
%}
+#include "dom.bnd"
+
binding window {
type js_libdom; /* the binding type */
@@ -150,6 +152,11 @@ api init %{
return NULL;
}
+ user_proto = jsapi_InitClass_Comment(cx, prototype);
+ if (user_proto == NULL) {
+ return NULL;
+ }
+
user_proto = jsapi_InitClass_Node(cx, prototype);
if (user_proto == NULL) {
return NULL;