1 package sun.jvm.hotspot.utilities.soql.wrapper;
   2 
   3 import java.lang.reflect.InvocationTargetException;
   4 import java.lang.reflect.Method;
   5 import jdk.nashorn.api.scripting.AbstractJSObject;
   6 
   7 
   8 public class JSObjectMethodWrapper extends AbstractJSObject{
   9 
  10   private final Object receiver;
  11 
  12   private final Method method;
  13 
  14   public JSObjectMethodWrapper(Object receiver, Method method){
  15     this.receiver = receiver;
  16     this.method = method;
  17   }
  18 
  19   /**
  20    * Return result of this method object.
  21    */
  22   @Override
  23   public Object call(Object thiz, Object... args){
  24     Object result;
  25 
  26     try{
  27       result = method.invoke(receiver, args);
  28     } catch(IllegalAccessException | InvocationTargetException e){
  29       throw new RuntimeException(e);
  30     }
  31 
  32     return new JSObjectInstanceWrapper(result);
  33   }
  34 
  35   @Override
  36   public boolean isFunction(){
  37     return true;
  38   }
  39 
  40 }