Ejemplo n.º 1
0
  @Override
  public Object call(ExecutionContext context, Object self, Object... args) {
    JSObject o = Types.toObject(context, self);
    Object tv = Types.toPrimitive(context, o, "Number");

    if (tv instanceof Number) {
      if (Double.isInfinite(((Number) tv).doubleValue())) {
        return Types.NULL;
      }
    }

    Object toISO = o.get(context, "toISOString");
    if (!(toISO instanceof JSFunction)) {
      throw new ThrowException(context, context.createTypeError("toISOString must be a function"));
    }

    return context.call((JSFunction) toISO, o);
  }
Ejemplo n.º 2
0
  protected Object primitiveGet(ExecutionContext context, JSObject o, String name) {
    // 8.7.1 primitive [[Get]]
    Object d = o.getProperty(context, name, false);
    if (d == Types.UNDEFINED) {
      return Types.UNDEFINED;
    }

    PropertyDescriptor desc = (PropertyDescriptor) d;
    if (desc.isDataDescriptor()) {
      Object value = desc.getValue();
      if (value == null) {
        value = Types.UNDEFINED;
      }
      return value;
    }

    Object getter = desc.getGetter();

    if (getter == Types.UNDEFINED) {
      return Types.UNDEFINED;
    }

    return context.call((JSFunction) getter, o);
  }