From: <asa...@us...> - 2012-11-27 08:43:08
|
Revision: 7784 http://sourceforge.net/p/htmlunit/code/7784 Author: asashour Date: 2012-11-27 08:43:05 +0000 (Tue, 27 Nov 2012) Log Message: ----------- JavaScript: properties of Array.prototype should be defined in standards mode (IE), thanks to jQuery. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-11-27 07:10:33 UTC (rev 7783) +++ trunk/htmlunit/src/changes/changes.xml 2012-11-27 08:43:05 UTC (rev 7784) @@ -9,6 +9,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> <action type="fix" dev="asashour"> + JavaScript: properties of Array.prototype should be defined in standards mode (IE). + </action> + <action type="fix" dev="asashour"> JavaScript: correctly process null function handlers. </action> <action type="fix" dev="asashour"> @@ -24,7 +27,7 @@ JavaScript: fix the return value of element.getAttribute() in standards mode (IE). </action> <action type="fix" dev="asashour"> - JavaScript: element.set/getAttribute() should fix the name (e.g. "className") only in Quirks mode (IE). + JavaScript: element.set/getAttribute() should fix the name (e.g. "className") only in quirks mode (IE). </action> <action type="fix" dev="mguillem"> Cookies: use 1970 as two digits year start for the expiration date. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2012-11-27 07:10:33 UTC (rev 7783) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2012-11-27 08:43:05 UTC (rev 7784) @@ -41,6 +41,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.Script; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -184,6 +185,10 @@ @Override public void initialize() throws IOException, FailingHttpStatusCodeException { final WebWindow enclosingWindow = getEnclosingWindow(); + if (isQuirksMode()) { + removePrototypeProperties((Scriptable) enclosingWindow.getScriptObject(), "Array", + "every", "filter", "forEach", "indexOf", "lastIndexOf", "map", "reduce", "reduceRight", "some"); + } final boolean isAboutBlank = getUrl() == WebClient.URL_ABOUT_BLANK; if (isAboutBlank) { // a frame contains first a faked "about:blank" before its real content specified by src gets loaded @@ -257,6 +262,20 @@ } /** + * Removes prototype properties. + * @param scope the scope + * @param className the class for which properties should be removed + * @param properties the properties to remove + */ + private void removePrototypeProperties(final Scriptable scope, final String className, + final String... properties) { + final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(scope, className); + for (final String property : properties) { + prototype.delete(property); + } + } + + /** * Adds an action that should be executed once the page has been loaded. * @param action the action */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2012-11-27 07:10:33 UTC (rev 7783) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2012-11-27 08:43:05 UTC (rev 7784) @@ -301,8 +301,6 @@ if (!browserVersion.hasFeature(JS_DEFINE_GETTER)) { removePrototypeProperties(window, "Object", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"); - removePrototypeProperties(window, "Array", "every", "filter", "forEach", "indexOf", "lastIndexOf", "map", - "reduce", "reduceRight", "some"); } // only FF has toSource @@ -356,12 +354,13 @@ /** * Removes prototype properties. - * @param window the scope + * @param scope the scope * @param className the class for which properties should be removed * @param properties the properties to remove */ - private void removePrototypeProperties(final Window window, final String className, final String... properties) { - final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, className); + private void removePrototypeProperties(final Scriptable scope, final String className, + final String... properties) { + final ScriptableObject prototype = (ScriptableObject) ScriptableObject.getClassPrototype(scope, className); for (final String property : properties) { prototype.delete(property); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java 2012-11-27 07:10:33 UTC (rev 7783) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollectionTest.java 2012-11-27 08:43:05 UTC (rev 7784) @@ -25,6 +25,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; /** * Tests for {@link HTMLCollection}. @@ -273,4 +274,48 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "undefined", "undefined", "undefined", "undefined" }, + DEFAULT = { "function", "function", "function", "function" }) + public void array_prototype() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(typeof Object.prototype.__defineGetter__);\n" + + " alert(typeof Object.prototype.__lookupGetter__);\n" + + " alert(typeof Array.prototype.indexOf);\n" + + " alert(typeof Array.prototype.map);\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "undefined", "undefined", "function", "function" }, + DEFAULT = { "function", "function", "function", "function" }) + public void array_prototype_standards() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(typeof Object.prototype.__defineGetter__);\n" + + " alert(typeof Object.prototype.__lookupGetter__);\n" + + " alert(typeof Array.prototype.indexOf);\n" + + " alert(typeof Array.prototype.map);\n" + + " }\n" + + "</script></head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-27 07:10:33 UTC (rev 7783) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-27 08:43:05 UTC (rev 7784) @@ -3057,7 +3057,6 @@ @Test @Alerts(FF3_6 = "traversing: not(Array) (0, 2, 2)", FF10 = "traversing: not(jQuery) (0, 1, 1)", CHROME = "traversing: not(Array) (0, 2, 2)", IE = "traversing: not(Array) (0, 2, 2)") - @NotYetImplemented(IE) public void test_279() throws Exception { runTest(279); } |