69 assert isExpectedObject(self) : "Couldn't link " + linkRequest.getCallSiteDescriptor() + " for " + self.getClass().getName();
70
71 return linkBean(linkRequest, linkerServices);
72 }
73
74 private static final MethodHandle EMPTY_PROP_GETTER =
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.isDynamicMethod(self)) {
90 throw typeError("method.not.constructor", ScriptRuntime.safeToString(self));
91 }
92 throw typeError("not.a.function", ScriptRuntime.safeToString(self));
93 case "call":
94 if(BeansLinker.isDynamicConstructor(self)) {
95 throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self));
96 }
97 if(BeansLinker.isDynamicMethod(self)) {
98 throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
99 }
100 throw typeError("not.a.function", ScriptRuntime.safeToString(self));
101 case "callMethod":
102 case "getMethod":
103 throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
104 case "getProp":
105 case "getElem":
106 if(NashornCallSiteDescriptor.isOptimistic(desc)) {
107 throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
108 }
|
69 assert isExpectedObject(self) : "Couldn't link " + linkRequest.getCallSiteDescriptor() + " for " + self.getClass().getName();
70
71 return linkBean(linkRequest, linkerServices);
72 }
73
74 private static final MethodHandle EMPTY_PROP_GETTER =
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 }
|