@Override
  public Object call(ExecutionContext context) {
    Object self = context.getThisBinding();

    Arguments argsObj = (Arguments) context.resolve("arguments").getValue(context);
    int numArgs = (int) argsObj.get(context, "length");
    int paramsLen = getFormalParameters().length;

    Object[] args = new Object[numArgs < paramsLen ? paramsLen : numArgs];

    for (int i = 0; i < numArgs; ++i) {
      Object v = argsObj.get(context, "" + i);
      if (v instanceof Reference) {
        if (((Reference) v).isUnresolvableReference()) {
          v = Types.UNDEFINED;
        } else {
          v = ((Reference) v).getValue(context);
        }
      }
      args[i] = v;
    }

    for (int i = numArgs; i < paramsLen; ++i) {
      args[i] = Types.UNDEFINED;
    }

    return call(context, self, args);
  }
Beispiel #2
0
  @Override
  public Object call(ExecutionContext context, Object self, Object... args) {
    Arguments argsObj = (Arguments) context.resolve("arguments").getValue(context);
    int numArgs = (int) argsObj.get(context, "length");

    if (self != Types.UNDEFINED && self != Types.NULL) {
      // Constructor
      String value = "";
      if (numArgs != 0) {
        value = Types.toString(context, args[0]);
      }
      PrimitiveDynObject primSelf = (PrimitiveDynObject) self;
      primSelf.setPrimitiveValue(value);
      return primSelf;
    } else {
      // As function
      if (numArgs == 0) {
        return "";
      }
      return Types.toString(context, args[0]);
    }
  }
Beispiel #3
0
  @Override
  public Object call(ExecutionContext context, Object self, Object... args) {
    Number number = 0L;
    Arguments argsObj = (Arguments) context.resolve("arguments").getValue(context);
    int numArgs = (int) argsObj.get(context, "length");

    if (numArgs != 0) {
      number = Types.toNumber(context, args[0]);
    }
    if (self == Types.UNDEFINED || self == Types.NULL) {
      // called as a function
      return number;
    } else {
      // called as a ctor
      PrimitiveDynObject numberObject = (PrimitiveDynObject) self;
      if (numArgs == 0) {
        number = 0L;
      }
      numberObject.setPrimitiveValue(number);
      return numberObject;
    }
  }