diff options
Diffstat (limited to 'src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java')
-rw-r--r-- | src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java b/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java index d2f23e82..3bc11499 100644 --- a/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java +++ b/src/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java @@ -25,11 +25,13 @@ package jdk.nashorn.internal.runtime.linker; +import static jdk.nashorn.internal.runtime.JSType.isString; +import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_CALL; import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_GETMEMBER; import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_GETSLOT; import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_SETMEMBER; import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_SETSLOT; -import static jdk.nashorn.internal.runtime.linker.BrowserJSObjectLinker.JSObjectHandles.JSOBJECT_CALL; + import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import jdk.internal.dynalink.CallSiteDescriptor; @@ -97,9 +99,10 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker { return null; } - final GuardedInvocation inv; + GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); + inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else { throw new AssertionError(); // Should never reach here. } @@ -110,20 +113,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: @@ -131,7 +135,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); @@ -142,7 +149,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); } @@ -170,12 +180,12 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker { if (index > -1) { return JSOBJECT_GETSLOT.invokeExact(jsobj, index); } - } else if (key instanceof String) { - final String name = (String)key; + } else if (isString(key)) { + final String name = key.toString(); if (name.indexOf('(') != -1) { - return fallback.invokeExact(jsobj, key); + return fallback.invokeExact(jsobj, (Object) name); } - return JSOBJECT_GETMEMBER.invokeExact(jsobj, (String)key); + return JSOBJECT_GETMEMBER.invokeExact(jsobj, name); } return null; } @@ -186,8 +196,8 @@ final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker { JSOBJECT_SETSLOT.invokeExact(jsobj, (int)key, value); } else if (key instanceof Number) { JSOBJECT_SETSLOT.invokeExact(jsobj, getIndex((Number)key), value); - } else if (key instanceof String) { - JSOBJECT_SETMEMBER.invokeExact(jsobj, (String)key, value); + } else if (isString(key)) { + JSOBJECT_SETMEMBER.invokeExact(jsobj, key.toString(), value); } } |