コード例 #1
0
ファイル: BuiltinNumber.java プロジェクト: juniorvicios/dynjs
 protected static void defineReadOnlyFunction(
     final JSObject on, final GlobalObject globalObject, String name, final Object value) {
   PropertyDescriptor desc = new PropertyDescriptor();
   desc.set(Names.VALUE, value);
   desc.set(Names.WRITABLE, false);
   desc.set(Names.ENUMERABLE, false);
   desc.set(Names.CONFIGURABLE, false);
   on.defineOwnProperty(null, name, desc, false);
 }
コード例 #2
0
ファイル: Slice.java プロジェクト: Joe8Bit/dynjs
  @Override
  public Object call(ExecutionContext context, Object self, Object... args) {
    // 15.4.4.10
    JSObject o = Types.toObject(context, self);

    JSObject a = BuiltinArray.newArray(context);
    long len = Types.toUint32(context, o.get(context, "length"));

    long relativeStart = Types.toInteger(context, args[0]);
    long k = Math.min(relativeStart, len);

    if (relativeStart < 0) {
      k = Math.max(len + relativeStart, 0);
    }

    long relativeEnd = len;
    if (args[1] != Types.UNDEFINED) {
      relativeEnd = Types.toInteger(context, args[1]);
    }

    long finalPos = Math.min(relativeEnd, len);

    if (relativeEnd < 0) {
      finalPos = Math.max(len + relativeEnd, 0);
    }

    long n = 0;

    while (k < finalPos) {
      boolean kPresent = o.hasProperty(context, "" + k);
      if (kPresent) {
        final Object kValue = o.get(context, "" + k);
        a.defineOwnProperty(
            context,
            "" + n,
            PropertyDescriptor.newDataPropertyDescriptor(kValue, true, true, true),
            false);
      }
      ++k;
      ++n;
    }

    return a;
  }
コード例 #3
0
  @Override
  public Object interpret(ExecutionContext context) {
    DynArray array = BuiltinArray.newArray(context);

    int numElements = this.exprs.size();
    int len = 0;
    for (int i = 0; i < numElements; ++i) {
      Expression each = this.exprs.get(i);
      Object value = null;
      if (each != null) {
        value = getValue(this.exprGets.get(i), context, each.interpret(context));
        array.defineOwnProperty(
            context,
            "" + i,
            PropertyDescriptor.newPropertyDescriptorForObjectInitializer(value),
            false);
      }
      ++len;
    }
    array.put(context, "length", (long) len, true);

    return (array);
  }