safely deal with NULL strings

This commit is contained in:
Vincent Sanders 2012-11-16 15:29:53 +00:00
parent c5fb16d56d
commit e36b8f6579
2 changed files with 33 additions and 22 deletions

View File

@ -181,19 +181,22 @@ operation createTextNode %{
dom_exception exc; dom_exception exc;
dom_text *text; dom_text *text;
JSLOG("Creating text node for string \"%s\"", data); if (data != NULL) {
exc = dom_string_create((unsigned char*)data, data_len, &data_dom);
if (exc != DOM_NO_ERR) {
return JS_FALSE;
}
exc = dom_document_create_text_node(private->node, data_dom, &text); JSLOG("Creating text node for string \"%s\"", data);
dom_string_unref(data_dom); exc = dom_string_create((unsigned char*)data, data_len, &data_dom);
if (exc != DOM_NO_ERR) { if (exc != DOM_NO_ERR) {
return JS_FALSE; 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); JSLOG("returning jsobject %p",jsret);
@ -205,19 +208,21 @@ operation createElement %{
dom_exception exc; dom_exception exc;
dom_element *element; dom_element *element;
JSLOG("Creating text node for string \"%s\"", localName); if (localName != NULL) {
exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom); JSLOG("Creating text node for string \"%s\"", localName);
if (exc != DOM_NO_ERR) { exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom);
return JS_FALSE; if (exc != DOM_NO_ERR) {
} return JS_FALSE;
}
exc = dom_document_create_element(private->node, localName_dom, &element); exc = dom_document_create_element(private->node, localName_dom, &element);
dom_string_unref(localName_dom); dom_string_unref(localName_dom);
if (exc != DOM_NO_ERR) { if (exc != DOM_NO_ERR) {
return JS_FALSE; 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); JSLOG("returning jsobject %p",jsret);

View File

@ -15,6 +15,12 @@ function output(x,y) {
} }
for(var key in Node){ for(var key in Node){
output(key, Node[key]); output(key, Node[key]);
}
document.body.appendChild(document.createElement('hr'));
for(var key in document.body){
output(key, document.body[key]);
} }
</script> </script>
</body> </body>