summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2012-11-16 15:29:53 +0000
committerVincent Sanders <vince@netsurf-browser.org>2012-11-16 15:31:14 +0000
commite36b8f657997ffca3d1cc1fe1a7130854d247262 (patch)
tree1694ef785162ac50be10078a8b7c21602da449fd
parentc5fb16d56df03580d99fae44d9fea44868f33cc5 (diff)
downloadnetsurf-e36b8f657997ffca3d1cc1fe1a7130854d247262.tar.gz
netsurf-e36b8f657997ffca3d1cc1fe1a7130854d247262.tar.bz2
safely deal with NULL strings
-rw-r--r--javascript/jsapi/htmldocument.bnd49
-rw-r--r--test/js/dom-node-enumerate.html6
2 files changed, 33 insertions, 22 deletions
diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd
index 80a30bb4e..7ca49489c 100644
--- a/javascript/jsapi/htmldocument.bnd
+++ b/javascript/jsapi/htmldocument.bnd
@@ -181,19 +181,22 @@ 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;
- }
+ if (data != NULL) {
- exc = dom_document_create_text_node(private->node, data_dom, &text);
- dom_string_unref(data_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
+ 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;
+ }
- jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc);
+ exc = dom_document_create_text_node(private->node, data_dom, &text);
+ dom_string_unref(data_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
+
+ jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc);
+ }
JSLOG("returning jsobject %p",jsret);
@@ -205,19 +208,21 @@ operation createElement %{
dom_exception exc;
dom_element *element;
- JSLOG("Creating text node for string \"%s\"", localName);
- exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
+ if (localName != NULL) {
+ JSLOG("Creating text node for string \"%s\"", localName);
+ exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
- exc = dom_document_create_element(private->node, localName_dom, &element);
- dom_string_unref(localName_dom);
- if (exc != DOM_NO_ERR) {
- return JS_FALSE;
- }
+ exc = dom_document_create_element(private->node, localName_dom, &element);
+ dom_string_unref(localName_dom);
+ if (exc != DOM_NO_ERR) {
+ return JS_FALSE;
+ }
- jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
+ jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc);
+ }
JSLOG("returning jsobject %p",jsret);
diff --git a/test/js/dom-node-enumerate.html b/test/js/dom-node-enumerate.html
index 6cbff2438..261d68020 100644
--- a/test/js/dom-node-enumerate.html
+++ b/test/js/dom-node-enumerate.html
@@ -16,6 +16,12 @@ function output(x,y) {
for(var key in Node){
output(key, Node[key]);
}
+
+ document.body.appendChild(document.createElement('hr'));
+
+for(var key in document.body){
+output(key, document.body[key]);
+}
</script>
</body>
</html>