< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.runtime.linker;
  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;


  30 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
  31 
  32 import java.lang.invoke.MethodHandle;
  33 import java.util.HashMap;
  34 import java.util.Map;
  35 import jdk.internal.dynalink.CallSiteDescriptor;
  36 import jdk.internal.dynalink.beans.BeansLinker;
  37 import jdk.internal.dynalink.linker.GuardedInvocation;
  38 import jdk.internal.dynalink.linker.GuardedTypeConversion;
  39 import jdk.internal.dynalink.linker.GuardingDynamicLinker;
  40 import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
  41 import jdk.internal.dynalink.linker.LinkRequest;
  42 import jdk.internal.dynalink.linker.LinkerServices;
  43 import jdk.internal.dynalink.support.Guards;
  44 import jdk.nashorn.internal.codegen.types.Type;
  45 import jdk.nashorn.internal.runtime.JSType;
  46 import jdk.nashorn.internal.runtime.ScriptRuntime;
  47 import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
  48 
  49 /**


  75             MH.dropArguments(MH.constant(Object.class, UNDEFINED), 0, Object.class);
  76     private static final MethodHandle EMPTY_ELEM_GETTER =
  77             MH.dropArguments(EMPTY_PROP_GETTER, 0, Object.class);
  78     private static final MethodHandle EMPTY_PROP_SETTER =
  79             MH.asType(EMPTY_ELEM_GETTER, EMPTY_ELEM_GETTER.type().changeReturnType(void.class));
  80     private static final MethodHandle EMPTY_ELEM_SETTER =
  81             MH.dropArguments(EMPTY_PROP_SETTER, 0, Object.class);
  82 
  83     private static GuardedInvocation linkBean(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
  84         final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor();
  85         final Object self = linkRequest.getReceiver();
  86         final String operator = desc.getFirstOperator();
  87         switch (operator) {
  88         case "new":
  89             if(BeansLinker.isDynamicConstructor(self)) {
  90                 throw typeError("no.constructor.matches.args", ScriptRuntime.safeToString(self));
  91             }
  92             if(BeansLinker.isDynamicMethod(self)) {
  93                 throw typeError("method.not.constructor", ScriptRuntime.safeToString(self));
  94             }
  95             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
  96         case "call":
  97             if(BeansLinker.isDynamicConstructor(self)) {
  98                 throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
  99             }
 100             if(BeansLinker.isDynamicMethod(self)) {
 101                 throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
 102             }
 103             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
 104         case "callMethod":
 105         case "getMethod":
 106             throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));



 107         case "getProp":
 108         case "getElem":
 109             if(NashornCallSiteDescriptor.isOptimistic(desc)) {
 110                 throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
 111             }
 112             if (desc.getOperand() != null) {
 113                 return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc);
 114             }
 115             return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc);
 116         case "setProp":
 117         case "setElem": {
 118             final boolean strict = NashornCallSiteDescriptor.isStrict(desc);
 119             if (strict) {
 120                 throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 121             }
 122             if (desc.getOperand() != null) {
 123                 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc);
 124             }
 125             return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc);
 126         }




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.runtime.linker;
  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  30 import static jdk.nashorn.internal.runtime.JSType.GET_UNDEFINED;
  31 import static jdk.nashorn.internal.runtime.JSType.TYPE_OBJECT_INDEX;
  32 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
  33 
  34 import java.lang.invoke.MethodHandle;
  35 import java.util.HashMap;
  36 import java.util.Map;
  37 import jdk.internal.dynalink.CallSiteDescriptor;
  38 import jdk.internal.dynalink.beans.BeansLinker;
  39 import jdk.internal.dynalink.linker.GuardedInvocation;
  40 import jdk.internal.dynalink.linker.GuardedTypeConversion;
  41 import jdk.internal.dynalink.linker.GuardingDynamicLinker;
  42 import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
  43 import jdk.internal.dynalink.linker.LinkRequest;
  44 import jdk.internal.dynalink.linker.LinkerServices;
  45 import jdk.internal.dynalink.support.Guards;
  46 import jdk.nashorn.internal.codegen.types.Type;
  47 import jdk.nashorn.internal.runtime.JSType;
  48 import jdk.nashorn.internal.runtime.ScriptRuntime;
  49 import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
  50 
  51 /**


  77             MH.dropArguments(MH.constant(Object.class, UNDEFINED), 0, Object.class);
  78     private static final MethodHandle EMPTY_ELEM_GETTER =
  79             MH.dropArguments(EMPTY_PROP_GETTER, 0, Object.class);
  80     private static final MethodHandle EMPTY_PROP_SETTER =
  81             MH.asType(EMPTY_ELEM_GETTER, EMPTY_ELEM_GETTER.type().changeReturnType(void.class));
  82     private static final MethodHandle EMPTY_ELEM_SETTER =
  83             MH.dropArguments(EMPTY_PROP_SETTER, 0, Object.class);
  84 
  85     private static GuardedInvocation linkBean(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
  86         final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor();
  87         final Object self = linkRequest.getReceiver();
  88         final String operator = desc.getFirstOperator();
  89         switch (operator) {
  90         case "new":
  91             if(BeansLinker.isDynamicConstructor(self)) {
  92                 throw typeError("no.constructor.matches.args", ScriptRuntime.safeToString(self));
  93             }
  94             if(BeansLinker.isDynamicMethod(self)) {
  95                 throw typeError("method.not.constructor", ScriptRuntime.safeToString(self));
  96             }
  97             throw typeError("not.a.function", desc.getFunctionErrorMessage(self));
  98         case "call":
  99             if(BeansLinker.isDynamicConstructor(self)) {
 100                 throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
 101             }
 102             if(BeansLinker.isDynamicMethod(self)) {
 103                 throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
 104             }
 105             throw typeError("not.a.function", desc.getFunctionErrorMessage(self));
 106         case "callMethod":

 107             throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 108         case "getMethod":
 109             // evaluate to undefined, later on Undefined will take care of throwing TypeError
 110             return getInvocation(MH.dropArguments(GET_UNDEFINED.get(TYPE_OBJECT_INDEX), 0, Object.class), self, linkerServices, desc);
 111         case "getProp":
 112         case "getElem":
 113             if(NashornCallSiteDescriptor.isOptimistic(desc)) {
 114                 throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
 115             }
 116             if (desc.getOperand() != null) {
 117                 return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc);
 118             }
 119             return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc);
 120         case "setProp":
 121         case "setElem": {
 122             final boolean strict = NashornCallSiteDescriptor.isStrict(desc);
 123             if (strict) {
 124                 throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 125             }
 126             if (desc.getOperand() != null) {
 127                 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc);
 128             }
 129             return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc);
 130         }


< prev index next >