CVS Commit: src/xdocs: Javascript: allow to set current node's property

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

CVS Commit: src/xdocs: Javascript: allow to set current node's property

mguillem
Log Message:
-----------
Javascript: allow to set current node's property within onclick event handler. Fix for bug 1260369.

Modified Files:
--------------
    htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host:
        Event.java
        (http://cvs.sourceforge.net/viewcvs.py/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java)
    htmlunit/src/xdocs:
        changes.xml
        (http://cvs.sourceforge.net/viewcvs.py/htmlunit/htmlunit/src/xdocs/changes.xml)
    htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html:
        ClickableElementTest.java
        (http://cvs.sourceforge.net/viewcvs.py/htmlunit/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java)
    htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript:
        SimpleScriptable.java
        (http://cvs.sourceforge.net/viewcvs.py/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java)

Revision Data
-------------
Index: ClickableElementTest.java
===================================================================
RCS file: /cvsroot/htmlunit/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lsrc/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java -Lsrc/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java -u -d -r1.14 -r1.15
--- src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java
+++ src/test/java/com/gargoylesoftware/htmlunit/html/ClickableElementTest.java
@@ -48,11 +48,12 @@
 import com.gargoylesoftware.htmlunit.WebTestCase;
 
 /**
- *  Tests for ClickableElementTest
+ * Tests for {@link ClickableElement}.
  *
- * @version  $Revision$
- * @author  David K. Taylor
+ * @version $Revision$
+ * @author David K. Taylor
  * @author Chris Erskine
+ * @author Marc Guillemot
  */
 public class ClickableElementTest extends WebTestCase {
     /**
@@ -87,7 +88,7 @@
      * @param expectedAlerts List of expected popup values
      * @throws Exception if the test fails
      */
-    private void onClickPageTest(final String htmlContent, final int numClicks, final List expectedAlerts)
+    private void onClickPageTest(final String htmlContent, final int numClicks, final List expectedAlerts)
         throws Exception {
         final BrowserVersion bv = new BrowserVersion("Netscape", "7", "", "1.2", 7);
         final WebClient client = new WebClient(bv);
@@ -963,19 +964,16 @@
     public void testVariable_onClick() throws Exception {
         onClickSimpleTest("var");
     }
-    
+
     /**
      * Test setting onClick handler from inside the onClick handler
      *
      * @throws Exception if the test fails
      */
     public void testSetOnClick() throws Exception {
-        if (notYetImplemented()) {
-            return;
-        }
         final List expectedAlerts = Arrays.asList(new String[] {"foo"});
-        onClickPageTest("<body><form>" +
-                "<button type='button' id='clickId' onclick='alert(\"foo\"); onclick==\"\";'>Item</button>" +
-                "</form></body>", 2, expectedAlerts);
-    }    
+        onClickPageTest("<html><body><form>" +
+                "<button type='button' id='clickId' onclick='alert(\"foo\"); onclick=null;'>Item</button>" +
+                "</form></body></html>", 2, expectedAlerts);
+    }
 }
Index: changes.xml
===================================================================
RCS file: /cvsroot/htmlunit/htmlunit/src/xdocs/changes.xml,v
retrieving revision 1.444
retrieving revision 1.445
diff -Lsrc/xdocs/changes.xml -Lsrc/xdocs/changes.xml -u -d -r1.444 -r1.445
--- src/xdocs/changes.xml
+++ src/xdocs/changes.xml
@@ -7,6 +7,9 @@
 
     <body>
         <release version="NextRelease" date="Unknown">
+            <action type="update" dev="mguillem" id="1260369">
+                Javascript: allow to set current node's property within onclick event handler.
+            </action>
             <action type="update" dev="mguillem" id="1209682">
                 Javascript: XMLHttpRequest now accepts non xml responses.
             </action>
Index: Event.java
===================================================================
RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lsrc/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java -Lsrc/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java -u -d -r1.5 -r1.6
--- src/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java
+++ src/java/com/gargoylesoftware/htmlunit/javascript/host/Event.java
@@ -50,6 +50,7 @@
  * @author <a hrer="mailto:[hidden email]">Chris Eldredge</a>
  * @author Mike Bowler
  * @author Chris Erskine
+ * @author Marc Guillemot
  */
 public class Event extends SimpleScriptable {
 
@@ -65,8 +66,9 @@
         super();
 
         currentTarget_ = currentTarget;
+        setParentScope((SimpleScriptable) domNode.getScriptObject());
 
-        super.setDomNode(domNode, false);
+        setDomNode(domNode, false);
     }
 
     /**
Index: SimpleScriptable.java
===================================================================
RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lsrc/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java -Lsrc/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java -u -d -r1.66 -r1.67
--- src/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java
+++ src/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java
@@ -95,7 +95,7 @@
 
     private JavaScriptConfiguration getJavaScriptConfiguration() {
         final BrowserVersion browserVersion
-            = getDomNodeOrDie().getPage().getWebClient().getBrowserVersion();
+            = getWindow().getWebWindow().getWebClient().getBrowserVersion();
         return JavaScriptConfiguration.getInstance(browserVersion);
     }
 
@@ -532,4 +532,22 @@
     protected Scriptable getStartingScope() {
         return (Scriptable) Context.getCurrentContext().getThreadLocal(JavaScriptEngine.KEY_STARTING_SCOPE);
     }
+
+    /**
+     *
+     * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable)
+     */
+    public boolean has(final String name, final Scriptable start) {
+        final SimpleScriptable simpleScriptable = (SimpleScriptable) start;
+
+        final JavaScriptConfiguration configuration = simpleScriptable.getJavaScriptConfiguration();
+        // getters and setters are defined on prototypes
+        if ((start == start.getPrototype() || simpleScriptable.getDomNodeOrNull() != null)
+                && configuration.getPropertyReadMethod(getClass(), name) != null) {
+            return true;
+        }
+        else {
+            return super.has(name, start);
+        }
+    }
 }


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop