jdk.nashorn.internal.runtime.JSType Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.JSType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
 *
 * @param self self reference
 * @param arg argument to push
 * @return array after pushes
 */
@SpecializedFunction
public static double push(final Object self, final Object arg) {
    try {
        final ScriptObject sobj = (ScriptObject)self;
        final ArrayData arrayData = sobj.getArray();
        final long length = arrayData.length();
        if (bulkable(sobj) && length < JSType.MAX_UINT) {
            sobj.setArray(arrayData.push(true, arg));
            return length + 1;
        }

        long len = JSType.toUint32(sobj.getLength());
        sobj.set(len++, arg, CALLSITE_STRICT);
        sobj.set("length", len, CALLSITE_STRICT);
        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example #2
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.5 Array.prototype.join (separator)
 *
 * @param self      self reference
 * @param separator element separator
 * @return string representation after join
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String join(final Object self, final Object separator) {
    final StringBuilder    sb   = new StringBuilder();
    final Iterator<Object> iter = arrayLikeIterator(self, true);
    final String           sep  = separator == ScriptRuntime.UNDEFINED ? "," : JSType.toString(separator);

    while (iter.hasNext()) {
        final Object obj = iter.next();

        if (obj != null && obj != ScriptRuntime.UNDEFINED) {
            sb.append(JSType.toString(obj));
        }

        if (iter.hasNext()) {
            sb.append(sep);
        }
    }

    return sb.toString();
}
 
Example #3
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...)
 *
 * @param self self reference
 * @param args arguments to push
 * @return array length after pushes
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object push(final Object self, final Object... args) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;

        if (bulkable(sobj) && sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
            final ArrayData newData = sobj.getArray().push(true, args);
            sobj.setArray(newData);
            return newData.length();
        }

        long len = JSType.toUint32(sobj.getLength());
        for (final Object element : args) {
            sobj.set(len++, element, CALLSITE_STRICT);
        }
        sobj.set("length", len, CALLSITE_STRICT);

        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example #4
Source File: NativeObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.3.2 Object.getPrototypeOf ( O )
 *
 * @param  self self reference
 * @param  obj object to get prototype from
 * @return the prototype of an object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getPrototypeOf(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).getProto();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).getProto();
    } else {
        final JSType type = JSType.of(obj);
        if (type == JSType.OBJECT) {
            // host (Java) objects have null __proto__
            return null;
        }

        // must be some JS primitive
        throw notAnObject(obj);
    }
}
 
Example #5
Source File: NativeDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static double[] convertCtorArgs(final Object[] args) {
    final double[] d = new double[7];
    boolean nullReturn = false;

    // should not bailout on first NaN or infinite. Need to convert all
    // subsequent args for possible side-effects via valueOf/toString overrides
    // on argument objects.
    for (int i = 0; i < d.length; i++) {
        if (i < args.length) {
            final double darg = JSType.toNumber(args[i]);
            if (isNaN(darg) || isInfinite(darg)) {
                nullReturn = true;
            }

            d[i] = (long)darg;
        } else {
            d[i] = i == 2 ? 1 : 0; // day in month defaults to 1
        }
    }

    if (0 <= d[0] && d[0] <= 99) {
        d[0] += 1900;
    }

    return nullReturn? null : d;
}
 
Example #6
Source File: NativeDate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static double[] convertCtorArgs(final Object[] args) {
    final double[] d = new double[7];
    boolean nullReturn = false;

    // should not bailout on first NaN or infinite. Need to convert all
    // subsequent args for possible side-effects via valueOf/toString overrides
    // on argument objects.
    for (int i = 0; i < d.length; i++) {
        if (i < args.length) {
            final double darg = JSType.toNumber(args[i]);
            if (isNaN(darg) || isInfinite(darg)) {
                nullReturn = true;
            }

            d[i] = (long)darg;
        } else {
            d[i] = i == 2 ? 1 : 0; // day in month defaults to 1
        }
    }

    if (0 <= d[0] && d[0] <= 99) {
        d[0] += 1900;
    }

    return nullReturn? null : d;
}
 
