< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java

Print this page




  80     public String getClassName() {
  81         return "Undefined";
  82     }
  83 
  84     @Override
  85     public String toString() {
  86         return "undefined";
  87     }
  88 
  89     /**
  90      * Lookup the appropriate method for an invoke dynamic call.
  91      * @param desc The invoke dynamic callsite descriptor.
  92      * @return GuardedInvocation to be invoked at call site.
  93      */
  94     public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
  95         final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
  96 
  97         switch (operator) {
  98         case "new":
  99         case "call": {
 100             final String name = desc.getNameTokenCount() > 2? desc.getNameToken(2) : null;
 101             final String msg = name != null? "cant.call.undefined.arg" : "cant.call.undefined";
 102             throw typeError(msg, name);
 103         }
 104 
 105         case "callMethod":
 106             throw lookupTypeError("cant.read.property.of.undefined", desc);
 107         // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
 108         // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
 109         // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
 110         // operation has an associated name or not.
 111         case "getProp":
 112         case "getElem":
 113         case "getMethod":
 114             if (desc.getNameTokenCount() < 3) {
 115                 return findGetIndexMethod(desc);
 116             }
 117             return findGetMethod(desc);
 118         case "setProp":
 119         case "setElem":
 120             if (desc.getNameTokenCount() < 3) {
 121                 return findSetIndexMethod(desc);




  80     public String getClassName() {
  81         return "Undefined";
  82     }
  83 
  84     @Override
  85     public String toString() {
  86         return "undefined";
  87     }
  88 
  89     /**
  90      * Lookup the appropriate method for an invoke dynamic call.
  91      * @param desc The invoke dynamic callsite descriptor.
  92      * @return GuardedInvocation to be invoked at call site.
  93      */
  94     public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
  95         final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
  96 
  97         switch (operator) {
  98         case "new":
  99         case "call": {
 100             final String name = NashornCallSiteDescriptor.getFunctionDescription(desc);
 101             final String msg = name != null? "not.a.function" : "cant.call.undefined";
 102             throw typeError(msg, name);
 103         }
 104 
 105         case "callMethod":
 106             throw lookupTypeError("cant.read.property.of.undefined", desc);
 107         // NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
 108         // emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
 109         // more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
 110         // operation has an associated name or not.
 111         case "getProp":
 112         case "getElem":
 113         case "getMethod":
 114             if (desc.getNameTokenCount() < 3) {
 115                 return findGetIndexMethod(desc);
 116             }
 117             return findGetMethod(desc);
 118         case "setProp":
 119         case "setElem":
 120             if (desc.getNameTokenCount() < 3) {
 121                 return findSetIndexMethod(desc);


< prev index next >