Commit a8b94a03 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Improved error handling in HTMLElement_Create calls.

parent 0835749a
......@@ -996,8 +996,10 @@ static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTa
if(FAILED(hres))
return hres;
elem = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE);
hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem);
nsIDOMHTMLElement_Release(nselem);
if(FAILED(hres))
return hres;
*newElem = HTMLELEM(elem);
IHTMLElement_AddRef(HTMLELEM(elem));
......
......@@ -1666,10 +1666,13 @@ HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **
{
HTMLElement *This = HTMLELEM_NODE_THIS(iface);
HTMLElement *new_elem;
HRESULT hres;
new_elem = HTMLElement_Create(This->node.doc, nsnode, FALSE);
IHTMLElement_AddRef(HTMLELEM(new_elem));
hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
if(FAILED(hres))
return hres;
IHTMLElement_AddRef(HTMLELEM(new_elem));
*ret = &new_elem->node;
return S_OK;
}
......@@ -1718,19 +1721,19 @@ void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElemen
ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
}
HTMLElement *HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic)
HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
{
nsIDOMHTMLElement *nselem;
HTMLElement *ret = NULL;
nsAString class_name_str;
const PRUnichar *class_name;
const tag_desc_t *tag;
HTMLElement *elem;
nsresult nsres;
HRESULT hres;
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
if(NS_FAILED(nsres))
return NULL;
return E_FAIL;
nsAString_Init(&class_name_str, NULL);
nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
......@@ -1739,21 +1742,30 @@ HTMLElement *HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL
tag = get_tag_desc(class_name);
if(tag) {
ret = tag->constructor(doc, nselem);
elem = tag->constructor(doc, nselem);
hres = elem ? S_OK : E_OUTOFMEMORY;
}else if(use_generic) {
ret = HTMLGenericElement_Create(doc, nselem);
hres = HTMLGenericElement_Create(doc, nselem, &elem);
}else {
ret = heap_alloc_zero(sizeof(HTMLElement));
HTMLElement_Init(ret, doc, nselem, &HTMLElement_dispex);
ret->node.vtbl = &HTMLElementImplVtbl;
elem = heap_alloc_zero(sizeof(HTMLElement));
if(elem) {
HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
elem->node.vtbl = &HTMLElementImplVtbl;
hres = S_OK;
}else {
hres = E_OUTOFMEMORY;
}
}
TRACE("%s ret %p\n", debugstr_w(class_name), ret);
TRACE("%s ret %p\n", debugstr_w(class_name), elem);
nsIDOMElement_Release(nselem);
nsAString_Finish(&class_name_str);
if(FAILED(hres))
return hres;
return ret;
*ret = elem;
return S_OK;
}
/* interface IHTMLFiltersCollection */
......
......@@ -166,16 +166,19 @@ static dispex_static_data_t HTMLGenericElement_dispex = {
HTMLGenericElement_iface_tids
};
HTMLElement *HTMLGenericElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
HRESULT HTMLGenericElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
{
HTMLGenericElement *ret;
ret = heap_alloc_zero(sizeof(HTMLGenericElement));
if(!ret)
return E_OUTOFMEMORY;
ret->lpHTMLGenericElementVtbl = &HTMLGenericElementVtbl;
ret->element.node.vtbl = &HTMLGenericElementImplVtbl;
HTMLElement_Init(&ret->element, doc, nselem, &HTMLGenericElement_dispex);
return &ret->element;
*elem = &ret->element;
return S_OK;
}
......@@ -820,10 +820,11 @@ static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *i
if(FAILED(hres))
return hres;
elem = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE);
if(!elem) {
hres = HTMLElement_Create(This->window->doc, (nsIDOMNode*)nselem, FALSE, &elem);
nsIDOMHTMLElement_Release(nselem);
if(FAILED(hres)) {
ERR("HTMLElement_Create failed\n");
return E_FAIL;
return hres;
}
hres = IHTMLElement_QueryInterface(HTMLELEM(elem), &IID_IHTMLImgElement, (void**)&img);
......@@ -832,8 +833,6 @@ static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *i
return hres;
}
nsIDOMHTMLElement_Release(nselem);
l = var_to_size(&width);
if(l)
IHTMLImgElement_put_width(img, l);
......
......@@ -1001,9 +1001,14 @@ static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNod
nsIDOMNode_GetNodeType(nsnode, &node_type);
switch(node_type) {
case ELEMENT_NODE:
*ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
case ELEMENT_NODE: {
HTMLElement *elem;
hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
if(FAILED(hres))
return hres;
*ret = &elem->node;
break;
}
case TEXT_NODE:
hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
if(FAILED(hres))
......
......@@ -820,7 +820,7 @@ HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**);
HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**);
HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
......@@ -838,7 +838,7 @@ HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HRESULT HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment