From: <rb...@us...> - 2013-04-09 16:05:06
|
Revision: 8215 http://sourceforge.net/p/htmlunit/code/8215 Author: rbri Date: 2013-04-09 16:05:03 +0000 (Tue, 09 Apr 2013) Log Message: ----------- IE 9 supports String.trim(). Issue 1501 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-09 16:05:03 UTC (rev 8215) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1501"> + JavaScript: IE 9 supports String.trim(). + </action> <action type="update" dev="rbri"> Upgrade commons-logging to 1.1.2. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -1180,10 +1180,14 @@ @BrowserFeature({ @WebBrowser(value = FF, maxVersion = 10), @WebBrowser(CHROME) }) STORAGE_OBSOLETE, - /** Indicates that string.trim(), .trimLeft() and .trimRight() are supported. */ + /** Indicates that string.trim() is supported. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) STRING_TRIM, + /** Indicates that string.trimLeft() and .trimRight() are supported. */ + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 9), @WebBrowser(CHROME) }) + STRING_TRIM_LEFT_RIGHT, + /** * Indicates that the href property for a <link rel="stylesheet" type="text/css" href="..." /> * is the fully qualified URL. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -25,6 +25,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HAS_OBJECT_WITH_PROTOTYPE_PROPERTY_IN_WINDOW_SCOPE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STRING_TRIM; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STRING_TRIM_LEFT_RIGHT; import java.io.IOException; import java.io.ObjectInputStream; @@ -284,15 +285,16 @@ // Rhino defines too much methods for us, particularly since implementation of ECMAScript5 removePrototypeProperties(window, "String", "equals", "equalsIgnoreCase"); - if (browserVersion.hasFeature(STRING_TRIM)) { + if (!browserVersion.hasFeature(STRING_TRIM)) { + removePrototypeProperties(window, "String", "trim"); + } + if (browserVersion.hasFeature(STRING_TRIM_LEFT_RIGHT)) { final ScriptableObject stringPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "String"); stringPrototype.defineFunctionProperties(new String[] {"trimLeft", "trimRight"}, StringCustom.class, ScriptableObject.EMPTY); } - else { - removePrototypeProperties(window, "String", "trim"); - } + if (!browserVersion.hasFeature(JS_FUNCTION_BIND)) { removePrototypeProperties(window, "Function", "bind"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -92,15 +92,56 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = "", DEFAULT = { "2", "3", "4" }) + @Alerts(IE8 = "", DEFAULT = "2") public void trim() throws Exception { final String html - = "<html><head><title>foo</title><script>\n" + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + "function doTest() {\n" + " var string = ' hi ';\n" + " if (''.trim) {\n" + " alert(string.trim().length);\n" + + " }\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = "", DEFAULT = "3") + public void trimRight() throws Exception { + final String html + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var string = ' hi ';\n" + + " if (''.trimRight) {\n" + " alert(string.trimRight().length);\n" + + " }\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = "", DEFAULT = "4") + public void trimLeft() throws Exception { + final String html + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var string = ' hi ';\n" + + " if (''.trimLeft) {\n" + " alert(string.trimLeft().length);\n" + " }\n" + "}\n" @@ -109,5 +150,4 @@ loadPageWithAlerts2(html); } - } |