8067420: BrowserJSObjectLinker should give priority to beans linker for property get/set

Reviewed-by: lagergren, attila, hannesw
This commit is contained in:
Athijegannathan Sundararajan 2014-12-15 16:30:45 +05:30
parent f6c045bef0
commit 05bf0c5a45
2 changed files with 20 additions and 13 deletions

View File

@ -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 @@ EOF, "text/html");
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);

View File

@ -118,20 +118,21 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker {
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:
@ -139,7 +140,10 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker {
}
}
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);
@ -150,7 +154,10 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker {
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);
}