Example #7
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
NativeArray(final long[] array) {
    this(ArrayData.allocate(array.length));

    ArrayData arrayData = this.getArray();
    Class<?> widest = int.class;

    for (int index = 0; index < array.length; index++) {
        final long value = array[index];

        if (widest == int.class && JSType.isRepresentableAsInt(value)) {
            arrayData = arrayData.set(index, (int) value, false);
        } else if (widest != Object.class && JSType.isRepresentableAsDouble(value)) {
            arrayData = arrayData.set(index, (double) value, false);
            widest = double.class;
        } else {
            arrayData = arrayData.set(index, (Object) value, false);
            widest = Object.class;
        }
    }

    this.setArray(arrayData);
}
 
Example #8
Source File: JSTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of JSType.toUint32(double)
 */
@Test
public void testToUint32() {
    assertEquals(JSType.toUint32(+0.0), 0);
    assertEquals(JSType.toUint32(-0.0), 0);
    assertEquals(JSType.toUint32(Double.NaN), 0);
    assertEquals(JSType.toUint32(Double.POSITIVE_INFINITY), 0);
    assertEquals(JSType.toUint32(Double.NEGATIVE_INFINITY), 0);
    assertEquals(JSType.toUint32(9223372036854775807.0d), 0);
    assertEquals(JSType.toUint32(-9223372036854775807.0d), 0);
    assertEquals(JSType.toUint32(1099511627776.0d), 0);
    assertEquals(JSType.toUint32(-1099511627776.0d), 0);
    assertEquals(JSType.toUint32(4294967295.0d), 4294967295l);
    assertEquals(JSType.toUint32(4294967296.0d), 0);
    assertEquals(JSType.toUint32(4294967297.0d), 1);
    assertEquals(JSType.toUint32(-4294967295.0d), 1);
    assertEquals(JSType.toUint32(-4294967296.0d), 0);
    assertEquals(JSType.toUint32(-4294967297.0d), 4294967295l);
    assertEquals(JSType.toUint32(4294967295.6d), 4294967295l);
    assertEquals(JSType.toUint32(4294967296.6d), 0);
    assertEquals(JSType.toUint32(4294967297.6d), 1);
    assertEquals(JSType.toUint32(-4294967295.6d), 1);
    assertEquals(JSType.toUint32(-4294967296.6d), 0);
    assertEquals(JSType.toUint32(-4294967297.6d), 4294967295l);
}
 
Example #9
Source File: JavaArgumentConverters.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static Number toNumber(final Object obj0) {
    // TODO - Order tests for performance.
    for (Object obj = obj0; ;) {
        if (obj == null) {
            return null;
        } else if (obj instanceof Number) {
            return (Number) obj;
        } else if (obj instanceof String) {
            return JSType.toNumber((String) obj);
        } else if (obj instanceof ConsString) {
            return JSType.toNumber(obj.toString());
        } else if (obj instanceof Boolean) {
            return (Boolean) obj ? 1 : +0.0;
        } else if (obj instanceof ScriptObject) {
            obj = JSType.toPrimitive(obj, Number.class);
            continue;
        } else if (obj == UNDEFINED) {
            return Double.NaN;
        }
        throw assertUnexpectedType(obj);
    }
}
 
Example #10
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
NativeArray(final long[] array) {
    this(ArrayData.allocate(array.length));

    ArrayData arrayData = this.getArray();
    Class<?> widest = int.class;

    for (int index = 0; index < array.length; index++) {
        final long value = array[index];

        if (widest == int.class && JSType.isRepresentableAsInt(value)) {
            arrayData = arrayData.set(index, (int) value, false);
        } else if (widest != Object.class && JSType.isRepresentableAsDouble(value)) {
            arrayData = arrayData.set(index, (double) value, false);
            widest = double.class;
        } else {
            arrayData = arrayData.set(index, (Object) value, false);
            widest = Object.class;
        }
    }

    this.setArray(arrayData);
}
 
