Mon, 15 Dec 2014 16:30:45 +0530
8067420: BrowserJSObjectLinker should give priority to beans linker for property get/set
Reviewed-by: lagergren, attila, hannesw
samples/browser_dom.js | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java | file | annotate | diff | comparison | revisions |
1.1 --- a/samples/browser_dom.js Thu Jan 15 10:18:31 2015 +0530 1.2 +++ b/samples/browser_dom.js Mon Dec 15 16:30:45 2014 +0530 1.3 @@ -1,4 +1,4 @@ 1.4 -#// Usage: jjs -fx browser.js 1.5 +#// Usage: jjs -fx browser_dom.js 1.6 1.7 /* 1.8 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.9 @@ -32,7 +32,7 @@ 1.10 */ 1.11 1.12 if (!$OPTIONS._fx) { 1.13 - print("Usage: jjs -fx browser.js"); 1.14 + print("Usage: jjs -fx browser_dom.js"); 1.15 exit(1); 1.16 } 1.17 1.18 @@ -74,10 +74,10 @@ 1.19 var btn = document.createElement("button"); 1.20 var n = 0; 1.21 // attach a button handler - nashorn function! 1.22 - btn.onclick = new EventListener(function() { 1.23 + btn.onclick = function() { 1.24 n++; print("You clicked " + n + " time(s)"); 1.25 print("you clicked OK " + wv.engine.executeScript("okCount")); 1.26 - }); 1.27 + }; 1.28 // attach text to button 1.29 var t = document.createTextNode("Click Me!"); 1.30 btn.appendChild(t);
2.1 --- a/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java Thu Jan 15 10:18:31 2015 +0530 2.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java Mon Dec 15 16:30:45 2014 +0530 2.3 @@ -112,20 +112,21 @@ 2.4 private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception { 2.5 final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0); 2.6 final int c = desc.getNameTokenCount(); 2.7 + GuardedInvocation inv; 2.8 + try { 2.9 + inv = nashornBeansLinker.getGuardedInvocation(request, linkerServices); 2.10 + } catch (Throwable th) { 2.11 + inv = null; 2.12 + } 2.13 2.14 switch (operator) { 2.15 case "getProp": 2.16 case "getElem": 2.17 case "getMethod": 2.18 - if (c > 2) { 2.19 - return findGetMethod(desc); 2.20 - } 2.21 - // For indexed get, we want GuardedInvocation from beans linker and pass it. 2.22 - // BrowserJSObjectLinker.get uses this fallback getter for explicit signature method access. 2.23 - return findGetIndexMethod(nashornBeansLinker.getGuardedInvocation(request, linkerServices)); 2.24 + return c > 2? findGetMethod(desc, inv) : findGetIndexMethod(inv); 2.25 case "setProp": 2.26 case "setElem": 2.27 - return c > 2 ? findSetMethod(desc) : findSetIndexMethod(); 2.28 + return c > 2? findSetMethod(desc, inv) : findSetIndexMethod(); 2.29 case "call": 2.30 return findCallMethod(desc); 2.31 default: 2.32 @@ -133,7 +134,10 @@ 2.33 } 2.34 } 2.35 2.36 - private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc) { 2.37 + private static GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final GuardedInvocation inv) { 2.38 + if (inv != null) { 2.39 + return inv; 2.40 + } 2.41 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 2.42 final MethodHandle getter = MH.insertArguments(JSOBJECT_GETMEMBER, 1, name); 2.43 return new GuardedInvocation(getter, IS_JSOBJECT_GUARD); 2.44 @@ -144,7 +148,10 @@ 2.45 return inv.replaceMethods(getter, inv.getGuard()); 2.46 } 2.47 2.48 - private static GuardedInvocation findSetMethod(final CallSiteDescriptor desc) { 2.49 + private static GuardedInvocation findSetMethod(final CallSiteDescriptor desc, final GuardedInvocation inv) { 2.50 + if (inv != null) { 2.51 + return inv; 2.52 + } 2.53 final MethodHandle getter = MH.insertArguments(JSOBJECT_SETMEMBER, 1, desc.getNameToken(2)); 2.54 return new GuardedInvocation(getter, IS_JSOBJECT_GUARD); 2.55 }