Commit 6bf247f9 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Better error handling in create_node calls.

parent 8fb6b02d
...@@ -185,9 +185,13 @@ static dispex_static_data_t HTMLCommentElement_dispex = { ...@@ -185,9 +185,13 @@ static dispex_static_data_t HTMLCommentElement_dispex = {
HTMLCommentElement_iface_tids HTMLCommentElement_iface_tids
}; };
HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode) HRESULT HTMLCommentElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLElement **elem)
{ {
HTMLCommentElement *ret = heap_alloc_zero(sizeof(*ret)); HTMLCommentElement *ret;
ret = heap_alloc_zero(sizeof(*ret));
if(!ret)
return E_OUTOFMEMORY;
ret->element.node.vtbl = &HTMLCommentElementImplVtbl; ret->element.node.vtbl = &HTMLCommentElementImplVtbl;
ret->lpIHTMLCommentElementVtbl = &HTMLCommentElementVtbl; ret->lpIHTMLCommentElementVtbl = &HTMLCommentElementVtbl;
...@@ -197,5 +201,6 @@ HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode ...@@ -197,5 +201,6 @@ HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode
nsIDOMNode_AddRef(nsnode); nsIDOMNode_AddRef(nsnode);
ret->element.node.nsnode = nsnode; ret->element.node.nsnode = nsnode;
return &ret->element; *elem = &ret->element;
return S_OK;
} }
...@@ -108,6 +108,7 @@ static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR t ...@@ -108,6 +108,7 @@ static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR t
HTMLDOMNode *node; HTMLDOMNode *node;
nsAString text_str; nsAString text_str;
nsresult nsres; nsresult nsres;
HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(text), newTextNode); TRACE("(%p)->(%s %p)\n", This, debugstr_w(text), newTextNode);
...@@ -124,8 +125,10 @@ static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR t ...@@ -124,8 +125,10 @@ static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR t
return E_FAIL; return E_FAIL;
} }
node = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext); hres = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext, &node);
nsIDOMElement_Release(nstext); nsIDOMElement_Release(nstext);
if(FAILED(hres))
return hres;
*newTextNode = HTMLDOMNODE(node); *newTextNode = HTMLDOMNODE(node);
IHTMLDOMNode_AddRef(HTMLDOMNODE(node)); IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
......
...@@ -125,9 +125,10 @@ static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bs ...@@ -125,9 +125,10 @@ static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bs
{ {
HTMLDocument *This = HTMLDOC5_THIS(iface); HTMLDocument *This = HTMLDOC5_THIS(iface);
nsIDOMComment *nscomment; nsIDOMComment *nscomment;
HTMLDOMNode *node; HTMLElement *elem;
nsAString str; nsAString str;
nsresult nsres; nsresult nsres;
HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrdata), ppRetNode); TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrdata), ppRetNode);
...@@ -144,11 +145,13 @@ static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bs ...@@ -144,11 +145,13 @@ static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bs
return E_FAIL; return E_FAIL;
} }
node = &HTMLCommentElement_Create(This->doc_node, (nsIDOMNode*)nscomment)->node; hres = HTMLCommentElement_Create(This->doc_node, (nsIDOMNode*)nscomment, &elem);
nsIDOMElement_Release(nscomment); nsIDOMElement_Release(nscomment);
if(FAILED(hres))
return hres;
*ppRetNode = HTMLDOMNODE(node); *ppRetNode = HTMLDOMNODE(&elem->node);
IHTMLDOMNode_AddRef(HTMLDOMNODE(node)); IHTMLDOMNode_AddRef(HTMLDOMNODE(&elem->node));
return S_OK; return S_OK;
} }
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml); WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
static HTMLDOMNode *get_node_obj(HTMLDocumentNode*,IUnknown*); static HTMLDOMNode *get_node_obj(HTMLDocumentNode*,IUnknown*);
static HTMLDOMNode *create_node(HTMLDocumentNode*,nsIDOMNode*); static HRESULT create_node(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
typedef struct { typedef struct {
DispatchEx dispex; DispatchEx dispex;
...@@ -962,7 +962,12 @@ void HTMLDOMNode_destructor(HTMLDOMNode *This) ...@@ -962,7 +962,12 @@ void HTMLDOMNode_destructor(HTMLDOMNode *This)
static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret) static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret)
{ {
*ret = create_node(This->doc, nsnode); HRESULT hres;
hres = create_node(This->doc, nsnode, ret);
if(FAILED(hres))
return hres;
IHTMLDOMNode_AddRef(HTMLDOMNODE(*ret)); IHTMLDOMNode_AddRef(HTMLDOMNODE(*ret));
return S_OK; return S_OK;
} }
...@@ -988,32 +993,45 @@ void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsno ...@@ -988,32 +993,45 @@ void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsno
doc->nodes = node; doc->nodes = node;
} }
static HTMLDOMNode *create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode) static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
{ {
HTMLDOMNode *ret;
PRUint16 node_type; PRUint16 node_type;
HRESULT hres;
nsIDOMNode_GetNodeType(nsnode, &node_type); nsIDOMNode_GetNodeType(nsnode, &node_type);
switch(node_type) { switch(node_type) {
case ELEMENT_NODE: case ELEMENT_NODE:
ret = &HTMLElement_Create(doc, nsnode, FALSE)->node; *ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
break; break;
case TEXT_NODE: case TEXT_NODE:
ret = HTMLDOMTextNode_Create(doc, nsnode); hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
if(FAILED(hres))
return hres;
break; break;
case COMMENT_NODE: case COMMENT_NODE: {
ret = &HTMLCommentElement_Create(doc, nsnode)->node; HTMLElement *comment;
hres = HTMLCommentElement_Create(doc, nsnode, &comment);
if(FAILED(hres))
return hres;
*ret = &comment->node;
break; break;
default:
ret = heap_alloc_zero(sizeof(HTMLDOMNode));
ret->vtbl = &HTMLDOMNodeImplVtbl;
HTMLDOMNode_Init(doc, ret, nsnode);
} }
default: {
HTMLDOMNode *node;
TRACE("type %d ret %p\n", node_type, ret); node = heap_alloc_zero(sizeof(HTMLDOMNode));
if(!node)
return E_OUTOFMEMORY;
return ret; node->vtbl = &HTMLDOMNodeImplVtbl;
HTMLDOMNode_Init(doc, node, nsnode);
*ret = node;
}
}
TRACE("type %d ret %p\n", node_type, *ret);
return S_OK;
} }
/* /*
...@@ -1037,8 +1055,7 @@ HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDO ...@@ -1037,8 +1055,7 @@ HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDO
return S_OK; return S_OK;
} }
*ret = create_node(This, nsnode); return create_node(This, nsnode, ret);
return *ret ? S_OK : E_OUTOFMEMORY;
} }
/* /*
......
...@@ -190,8 +190,12 @@ static void HTMLDOMTextNode_destructor(HTMLDOMNode *iface) ...@@ -190,8 +190,12 @@ static void HTMLDOMTextNode_destructor(HTMLDOMNode *iface)
static HRESULT HTMLDOMTextNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret) static HRESULT HTMLDOMTextNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
{ {
HTMLDOMTextNode *This = HTMLTEXT_NODE_THIS(iface); HTMLDOMTextNode *This = HTMLTEXT_NODE_THIS(iface);
HRESULT hres;
hres = HTMLDOMTextNode_Create(This->node.doc, nsnode, ret);
if(FAILED(hres))
return hres;
*ret = HTMLDOMTextNode_Create(This->node.doc, nsnode);
IHTMLDOMNode_AddRef(HTMLDOMNODE(*ret)); IHTMLDOMNode_AddRef(HTMLDOMNODE(*ret));
return S_OK; return S_OK;
} }
...@@ -217,21 +221,28 @@ static dispex_static_data_t HTMLDOMTextNode_dispex = { ...@@ -217,21 +221,28 @@ static dispex_static_data_t HTMLDOMTextNode_dispex = {
HTMLDOMTextNode_iface_tids HTMLDOMTextNode_iface_tids
}; };
HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode) HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **node)
{ {
HTMLDOMTextNode *ret; HTMLDOMTextNode *ret;
nsresult nsres; nsresult nsres;
ret = heap_alloc_zero(sizeof(*ret)); ret = heap_alloc_zero(sizeof(*ret));
if(!ret)
return E_OUTOFMEMORY;
ret->node.vtbl = &HTMLDOMTextNodeImplVtbl; ret->node.vtbl = &HTMLDOMTextNodeImplVtbl;
ret->lpIHTMLDOMTextNodeVtbl = &HTMLDOMTextNodeVtbl; ret->lpIHTMLDOMTextNodeVtbl = &HTMLDOMTextNodeVtbl;
init_dispex(&ret->node.dispex, (IUnknown*)HTMLTEXT(ret), &HTMLDOMTextNode_dispex);
HTMLDOMNode_Init(doc, &ret->node, nsnode);
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&ret->nstext); nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&ret->nstext);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMText iface: %08x\n", nsres); ERR("Could not get nsIDOMText iface: %08x\n", nsres);
heap_free(ret);
return E_FAIL;
}
return &ret->node; init_dispex(&ret->node.dispex, (IUnknown*)HTMLTEXT(ret), &HTMLDOMTextNode_dispex);
HTMLDOMNode_Init(doc, &ret->node, nsnode);
*node = &ret->node;
return S_OK;
} }
...@@ -818,10 +818,10 @@ HRESULT get_node_text(HTMLDOMNode*,BSTR*); ...@@ -818,10 +818,10 @@ HRESULT get_node_text(HTMLDOMNode*,BSTR*);
HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**); HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*); HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL); HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*); HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**);
HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*); HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*); HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
HTMLElement *HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*); HTMLElement *HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
......
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