Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
Tests for this are added later in the series. The reason we implement it now is because it is required for the *existing* tests to pass once proxies are implemented. Some of the existing mshtml tests have checks of the form:
ok(e === something, "e = " + e);
Where `e` is an element. Currently this retrieves its value prop, but once proxies are implemented for modes >= IE9, it will try to obtain its toString method when concatenating (this is the behavior for JS objects, so it's correct), making the tests throw an exception, even when otherwise passing, because of them returning E_NOTIMPL.
Implementing it now resolves this issue. Implementation of the other missing toString methods will follow after this series.
dlls/mshtml/htmlelem.c | 45 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index d9554f4..4d11d67 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -2111,9 +2111,50 @@ static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *
static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String) { + static const WCHAR prefix[12] = L"[object HTML"; + static const WCHAR suffix[] = L"Element]"; + HTMLElement *This = impl_from_IHTMLElement(iface); - FIXME("(%p)->(%p)\n", This, String); - return E_NOTIMPL; + const PRUnichar *str; + nsAString tag_str; + nsresult nsres; + WCHAR *tmp, *p; + HRESULT hres; + + TRACE("(%p)->(%p)\n", This, String); + + if(!This->dom_element) { + *String = SysAllocString(L"[object HTMLCommentElement]"); + return *String ? S_OK : E_OUTOFMEMORY; + } + + nsAString_Init(&tag_str, NULL); + nsres = nsIDOMElement_GetTagName(This->dom_element, &tag_str); + if(NS_FAILED(nsres)) { + nsAString_Finish(&tag_str); + return map_nsresult(nsres); + } + nsAString_GetData(&tag_str, &str); + + tmp = heap_alloc(sizeof(prefix) + sizeof(suffix) + wcslen(str) * sizeof(WCHAR)); + if(tmp) { + memcpy(tmp, prefix, sizeof(prefix)); + p = tmp + ARRAY_SIZE(prefix); + if(*str) { + *p++ = *str++; /* copy first uppercase char */ + while(*str) + *p++ = tolower(*str++); + } + memcpy(p, suffix, sizeof(suffix)); + + *String = SysAllocString(tmp); + hres = *String ? S_OK : E_OUTOFMEMORY; + heap_free(tmp); + }else + hres = E_OUTOFMEMORY; + + nsAString_Finish(&tag_str); + return hres; }
static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)