Example #11
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
 *
 * @param self self reference
 * @param arg argument to push
 * @return array after pushes
 */
@SpecializedFunction
public static double push(final Object self, final Object arg) {
    try {
        final ScriptObject sobj = (ScriptObject)self;
        final ArrayData arrayData = sobj.getArray();
        final long length = arrayData.length();
        if (bulkable(sobj) && length < JSType.MAX_UINT) {
            sobj.setArray(arrayData.push(true, arg));
            return length + 1;
        }

        long len = JSType.toUint32(sobj.getLength());
        sobj.set(len++, arg, CALLSITE_STRICT);
        sobj.set("length", len, CALLSITE_STRICT);
        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example #12
Source File: JavaArgumentConverters.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static Number toNumber(final Object obj0) {
    // TODO - Order tests for performance.
    for (Object obj = obj0; ;) {
        if (obj == null) {
            return null;
        } else if (obj instanceof Number) {
            return (Number) obj;
        } else if (obj instanceof String) {
            return JSType.toNumber((String) obj);
        } else if (obj instanceof ConsString) {
            return JSType.toNumber(obj.toString());
        } else if (obj instanceof Boolean) {
            return (Boolean) obj ? 1 : +0.0;
        } else if (obj instanceof ScriptObject) {
            obj = JSType.toPrimitive(obj, Number.class);
            continue;
        } else if (obj == UNDEFINED) {
            return Double.NaN;
        }
        throw assertUnexpectedType(obj);
    }
}
 
Example #13
Source File: JSTypeTest.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of toString method, of class Runtime.
 */
@Test
public void testToString_Object() {
    assertEquals(JSType.toString(ScriptRuntime.UNDEFINED), "undefined");
    assertEquals(JSType.toString(null), "null");
    assertEquals(JSType.toString(Boolean.TRUE), "true");
    assertEquals(JSType.toString(Boolean.FALSE), "false");
    assertEquals(JSType.toString(""), "");
    assertEquals(JSType.toString("nashorn"), "nashorn");
    assertEquals(JSType.toString(Double.NaN), "NaN");
    assertEquals(JSType.toString(Double.POSITIVE_INFINITY), "Infinity");
    assertEquals(JSType.toString(Double.NEGATIVE_INFINITY), "-Infinity");
    assertEquals(JSType.toString(0.0), "0");
    // FIXME: add more number-to-string test cases
    // FIXME: add case for Object type (JSObject with getDefaultValue)
}
 
Example #14
Source File: JavaArgumentConverters.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static Double toDouble(final Object obj0) {
    // TODO - Order tests for performance.
    for (Object obj = obj0; ;) {
        if (obj == null) {
            return null;
        } else if (obj instanceof Double) {
            return (Double) obj;
        } else if (obj instanceof Number) {
            return ((Number)obj).doubleValue();
        } else if (obj instanceof String) {
            return JSType.toNumber((String) obj);
        } else if (obj instanceof ConsString) {
            return JSType.toNumber(obj.toString());
        } else if (obj instanceof Boolean) {
            return (Boolean) obj ? 1 : +0.0;
        } else if (obj instanceof ScriptObject) {
            obj = JSType.toPrimitive(obj, Number.class);
            continue;
        } else if (obj == UNDEFINED) {
            return Double.NaN;
        }
        throw assertUnexpectedType(obj);
    }
}
 
Example #15
Source File: NativeArray.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...)
 *
 * @param self self reference
 * @param args arguments to push
 * @return array after pushes
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object push(final Object self, final Object... args) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;

        if (bulkable(sobj)) {
            if (sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
                final ArrayData newData = sobj.getArray().push(true, args);
                sobj.setArray(newData);
                return newData.length();
            }
            //fallthru
        }

        long len = JSType.toUint32(sobj.getLength());
        for (final Object element : args) {
            sobj.set(len++, element, true);
        }
        sobj.set("length", len, true);

        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example #16
Source File: NativeURIError.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
NativeURIError(final Object msg, final Global global) {
    super(global.getURIErrorPrototype(), $nasgenmap$);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #17
Source File: NativeTypeError.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
NativeTypeError(final Object msg, final Global global) {
    super(global.getTypeErrorPrototype(), global.getTypeErrorMap());
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        delete(NativeError.MESSAGE, false);
    }
}
 
Example #18
Source File: NativeRegExpExecResult.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Length getter
 * @param self self reference
 * @return length property value
 */
@Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object length(final Object self) {
    if (self instanceof ScriptObject) {
        return (double) JSType.toUint32(((ScriptObject)self).getArray().length());
    }

    return 0;
}
 
Example #19
Source File: NativeArrayBuffer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param newObj is this invoked with new
 * @param self   self reference
 * @param args   arguments to constructor
 * @return new NativeArrayBuffer
 */
@Constructor(arity = 1)
public static NativeArrayBuffer constructor(final boolean newObj, final Object self, final Object... args) {
    if (!newObj) {
        throw typeError("constructor.requires.new", "ArrayBuffer");
    }

    if (args.length == 0) {
        return new NativeArrayBuffer(0);
    }

    return new NativeArrayBuffer(JSType.toInt32(args[0]));
}
 
Example #20
Source File: NativeDate.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.9.5.27 Date.prototype.setTime (time)
 *
 * @param self self reference
 * @param time time
 * @return time
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double setTime(final Object self, final Object time) {
    final NativeDate nd  = getNativeDate(self);
    final double     num = timeClip(JSType.toNumber(time));
    nd.setTime(num);
    return num;
}
 
Example #21
Source File: NativeURIError.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
NativeURIError(final Object msg, final Global global) {
    super(global.getURIErrorPrototype(), $nasgenmap$);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
    NativeError.initException(this);
}
 
Example #22
Source File: NativeString.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.15 String.prototype.substring (start, end)
 *
 * @param self  self reference
 * @param start start position of substring
 * @param end   end position of substring
 * @return substring given start and end indexes
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String substring(final Object self, final Object start, final Object end) {

    final String str = checkObjectToString(self);
    if (end == UNDEFINED) {
        return substring(str, JSType.toInteger(start));
    }
    return substring(str, JSType.toInteger(start), JSType.toInteger(end));
}
 
Example #23
Source File: ArrayLikeIterator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ArrayLikeIterator factory (reverse order)
 * @param object object over which to do reverse element iteration
 * @param includeUndefined should undefined elements be included in the iteration
 * @return iterator
 */
public static ArrayLikeIterator<Object> reverseArrayLikeIterator(final Object object, final boolean includeUndefined) {
    Object obj = object;

    if (ScriptObject.isArray(obj)) {
        return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined);
    }

    obj = JSType.toScriptObject(obj);
    if (obj instanceof ScriptObject) {
        return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined);
    }

    if (obj instanceof JSObject) {
        return new ReverseJSObjectIterator((JSObject)obj, includeUndefined);
    }

    if (obj instanceof List) {
        return new ReverseJavaListIterator((List<?>)obj, includeUndefined);
    }

    if (obj != null && obj.getClass().isArray()) {
        return new ReverseJavaArrayIterator(obj, includeUndefined);
    }

    return new EmptyArrayLikeIterator();
}
 
