Beispiel #1
0
 @Override
 public Object getDefaultValue(Class<?> hint) {
   if (hint == ScriptRuntime.FunctionClass) return this;
   Object rval;
   Class<?> type;
   try {
     rval = field.get(javaObject);
     type = field.getType();
   } catch (IllegalAccessException accEx) {
     throw Context.reportRuntimeError1("msg.java.internal.private", field.getName());
   }
   Context cx = Context.getContext();
   rval = cx.getWrapFactory().wrap(cx, this, rval, type);
   if (rval instanceof Scriptable) {
     rval = ((Scriptable) rval).getDefaultValue(hint);
   }
   return rval;
 }
Beispiel #2
0
 private static Object doCall(
     Context cx,
     Scriptable scope,
     Scriptable thisObj,
     Function f,
     Object[] args,
     long argsToWrap) {
   // Wrap the rest of objects
   for (int i = 0; i != args.length; ++i) {
     if (0 != (argsToWrap & (1 << i))) {
       Object arg = args[i];
       if (!(arg instanceof Scriptable)) {
         args[i] = cx.getWrapFactory().wrap(cx, scope, arg, null);
       }
     }
   }
   return f.call(cx, scope, thisObj, args);
 }
Beispiel #3
0
 Object get(Scriptable scope, String name, Object javaObject, boolean isStatic) {
   Map<String, Object> ht = isStatic ? staticMembers : members;
   Object member = ht.get(name);
   if (!isStatic && member == null) {
     // Try to get static member from instance (LC3)
     member = staticMembers.get(name);
   }
   if (member == null) {
     member =
         this.getExplicitFunction(
             scope, name,
             javaObject, isStatic);
     if (member == null) return Scriptable.NOT_FOUND;
   }
   if (member instanceof Scriptable) {
     return member;
   }
   Context cx = Context.getContext();
   Object rval;
   Class<?> type;
   try {
     if (member instanceof BeanProperty) {
       BeanProperty bp = (BeanProperty) member;
       if (bp.getter == null) return Scriptable.NOT_FOUND;
       rval = bp.getter.invoke(javaObject, Context.emptyArgs);
       type = bp.getter.method().getReturnType();
     } else {
       Field field = (Field) member;
       rval = field.get(isStatic ? null : javaObject);
       type = field.getType();
     }
   } catch (Exception ex) {
     throw Context.throwAsScriptRuntimeEx(ex);
   }
   // Need to wrap the object before we return it.
   scope = ScriptableObject.getTopLevelScope(scope);
   return cx.getWrapFactory().wrap(cx, scope, rval, type);
 }