@Override protected Object invokeNoSuchProperty(final String name, final int programPoint) { final Object retval = createProperty(name); if (isValid(programPoint)) { throw new UnwarrantedOptimismException(retval, programPoint); } return retval; }
@Override public int getIntOptimistic(final int index, final int programPoint) { if (undefined.isSet(index)) { throw new UnwarrantedOptimismException(UNDEFINED, programPoint); } return super.getIntOptimistic(index, programPoint); }
@Override public long getLongOptimistic(final int index, final int programPoint) { if (undefined.isSet(index)) { throw new UnwarrantedOptimismException(UNDEFINED, programPoint); } return super.getLongOptimistic(index, programPoint); }
@Override public double getDoubleOptimistic(final int index, final int programPoint) { if (undefined.isSet(index)) { throw new UnwarrantedOptimismException(UNDEFINED, programPoint); } return super.getDoubleOptimistic(index, programPoint); }
void optimisticTypeToString(final StringBuilder sb, final boolean optimistic) { sb.append('{'); final Type type = getType(); final String desc = type == Type.UNDEFINED ? "U" : type.getDescriptor(); sb.append(desc.charAt(desc.length() - 1) == ';' ? "O" : desc); if (isOptimistic() && optimistic) { sb.append(OPT_IDENTIFIER); final int pp = ((Optimistic)this).getProgramPoint(); if (UnwarrantedOptimismException.isValid(pp)) { sb.append('_').append(pp); } } sb.append('}'); }
@Override protected Object invokeNoSuchProperty(final Object key, final boolean isScope, final int programPoint) { if (!(key instanceof String)) { return super.invokeNoSuchProperty(key, isScope, programPoint); } final Object retval = createProperty((String) key); if (isValid(programPoint)) { throw new UnwarrantedOptimismException(retval, programPoint); } return retval; }
@Override protected Object invokeNoSuchProperty(final String name, final boolean isScope, final int programPoint) { final Object retval = createProperty(name); if (isValid(programPoint)) { throw new UnwarrantedOptimismException(retval, programPoint); } return retval; }
private static GuardedInvocation linkBean(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor(); final Object self = linkRequest.getReceiver(); final String operator = desc.getFirstOperator(); switch (operator) { case "new": if(BeansLinker.isDynamicMethod(self)) { throw typeError("method.not.constructor", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", ScriptRuntime.safeToString(self)); case "call": if(BeansLinker.isDynamicConstructor(self)) { throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self)); } if(BeansLinker.isDynamicMethod(self)) { throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", ScriptRuntime.safeToString(self)); case "callMethod": case "getMethod": throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self)); case "getProp": case "getElem": if(NashornCallSiteDescriptor.isOptimistic(desc)) { throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc); case "setProp": case "setElem": { final boolean strict = NashornCallSiteDescriptor.isStrict(desc); if (strict) { throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); } default: break; } throw new AssertionError("unknown call type " + desc); }
@SuppressWarnings("unused") private static Object getDifferentUndefined(final int programPoint) { throw new UnwarrantedOptimismException(Undefined.getUndefined(), programPoint); }
@SuppressWarnings("unused") private static Object throwOptimisticUndefined(final int programPoint) { throw new UnwarrantedOptimismException(UNDEFINED, programPoint, Type.OBJECT); }
@Test public void unwarrantedOptimismExceptionNotSerializable() { tryToSerialize(new UnwarrantedOptimismException(1.0, 128)); }
private static GuardedInvocation linkBean(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor(); final Object self = linkRequest.getReceiver(); final String operator = desc.getFirstOperator(); switch (operator) { case "new": if(BeansLinker.isDynamicConstructor(self)) { throw typeError("no.constructor.matches.args", ScriptRuntime.safeToString(self)); } if(BeansLinker.isDynamicMethod(self)) { throw typeError("method.not.constructor", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", ScriptRuntime.safeToString(self)); case "call": if(BeansLinker.isDynamicConstructor(self)) { throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self)); } if(BeansLinker.isDynamicMethod(self)) { throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", ScriptRuntime.safeToString(self)); case "callMethod": case "getMethod": throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self)); case "getProp": case "getElem": if(NashornCallSiteDescriptor.isOptimistic(desc)) { throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc); case "setProp": case "setElem": { final boolean strict = NashornCallSiteDescriptor.isStrict(desc); if (strict) { throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); } default: break; } throw new AssertionError("unknown call type " + desc); }