src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java

Print this page
rev 970 : 8058545: With strict mode, bean property assignment of a non-existent property should result in TypeError
Reviewed-by: hannesw, lagergren

+8058545: With strict mode, bean property assignment of a non-existent property should result in TypeError


 114             if(BeansLinker.isDynamicConstructor(self)) {
 115                 throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
 116             }
 117             if(BeansLinker.isDynamicMethod(self)) {
 118                 throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
 119             }
 120             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
 121         case "callMethod":
 122         case "getMethod":
 123             throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 124         case "getProp":
 125         case "getElem":
 126             if(NashornCallSiteDescriptor.isOptimistic(desc)) {
 127                 throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
 128             }
 129             if (desc.getOperand() != null) {
 130                 return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc);
 131             }
 132             return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc);
 133         case "setProp":
 134         case "setElem":




 135             if (desc.getOperand() != null) {
 136                 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc);
 137             }
 138             return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc);

 139         default:
 140             break;
 141         }
 142         throw new AssertionError("unknown call type " + desc);
 143     }
 144 
 145     @Override
 146     public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
 147         final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
 148         return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
 149     }
 150 
 151     /**
 152      * Main part of the implementation of {@link GuardingTypeConverterFactory#convertToType(Class, Class)} that doesn't
 153      * care about adapting the method signature; that's done by the invoking method. Returns conversion from Object to String/number/boolean (JS primitive types).
 154      * @param sourceType the source type
 155      * @param targetType the target type
 156      * @return a guarded invocation that converts from the source type to the target type.
 157      * @throws Exception if something goes wrong
 158      */




 114             if(BeansLinker.isDynamicConstructor(self)) {
 115                 throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
 116             }
 117             if(BeansLinker.isDynamicMethod(self)) {
 118                 throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
 119             }
 120             throw typeError("not.a.function", ScriptRuntime.safeToString(self));
 121         case "callMethod":
 122         case "getMethod":
 123             throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 124         case "getProp":
 125         case "getElem":
 126             if(NashornCallSiteDescriptor.isOptimistic(desc)) {
 127                 throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
 128             }
 129             if (desc.getOperand() != null) {
 130                 return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc);
 131             }
 132             return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc);
 133         case "setProp":
 134         case "setElem": {
 135             final boolean strict = NashornCallSiteDescriptor.isStrict(desc);
 136             if (strict) {
 137                 throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self));
 138             }
 139             if (desc.getOperand() != null) {
 140                 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc);
 141             }
 142             return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc);
 143         }
 144         default:
 145             break;
 146         }
 147         throw new AssertionError("unknown call type " + desc);
 148     }
 149 
 150     @Override
 151     public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
 152         final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
 153         return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
 154     }
 155 
 156     /**
 157      * Main part of the implementation of {@link GuardingTypeConverterFactory#convertToType(Class, Class)} that doesn't
 158      * care about adapting the method signature; that's done by the invoking method. Returns conversion from Object to String/number/boolean (JS primitive types).
 159      * @param sourceType the source type
 160      * @param targetType the target type
 161      * @return a guarded invocation that converts from the source type to the target type.
 162      * @throws Exception if something goes wrong
 163      */