From: <rb...@us...> - 2017-12-01 07:16:34
|
Revision: 14983 http://sourceforge.net/p/htmlunit/code/14983 Author: rbri Date: 2017-12-01 07:16:31 +0000 (Fri, 01 Dec 2017) Log Message: ----------- WebSocket constructor call failed with a NPE when called during page construction Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-11-29 20:13:19 UTC (rev 14982) +++ trunk/htmlunit/src/changes/changes.xml 2017-12-01 07:16:31 UTC (rev 14983) @@ -9,6 +9,9 @@ <body> <release version="2.29" date="xx, 2017" description=""> <action type="fix" dev="rbri" issue="1932"> + JavaScript: WebSocket constructor call failed with a NPE when called during page construction. + </action> + <action type="fix" dev="rbri" issue="1932"> JavaScript: fix Number.toLocaleString() to be able to support locale strings like 'en-US'. </action> <action type="add" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-11-29 20:13:19 UTC (rev 14982) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-12-01 07:16:31 UTC (rev 14983) @@ -128,7 +128,7 @@ try { containingPage_ = (HtmlPage) window.getWebWindow().getEnclosedPage(); setParentScope(window); - setDomNode(containingPage_.getBody(), false); + setDomNode(containingPage_.getDocumentElement(), false); final WebClient webClient = window.getWebWindow().getWebClient(); if (webClient.getOptions().isUseInsecureSSL()) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-11-29 20:13:19 UTC (rev 14982) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-12-01 07:16:31 UTC (rev 14983) @@ -90,6 +90,27 @@ * @throws Exception if the test fails */ @Test + @Alerts({"[object WebSocket]", "ws://localhost:12345/"}) + public void earlyConstruction() throws Exception { + final String html = "<html><head><script>\n" + + " function test() {\n" + + " var location = 'ws://localhost:" + PORT + "/';\n" + + " var ws = new WebSocket(location);\n" + + " alert(ws);\n" + + " alert(ws.url);\n" + + " }\n" + + " test();\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts({"exception undefined", "exception null", "exception empty", "exception invalid"}) public void initialWithoutUrl() throws Exception { final String html = "<html><head><script>\n" |