MCPcopy Create free account
hub / github.com/mozilla/rhino / put

Method put

rhino/src/main/java/org/mozilla/javascript/JavaMembers.java:145–194  ·  view source on GitHub ↗
(
            Scriptable obj,
            VarScope scope,
            String name,
            Object javaObject,
            Object value,
            boolean isStatic)

Source from the content-addressed store, hash-verified

143 }
144
145 void put(
146 Scriptable obj,
147 VarScope scope,
148 String name,
149 Object javaObject,
150 Object value,
151 boolean isStatic) {
152 Map<String, Object> ht = isStatic ? staticMembers : members;
153 Object member = ht.get(name);
154 if (!isStatic && member == null) {
155 // Try to get static member from instance (LC3)
156 member = staticMembers.get(name);
157 }
158 if (member == null) throw reportMemberNotFound(name);
159 if (member instanceof ExecutableOverload.WithField) {
160 var withField = (ExecutableOverload.WithField) member;
161 member = withField.field;
162 }
163
164 // Is this a bean property "set"?
165 if (member instanceof BeanProperty) {
166 BeanProperty bp = (BeanProperty) member;
167 if (bp.setter == null) {
168 throw reportMemberNotFound(name);
169 }
170 bp.setter.call(Context.getContext(), scope, obj, new Object[] {value});
171 } else if (member instanceof NativeJavaField) {
172 var field = (NativeJavaField) member;
173 var type = field.type();
174 if (obj instanceof NativeJavaObject) {
175 type =
176 TypeInfoFactory.GLOBAL.consolidateType(
177 type, ((NativeJavaObject) obj).staticType);
178 }
179 try {
180 field.set(javaObject, Context.jsToJava(value, type));
181 } catch (IllegalAccessException accessEx) {
182 throw Context.throwAsScriptRuntimeEx(accessEx);
183 } catch (IllegalArgumentException argEx) {
184 throw Context.reportRuntimeErrorById(
185 "msg.java.internal.field.type",
186 value.getClass().getName(),
187 field,
188 javaObject.getClass().getName());
189 }
190 } else {
191 String str = (member == null) ? "msg.java.internal.private" : "msg.java.method.assign";
192 throw Context.reportRuntimeErrorById(str, name);
193 }
194 }
195
196 Object[] getIds(boolean isStatic) {
197 Map<String, Object> map = isStatic ? staticMembers : members;

Callers

nothing calls this directly

Calls 12

reportMemberNotFoundMethod · 0.95
getContextMethod · 0.95
jsToJavaMethod · 0.95
typeMethod · 0.80
consolidateTypeMethod · 0.80
getClassMethod · 0.80
getMethod · 0.65
callMethod · 0.65
getNameMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected