124 final boolean strict = NashornCallSiteDescriptor.isStrict(desc); 125 if (strict) { 126 throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); 127 } 128 if (NashornCallSiteDescriptor.getOperand(desc) != null) { 129 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); 130 } 131 return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); 132 default: 133 throw new AssertionError("unknown call type " + desc); 134 } 135 } 136 137 @Override 138 public GuardedInvocation convertToType(final Class<?> sourceType, final Class<?> targetType, final Supplier<MethodHandles.Lookup> lookupSupplier) throws Exception { 139 final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType); 140 return gi == null ? null : gi.asType(MH.type(targetType, sourceType)); 141 } 142 143 /** 144 * Main part of the implementation of {@link GuardingTypeConverterFactory#convertToType(Class, Class)} that doesn't 145 * care about adapting the method signature; that's done by the invoking method. Returns conversion from Object to String/number/boolean (JS primitive types). 146 * @param sourceType the source type 147 * @param targetType the target type 148 * @return a guarded invocation that converts from the source type to the target type. 149 * @throws Exception if something goes wrong 150 */ 151 private static GuardedInvocation convertToTypeNoCast(final Class<?> sourceType, final Class<?> targetType) throws Exception { 152 final MethodHandle mh = CONVERTERS.get(targetType); 153 if (mh != null) { 154 return new GuardedInvocation(mh); 155 } 156 157 return null; 158 } 159 160 private static GuardedInvocation getInvocation(final MethodHandle handle, final Object self, final LinkerServices linkerServices, final CallSiteDescriptor desc) { 161 return Bootstrap.asTypeSafeReturn(new GuardedInvocation(handle, Guards.getClassGuard(self.getClass())), linkerServices, desc); 162 } 163 164 // Used solely in an assertion to figure out if the object we get here is something we in fact expect. Objects 165 // linked by NashornLinker should never reach here. | 124 final boolean strict = NashornCallSiteDescriptor.isStrict(desc); 125 if (strict) { 126 throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); 127 } 128 if (NashornCallSiteDescriptor.getOperand(desc) != null) { 129 return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); 130 } 131 return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); 132 default: 133 throw new AssertionError("unknown call type " + desc); 134 } 135 } 136 137 @Override 138 public GuardedInvocation convertToType(final Class<?> sourceType, final Class<?> targetType, final Supplier<MethodHandles.Lookup> lookupSupplier) throws Exception { 139 final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType); 140 return gi == null ? null : gi.asType(MH.type(targetType, sourceType)); 141 } 142 143 /** 144 * Main part of the implementation of {@link GuardingTypeConverterFactory#convertToType} that doesn't 145 * care about adapting the method signature; that's done by the invoking method. Returns conversion 146 * from Object to String/number/boolean (JS primitive types). 147 * @param sourceType the source type 148 * @param targetType the target type 149 * @return a guarded invocation that converts from the source type to the target type. 150 * @throws Exception if something goes wrong 151 */ 152 private static GuardedInvocation convertToTypeNoCast(final Class<?> sourceType, final Class<?> targetType) throws Exception { 153 final MethodHandle mh = CONVERTERS.get(targetType); 154 if (mh != null) { 155 return new GuardedInvocation(mh); 156 } 157 158 return null; 159 } 160 161 private static GuardedInvocation getInvocation(final MethodHandle handle, final Object self, final LinkerServices linkerServices, final CallSiteDescriptor desc) { 162 return Bootstrap.asTypeSafeReturn(new GuardedInvocation(handle, Guards.getClassGuard(self.getClass())), linkerServices, desc); 163 } 164 165 // Used solely in an assertion to figure out if the object we get here is something we in fact expect. Objects 166 // linked by NashornLinker should never reach here. |