Example #24
Source File: NativeObject.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.2.1 , 15.2.1.1 new Object([value]) and Object([value])
 *
 * Constructor
 *
 * @param newObj is the new object instantiated with the new operator
 * @param self   self reference
 * @param value  value of object to be instantiated
 * @return the new NativeObject
 */
@Constructor
public static Object construct(final boolean newObj, final Object self, final Object value) {
    final JSType type = JSType.of(value);

    // Object(null), Object(undefined), Object() are same as "new Object()"

    if (newObj || (type == JSType.NULL || type == JSType.UNDEFINED)) {
        switch (type) {
        case BOOLEAN:
        case NUMBER:
        case STRING:
            return Global.toObject(value);
        case OBJECT:
        case FUNCTION:
            return value;
        case NULL:
        case UNDEFINED:
            // fall through..
        default:
            break;
        }

        return Global.newEmptyInstance();
    }

    return Global.toObject(value);
}
 
Example #25
Source File: NativeDate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - ECMA 15.9.3.1 new Date (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param isNew is this Date constructed with the new operator
 * @param self  self reference
 * @param args  arguments
 * @return new Date
 */
@Constructor(arity = 7)
public static Object construct(final boolean isNew, final Object self, final Object... args) {
    if (! isNew) {
        return toStringImpl(new NativeDate(), FORMAT_DATE_TIME);
    }

    NativeDate result;
    switch (args.length) {
    case 0:
        result = new NativeDate();
        break;

    case 1:
        double num;
        final Object arg = JSType.toPrimitive(args[0]);
        if (JSType.isString(arg)) {
            num = parseDateString(arg.toString());
        } else {
            num = timeClip(JSType.toNumber(args[0]));
        }
        result = new NativeDate(num);
        break;

    default:
        result = new NativeDate(0);
        final double[] d = convertCtorArgs(args);
        if (d == null) {
            result.setTime(Double.NaN);
        } else {
            final double time = timeClip(utc(makeDate(d), result.getTimeZone()));
            result.setTime(time);
        }
        break;
     }

     return result;
}
 
Example #26
Source File: NativeError.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private NativeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
}
 
