コード例 #1
0
  /** Execute the static function */
  ESBase execute() throws Throwable {
    Global resin = (Global) prototype;

    try {
      Call call = resin.getCall();
      call.caller = call;
      call.setArg(0, this);
      call.top = 1;

      call.scopeLength = 1;
      call.scope[0] = this;
      call.global = this;

      ESBase value = null;

      try {
        value = call(0, call, 0);
      } finally {
        resin.freeCall(call);
      }

      return value;
    } catch (ESException e) {
      throw e;
    } catch (Throwable e) {
      throw new ESWrapperException(e);
    }
  }
コード例 #2
0
  /** XXX: not right */
  public ESBase toPrimitive(int hint) throws Throwable {
    Global resin = Global.getGlobalProto();
    Call eval = resin.getCall();
    eval.global = resin.getGlobal();

    try {
      ESBase fun = hasProperty(hint == STRING ? TO_STRING : VALUE_OF);

      if (fun instanceof ESClosure || fun instanceof Native) {
        eval.stack[0] = this;
        eval.top = 1;
        ESBase value = fun.call(eval, 0);

        if (value instanceof ESBase && !(value instanceof ESObject)) return value;
      }

      fun = hasProperty(hint == STRING ? VALUE_OF : TO_STRING);

      if (fun instanceof ESClosure || fun instanceof Native) {
        eval.stack[0] = this;
        eval.top = 1;
        ESBase value = fun.call(eval, 0);

        if (value instanceof ESBase && !(value instanceof ESObject)) return value;
      }

      throw new ESException("cannot convert object to primitive type");
    } finally {
      resin.freeCall(eval);
    }
  }
コード例 #3
0
ファイル: NativeArray.java プロジェクト: dlitz/resin
  private int compare(ESBase cmp, ESBase a, ESBase b) throws Throwable {
    if (a == b) return 0;
    else if (a == esUndefined) return 1;
    else if (b == esUndefined) return -1;
    else if (a == esNull) return 1;
    else if (b == esNull) return -1;
    else if (cmp != null) {
      // Call eval = new Call(ESGlobal.getGlobalProto(), false);
      Global resin = Global.getGlobalProto();
      Call eval = resin.getCall();

      eval.stack[0] = esNull;
      eval.stack[1] = a;
      eval.stack[2] = b;
      eval.top = 1;

      int result = cmp.call(eval, 2).toInt32();

      resin.freeCall(eval);

      return result;
    } else {
      String sa = a.toString();
      String sb = b.toString();

      return sa.compareTo(sb);
    }
  }