Java Code Examples for jdk.internal.dynalink.linker.GuardedInvocation#filterArguments()

The following examples show how to use jdk.internal.dynalink.linker.GuardedInvocation#filterArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NashornBeansLinker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final String name = getFunctionalInterfaceMethodName(self.getClass());
        if (name != null) {
            final MethodType callType = desc.getMethodType();
            // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name>
            final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(),
                    "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2),
                    NashornCallSiteDescriptor.getFlags(desc));
            final GuardedInvocation gi = getGuardedInvocation(beansLinker,
                    linkRequest.replaceArguments(newDesc, linkRequest.getArguments()),
                    new NashornBeansLinkerServices(linkerServices));

            // drop 'thiz' passed from the script.
            return gi.replaceMethods(
                MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)),
                gi.getGuard());
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
Example 2
Source File: NashornBeansLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final Method m = getFunctionalInterfaceMethod(self.getClass());
        if (m != null) {
            final MethodType callType = desc.getMethodType();
            // 'callee' and 'thiz' passed from script + actual arguments
            if (callType.parameterCount() != m.getParameterCount() + 2) {
                throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
            }
            return new GuardedInvocation(
                    // drop 'thiz' passed from the script.
                    MH.dropArguments(linkerServices.filterInternalObjects(desc.getLookup().unreflect(m)), 1,
                            callType.parameterType(1)), Guards.getInstanceOfGuard(
                                    m.getDeclaringClass())).asTypeSafeReturn(
                                            new NashornBeansLinkerServices(linkerServices), callType);
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
Example 3
Source File: NashornBeansLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final String name = getFunctionalInterfaceMethodName(self.getClass());
        if (name != null) {
            final MethodType callType = desc.getMethodType();
            // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name>
            final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(),
                    "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2),
                    NashornCallSiteDescriptor.getFlags(desc));
            final GuardedInvocation gi = getGuardedInvocation(beansLinker,
                    linkRequest.replaceArguments(newDesc, linkRequest.getArguments()),
                    new NashornBeansLinkerServices(linkerServices));

            // drop 'thiz' passed from the script.
            return gi.replaceMethods(
                MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)),
                gi.getGuard());
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
Example 4
Source File: NashornBeansLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final String name = getFunctionalInterfaceMethodName(self.getClass());
        if (name != null) {
            final MethodType callType = desc.getMethodType();
            // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name>
            final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(),
                    "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2),
                    NashornCallSiteDescriptor.getFlags(desc));
            final GuardedInvocation gi = getGuardedInvocation(beansLinker,
                    linkRequest.replaceArguments(newDesc, linkRequest.getArguments()),
                    new NashornBeansLinkerServices(linkerServices));

            // drop 'thiz' passed from the script.
            return gi.replaceMethods(
                MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)),
                gi.getGuard());
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
Example 5
Source File: NashornBeansLinker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final String name = getFunctionalInterfaceMethodName(self.getClass());
        if (name != null) {
            final MethodType callType = desc.getMethodType();
            // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name>
            final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(),
                    "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2),
                    NashornCallSiteDescriptor.getFlags(desc));
            final GuardedInvocation gi = getGuardedInvocation(beansLinker,
                    linkRequest.replaceArguments(newDesc, linkRequest.getArguments()),
                    new NashornBeansLinkerServices(linkerServices));

            // drop 'thiz' passed from the script.
            return gi.replaceMethods(
                MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)),
                gi.getGuard());
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
Example 6
Source File: NashornBeansLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final String name = getFunctionalInterfaceMethodName(self.getClass());
        if (name != null) {
            final MethodType callType = desc.getMethodType();
            // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name>
            final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(),
                    "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2),
                    NashornCallSiteDescriptor.getFlags(desc));
            final GuardedInvocation gi = getGuardedInvocation(beansLinker,
                    linkRequest.replaceArguments(newDesc, linkRequest.getArguments()),
                    new NashornBeansLinkerServices(linkerServices));

            // drop 'thiz' passed from the script.
            return gi.replaceMethods(
                MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)),
                gi.getGuard());
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}