Example #27
Source File: NativeError.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private NativeError(final Object msg, final ScriptObject proto, final PropertyMap map) {
    super(proto, map);
    if (msg != UNDEFINED) {
        this.instMessage = JSType.toString(msg);
    } else {
        this.delete(NativeError.MESSAGE, false);
    }
}
 
Example #28
Source File: NativeDataView.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 8-bit unsigned int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value byte value to set
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object setUint8(final Object self, final Object byteOffset, final Object value) {
    try {
        getBuffer(self).put(JSType.toInt32(byteOffset), (byte)JSType.toInt32(value));
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #29
Source File: ArrayLikeIterator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ArrayLikeIterator factory
 * @param object object over which to do reverse element iteration
 * @param includeUndefined should undefined elements be included in the iteration
 * @return iterator
 */
public static ArrayLikeIterator<Object> arrayLikeIterator(final Object object, final boolean includeUndefined) {
    Object obj = object;

    if (ScriptObject.isArray(obj)) {
        return new ScriptArrayIterator((ScriptObject) obj, includeUndefined);
    }

    obj = JSType.toScriptObject(obj);
    if (obj instanceof ScriptObject) {
        return new ScriptObjectIterator((ScriptObject)obj, includeUndefined);
    }

    if (obj instanceof JSObject) {
        return new JSObjectIterator((JSObject)obj, includeUndefined);
    }

    if (obj instanceof List) {
        return new JavaListIterator((List<?>)obj, includeUndefined);
    }

    if (obj != null && obj.getClass().isArray()) {
        return new JavaArrayIterator(obj, includeUndefined);
    }

    return new EmptyArrayLikeIterator();
}
 
Example #30
Source File: IntArrayData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ArrayData set(final int index, final long value, final boolean strict) {
    if (JSType.isRepresentableAsInt(value)) {
        array[index] = JSType.toInt32(value);
        setLength(Math.max(index + 1, length()));
        return this;
    }

    return convert(Long.class).set(index, value, strict);
}