Module: wine Branch: master Commit: b99c89f38369a9894430d32209fcf60c5f65b8cf URL: https://gitlab.winehq.org/wine/wine/-/commit/b99c89f38369a9894430d32209fcf60...
Author: Gabriel Ivăncescu gabrielopcode@gmail.com Date: Fri Nov 25 19:10:04 2022 +0200
mshtml: Return proper error for invalid selectors in IE8 mode.
More importantly it gets rid of the ERR since such failures are normal.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
---
dlls/mshtml/htmldoc.c | 13 +++++---- dlls/mshtml/htmlelem.c | 13 +++++---- dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/nsembed.c | 2 ++ dlls/mshtml/tests/documentmode.js | 58 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 12 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index d4d32693f80..a80dfe4f671 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -4742,8 +4742,8 @@ static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, B nsres = nsIDOMDocument_QuerySelector(This->dom_document, &nsstr, &nselem); nsAString_Finish(&nsstr); if(NS_FAILED(nsres)) { - ERR("QuerySelector failed: %08lx\n", nsres); - return E_FAIL; + WARN("QuerySelector failed: %08lx\n", nsres); + return map_nsresult(nsres); }
if(!nselem) { @@ -4765,16 +4765,17 @@ static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface HTMLDocumentNode *This = impl_from_IDocumentSelector(iface); nsIDOMNodeList *node_list; nsAString nsstr; + nsresult nsres; HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
nsAString_InitDepend(&nsstr, v); - hres = map_nsresult(nsIDOMDocument_QuerySelectorAll(This->dom_document, &nsstr, &node_list)); + nsres = nsIDOMDocument_QuerySelectorAll(This->dom_document, &nsstr, &node_list); nsAString_Finish(&nsstr); - if(FAILED(hres)) { - ERR("QuerySelectorAll failed: %08lx\n", hres); - return hres; + if(NS_FAILED(nsres)) { + WARN("QuerySelectorAll failed: %08lx\n", nsres); + return map_nsresult(nsres); }
hres = create_child_collection(node_list, dispex_compat_mode(&This->node.event_target.dispex), pel); diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index 24040d914ec..07fe6141e6b 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -6344,8 +6344,8 @@ static HRESULT WINAPI ElementSelector_querySelector(IElementSelector *iface, BST nsres = nsIDOMElement_QuerySelector(This->dom_element, &nsstr, &nselem); nsAString_Finish(&nsstr); if(NS_FAILED(nsres)) { - ERR("QuerySelector failed: %08lx\n", nsres); - return E_FAIL; + WARN("QuerySelector failed: %08lx\n", nsres); + return map_nsresult(nsres); }
if(!nselem) { @@ -6367,6 +6367,7 @@ static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface, HTMLElement *This = impl_from_IElementSelector(iface); nsIDOMNodeList *node_list; nsAString nsstr; + nsresult nsres; HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel); @@ -6377,11 +6378,11 @@ static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface, }
nsAString_InitDepend(&nsstr, v); - hres = map_nsresult(nsIDOMElement_QuerySelectorAll(This->dom_element, &nsstr, &node_list)); + nsres = nsIDOMElement_QuerySelectorAll(This->dom_element, &nsstr, &node_list); nsAString_Finish(&nsstr); - if(FAILED(hres)) { - ERR("QuerySelectorAll failed: %08lx\n", hres); - return hres; + if(NS_FAILED(nsres)) { + WARN("QuerySelectorAll failed: %08lx\n", nsres); + return map_nsresult(nsres); }
hres = create_child_collection(node_list, dispex_compat_mode(&This->node.event_target.dispex), pel); diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index af1c50c5091..b750cad6585 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -59,6 +59,7 @@ #define NS_ERROR_INVALID_ARG ((nsresult)0x80070057L) #define NS_ERROR_UNEXPECTED ((nsresult)0x8000ffffL) #define NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR ((nsresult)0x80530007) +#define NS_ERROR_DOM_SYNTAX_ERR ((nsresult)0x8053000c)
#define NS_ERROR_MODULE_NETWORK 6
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 8fb3b2a52ed..b7518f55ef9 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -911,6 +911,8 @@ HRESULT map_nsresult(nsresult nsres) return E_UNEXPECTED; case NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR: return 0x80700007; /* according to tests */ + case NS_ERROR_DOM_SYNTAX_ERR: + return E_INVALIDARG; /* FIXME: Throw SyntaxError for IE9+ modes */ case NS_BINDING_ABORTED: return E_ABORT; } diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index 8fd97d11cd6..760d8db5e38 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -2200,6 +2200,64 @@ sync_test("nullDisp", function() { } });
+sync_test("invalid selectors", function() { + var v = document.documentMode, body = document.body, i; + if(v < 8) + return; + + var selectors = [ + "[s!='']", + "*,:x", + "*,##", + ":x", + "##", + "*,", + "," + ]; + + for(i = 0; i < selectors.length; i++) { + try { + body.querySelector(selectors[i]); + ok(false, "body.querySelector("" + selectors[i] + "" did not throw exception"); + }catch(e) { + if(v < 9) + ok(e.number === 0x70057 - 0x80000000, "body.querySelector("" + selectors[i] + "" threw " + e.number); + else { + todo_wine. + ok(e.name === (v < 10 ? undefined : "SyntaxError"), "body.querySelector("" + selectors[i] + "" threw " + e.name); + } + } + try { + body.querySelectorAll(selectors[i]); + ok(false, "body.querySelectorAll("" + selectors[i] + "" did not throw exception"); + }catch(e) { + if(v < 9) + ok(e.number === 0x70057 - 0x80000000, "body.querySelectorAll("" + selectors[i] + "" threw " + e.number); + else { + todo_wine. + ok(e.name === (v < 10 ? undefined : "SyntaxError"), "body.querySelectorAll("" + selectors[i] + "" threw " + e.name); + } + } + } + + if(!body.msMatchesSelector) + return; + + for(i = 0; i < selectors.length; i++) { + try { + body.msMatchesSelector(selectors[i]); + ok(false, "body.msMatchesSelector("" + selectors[i] + "" did not throw exception"); + }catch(e) { + if(v < 9) + ok(e.number === 0x70057 - 0x80000000, "body.msMatchesSelector("" + selectors[i] + "" threw " + e.number); + else { + todo_wine. + ok(e.name === (v < 10 ? undefined : "SyntaxError"), "body.msMatchesSelector("" + selectors[i] + "" threw " + e.name); + } + } + } +}); + sync_test("__proto__", function() { var v = document.documentMode; var r, x = 42;