Java Code Examples for jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#getFunctionDescription()

The following examples show how to use jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor#getFunctionDescription() . 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: Undefined.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example 2
Source File: Undefined.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example 3
Source File: Undefined.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example 4
Source File: Undefined.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}
 
Example 5
Source File: Undefined.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lookup the appropriate method for an invoke dynamic call.
 * @param desc The invoke dynamic callsite descriptor.
 * @return GuardedInvocation to be invoked at call site.
 */
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
    final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);

    switch (operator) {
    case "new":
    case "call": {
        final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
        final String msg = name != null? "not.a.function" : "cant.call.undefined";
        throw typeError(msg, name);
    }

    case "callMethod":
        throw lookupTypeError("cant.read.property.of.undefined", desc);
    // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
    // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
    // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
    // operation has an associated name or not.
    case "getProp":
    case "getElem":
    case "getMethod":
        if (desc.getNameTokenCount() < 3) {
            return findGetIndexMethod(desc);
        }
        return findGetMethod(desc);
    case "setProp":
    case "setElem":
        if (desc.getNameTokenCount() < 3) {
            return findSetIndexMethod(desc);
        }
        return findSetMethod(desc);
    default:
        break;
    }

    return null;
}