From: <asa...@us...> - 2012-11-05 08:17:43
|
Revision: 7682 http://sourceforge.net/p/htmlunit/code/7682 Author: asashour Date: 2012-11-05 08:17:40 +0000 (Mon, 05 Nov 2012) Log Message: ----------- JavaScript: remove unneeded global properties (FF). 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/JavaScriptEngine2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-11-05 06:37:03 UTC (rev 7681) +++ trunk/htmlunit/src/changes/changes.xml 2012-11-05 08:17:40 UTC (rev 7682) @@ -8,6 +8,9 @@ <body> <release version="2.11" date="???" description="Bugfixes, Java 6, HtmlPage.getElementById(), .type() special keys, initial WebSocket support, initial SVG support, primitive Geolocation support, SOCKS proxy for https, CORS"> + <action type="fix" dev="asashour"> + JavaScript: remove unneeded global properties (FF). + </action> <action type="add" dev="asashour" issue="1420"> JavaScript: implement "constructor" property of all host objects (FF). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-05 06:37:03 UTC (rev 7681) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-05 08:17:40 UTC (rev 7682) @@ -290,10 +290,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_144, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_150, /** Was originally .isFirefox(). */ @@ -1038,6 +1034,10 @@ @BrowserFeature(@WebBrowser(IE)) JS_WINDOW_IS_NOT_A_FUNCTION, + /** Supports XML. */ + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) + JS_XML, + /** Indicates that a xml attribute supports the text property. */ @BrowserFeature(@WebBrowser(IE)) JS_XML_ATTRIBUTE_HAS_TEXT_PROPERTY, 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-05 06:37:03 UTC (rev 7681) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2012-11-05 08:17:40 UTC (rev 7682) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_144; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ALLOW_CONST_ASSIGNMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CONSTRUCTOR; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFINE_GETTER; @@ -23,6 +22,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FUNCTION_BIND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FUNCTION_TOSOURCE; 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 java.io.IOException; @@ -197,9 +197,10 @@ } // remove some objects, that Rhino defines in top scope but that we don't want - deleteProperties(window, "javax", "org", "com", "edu", "net", "JavaAdapter", "JavaImporter", "Continuation"); - if (browserVersion.hasFeature(GENERATED_144)) { - deleteProperties(window, "Packages", "java", "getClass", "XML", "XMLList", "Namespace", "QName"); + deleteProperties(window, "java", "javax", "org", "com", "edu", "net", + "JavaAdapter", "JavaImporter", "Continuation", "Packages", "getClass"); + if (!browserVersion.hasFeature(JS_XML)) { + deleteProperties(window, "XML", "XMLList", "Namespace", "QName"); } // put custom object to be called as very last prototype to call the fallback getter (if any) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2012-11-05 06:37:03 UTC (rev 7681) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2012-11-05 08:17:40 UTC (rev 7682) @@ -200,4 +200,45 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("exception") + public void packages() throws Exception { + object("Packages"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("exception") + public void java() throws Exception { + object("java"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("undefined") + public void object_getClass() throws Exception { + object("window.getClass"); + } + + private void object(final String object) throws Exception { + final String html = "<html><head></head><body>\n" + + "<script>\n" + + "try {\n" + + " alert(" + object + ");\n" + + "} catch (e) {\n" + + " alert('exception');\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |