summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-11-04 11:18:37 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-11-04 11:20:02 +0000
commit8de9e1907759de5de7ded43573417b2f2e471c04 (patch)
tree6666110bfe84e3d34a2c33e2d9159d8bb806acbd
parentf5a98defaec97cf7a18516c8c9af49f10b93f0cf (diff)
downloadnetsurf-8de9e1907759de5de7ded43573417b2f2e471c04.tar.gz
netsurf-8de9e1907759de5de7ded43573417b2f2e471c04.tar.bz2
improve dom reference accounting
-rw-r--r--javascript/jsapi/dom.bnd15
-rw-r--r--javascript/jsapi/htmlcollection.bnd8
-rw-r--r--javascript/jsapi/htmldocument.bnd6
-rw-r--r--javascript/jsapi/htmlelement.bnd16
-rw-r--r--javascript/jsapi/nodelist.bnd6
-rw-r--r--javascript/jsapi/window.bnd2
6 files changed, 34 insertions, 19 deletions
diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd
index 14068ba2e..fdf1f253a 100644
--- a/javascript/jsapi/dom.bnd
+++ b/javascript/jsapi/dom.bnd
@@ -13,6 +13,7 @@ operation getElementById %{
}
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;
}
@@ -37,16 +38,14 @@ operation getElementsByTagName %{
return JS_FALSE;
}
- LOG(("here"));
-
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;
}
- LOG(("nodelist %p", nodelist));
if (/*collection*/nodelist != NULL) {
- /* jsret = jsapi_new_HTMLCollection(cx,
+ /*jsret = jsapi_new_HTMLCollection(cx,
NULL,
NULL,
collection,
@@ -65,8 +64,14 @@ getter textContent %{
dom_string *content;
exc = dom_node_get_text_content(private->node, &content);
- if ((exc == DOM_NO_ERR) && (content != NULL)) {
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ if (content != NULL) {
jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content));
+ dom_string_unref(content);
+
}
%}
diff --git a/javascript/jsapi/htmlcollection.bnd b/javascript/jsapi/htmlcollection.bnd
index a7947cd29..f4a11549b 100644
--- a/javascript/jsapi/htmlcollection.bnd
+++ b/javascript/jsapi/htmlcollection.bnd
@@ -82,4 +82,10 @@ operation namedItem %{
jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc);
}
- %}
+%}
+
+api finalise %{
+ if (private != NULL) {
+ dom_html_collection_unref(private->collection);
+ }
+%}
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index c90114162..4cc4971fb 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -38,3 +38,9 @@ binding document {
interface Document; /* Web IDL interface to generate */
}
+
+api finalise %{
+ if (private != NULL) {
+ dom_node_unref(private->node);
+ }
+%}
diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd
index 596bb7de0..83941c1b7 100644
--- a/javascript/jsapi/htmlelement.bnd
+++ b/javascript/jsapi/htmlelement.bnd
@@ -34,18 +34,12 @@ binding htmlelement {
interface HTMLElement; /* Web IDL interface to generate */
- /* private members:
- * - stored in private context structure.
- * - passed as parameters to constructor and stored automatically.
- * - are *not* considered for property getters/setters.
- *
- * internal members:
- * - value stored in private context structure
- * - not passed to constructor
- * - must be instantiated by constructor
- * - are considered for property getters/setters.
- */
private "dom_element *" node;
private "struct html_content *" htmlc;
}
+api finalise %{
+ if (private != NULL) {
+ dom_node_unref(private->node);
+ }
+%} \ No newline at end of file
diff --git a/javascript/jsapi/nodelist.bnd b/javascript/jsapi/nodelist.bnd
index 710536dcf..d6e9fe941 100644
--- a/javascript/jsapi/nodelist.bnd
+++ b/javascript/jsapi/nodelist.bnd
@@ -63,5 +63,9 @@ operation item %{
}
%}
-
+api finalise %{
+ if (private != NULL) {
+ dom_nodelist_unref(private->nodelist);
+ }
+%}
diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd
index 6f5e1af47..bf3f1700d 100644
--- a/javascript/jsapi/window.bnd
+++ b/javascript/jsapi/window.bnd
@@ -126,7 +126,7 @@ api new %{
private->document = jsapi_new_Document(cx,
NULL,
newobject,
- htmlc->document,
+ (dom_document *)dom_node_ref(htmlc->document),
htmlc);
if (private->document == NULL) {
free(private);