From: <mgu...@us...> - 2013-01-24 11:16:31
|
Revision: 8033 http://sourceforge.net/p/htmlunit/code/8033 Author: mguillem Date: 2013-01-24 11:16:28 +0000 (Thu, 24 Jan 2013) Log Message: ----------- JavaScript: fixed hanging problem (infinite loop) after Object function was called with a window as parameter. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-24 11:16:28 UTC (rev 8033) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem"> + JavaScript: fixed hanging problem (infinite loop) after Object function was called with a window as parameter. + </action> <action type="fix" dev="mguillem" issue="1458"> JavaScript: determine default path for cookies set with document.cookie from current URL. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java 2013-01-24 11:16:28 UTC (rev 8033) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; + import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptableProxy; @@ -43,4 +45,12 @@ return (Window) webWindow_.getScriptObject(); } + /** + * Does nothing. + * @param parent the new parent scope + */ + @Override + public void setParentScope(final Scriptable parent) { + // nothing as the window is the top level scope and its parent scope should stay null + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-24 11:16:28 UTC (rev 8033) @@ -1029,4 +1029,25 @@ loadPageWithAlerts2(html); } + + /** + * This was causing HtmlUnit to hang as of HtmlUnit-2.12 snapshot from 24.01.2013 and probably since a very long + * time. + * The reason was that "top" evaluate to WindowProxy and "Object(top)" was setting the top scope as parentScope + * of the WindowProxy which was setting it on the Window where it should always be null. + * @throws Exception if the test fails + */ + @Test + @Alerts("undefined") + public void hangingObjectCallOnWindowProxy() throws Exception { + final String html = "<html><body>\n" + + "<iframe id='it'></iframe>;\n" + + "<script>\n" + + " Object(top);\n" + + " alert(window.foo);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |