changeset 1371:4a12b571aa4c

8067420: BrowserJSObjectLinker should give priority to beans linker for property get/set Reviewed-by: lagergren, attila, hannesw
author sundar
date Mon, 15 Dec 2014 16:30:45 +0530
parents 1088408b1c02
children b9dda83d984b
files samples/browser_dom.js src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java
diffstat 2 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/samples/browser_dom.js	Thu Jan 15 10:18:31 2015 +0530
+++ b/samples/browser_dom.js	Mon Dec 15 16:30:45 2014 +0530
@@ -1,4 +1,4 @@
-#// Usage: jjs -fx browser.js
+#// Usage: jjs -fx browser_dom.js
 
 /*
  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 if (!$OPTIONS._fx) {
-    print("Usage: jjs -fx browser.js");
+    print("Usage: jjs -fx browser_dom.js");
     exit(1);
 }
 
@@ -74,10 +74,10 @@
                var btn = document.createElement("button");
                var n = 0;
                // attach a button handler - nashorn function!
-               btn.onclick = new EventListener(function() {
+               btn.onclick = function() {
                    n++; print("You clicked " + n + " time(s)");
                    print("you clicked OK " + wv.engine.executeScript("okCount"));
-               });
+               };
                // attach text to button
                var t = document.createTextNode("Click Me!"); 
                btn.appendChild(t);
--- a/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java	Thu Jan 15 10:18:31 2015 +0530
+++ b/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java	Mon Dec 15 16:30:45 2014 +0530
@@ -112,20 +112,21 @@
     private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
         final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
         final int c = desc.getNameTokenCount();
+        GuardedInvocation inv;
+        try {
+            inv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
+        } catch (Throwable th) {
+            inv = null;
+        }
 
         switch (operator) {
             case "getProp":
             case "getElem":
             case "getMethod":
-                if (c > 2) {
-                    return findGetMethod(desc);
-                }
-            // For indexed get, we want GuardedInvocation from beans linker and pass it.
-            // BrowserJSObjectLinker.get uses this fallback getter for explicit signature method access.
-            return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices));
+                return c > 2? findGetMethod(desc, inv) : findGetIndexMethod(inv);
             case "setProp":
             case "setElem":
-                return c > 2 ? findSetMethod(desc) : findSetIndexMethod();
+                return c > 2? findSetMethod(desc, inv) : findSetIndexMethod();
             case "call":
                 return findCallMethod(desc);
             default:
@@ -133,7 +134,10 @@
         }
     }
 
-    private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc) {
+    private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final GuardedInvocation inv) {
+        if (inv != null) {
+            return inv;
+        }
         final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
         final MethodHandle getter = MH.insertArguments(JSOBJECT_GETMEMBER, 1, name);
         return new GuardedInvocation(getter, IS_JSOBJECT_GUARD);
@@ -144,7 +148,10 @@
         return inv.replaceMethods(getter, inv.getGuard());
     }
 
-    private static GuardedInvocation findSetMethod(final CallSiteDescriptor desc) {
+    private static GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final GuardedInvocation inv) {
+        if (inv != null) {
+            return inv;
+        }
         final MethodHandle getter = MH.insertArguments(JSOBJECT_SETMEMBER, 1, desc.getNameToken(2));
         return new GuardedInvocation(getter, IS_JSOBJECT_GUARD);
     }