Java Code Examples for jdk.nashorn.internal.runtime.JSType#toInt32()

The following examples show how to use jdk.nashorn.internal.runtime.JSType#toInt32() . 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: LengthNotWritableFilter.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getInt(final int index) {
    if (index >= length()) {
        return JSType.toInt32(get(index));
    }
    return underlying.getInt(index);
}
 
Example 2
Source File: SparseArrayData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getInt(final int index) {
    if (index >= 0 && index < maxDenseLength) {
        return underlying.getInt(index);
    }
    return JSType.toInt32(sparseMap.get(indexToKey(index)));
}
 
Example 3
Source File: NativeDebug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example 4
Source File: SparseArrayData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getInt(final int index) {
    if (index >= 0 && index < maxDenseLength) {
        return underlying.getInt(index);
    }
    return JSType.toInt32(sparseMap.get(indexToKey(index)));
}
 
Example 5
Source File: NativeArrayBuffer.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object slice(final Object self, final Object begin0, final Object end0) {
    final NativeArrayBuffer arrayBuffer = (NativeArrayBuffer)self;
    int begin = JSType.toInt32(begin0);
    int end = end0 != ScriptRuntime.UNDEFINED ? JSType.toInt32(end0) : arrayBuffer.getByteLength();
    begin = adjustIndex(begin, arrayBuffer.getByteLength());
    end = adjustIndex(end, arrayBuffer.getByteLength());
    return new NativeArrayBuffer((NativeArrayBuffer) self, begin, Math.max(end, begin));
}
 
Example 6
Source File: SparseArrayData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getInt(final int index) {
    if (index >= 0 && index < maxDenseLength) {
        return underlying.getInt(index);
    }
    return JSType.toInt32(sparseMap.get(indexToKey(index)));
}
 
Example 7
Source File: NativeDebug.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example 8
Source File: NativeDebug.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expands the event queue capacity, or truncates if capacity is lower than
 * current capacity. Then only the newest entries are kept
 * @param self self reference
 * @param newCapacity new capacity
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void expandEventQueueCapacity(final Object self, final Object newCapacity) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int nc = JSType.toInt32(newCapacity);
    while (q.size() > nc) {
        q.removeFirst();
    }
    setEventQueueCapacity(self, nc);
}
 
Example 9
Source File: NativeDebug.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example 10
Source File: NativeArrayBuffer.java    From openjdk-jdk8u 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 11
Source File: NativeString.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getInt(final double key) {
    return JSType.toInt32(get(key));
}
 
Example 12
Source File: ObjectArrayData.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getInt(final int index) {
    return JSType.toInt32(array[index]);
}
 
Example 13
Source File: NativeDataView.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example 14
Source File: NativeString.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getInt(final double key) {
    return JSType.toInt32(get(key));
}
 
Example 15
Source File: NativeDataView.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example 16
Source File: NativeDataView.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example 17
Source File: NativeDataView.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new DataView object using the passed ArrayBuffer for its
 * storage. Optional byteOffset and byteLength can be used to limit the
 * section of the buffer referenced. The byteOffset indicates the offset in
 * bytes from the start of the ArrayBuffer, and the byteLength is the number
 * of bytes from the offset that this DataView will reference. If both
 * byteOffset and byteLength are omitted, the DataView spans the entire
 * ArrayBuffer range. If the byteLength is omitted, the DataView extends from
 * the given byteOffset until the end of the ArrayBuffer.
 *
 * If the given byteOffset and byteLength references an area beyond the end
 * of the ArrayBuffer an exception is raised.

 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param args   arguments to the constructor
 * @return newly constructed DataView object
 */
@Constructor(arity = 1)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object... args) {
    if (args.length == 0 || !(args[0] instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }

    final NativeArrayBuffer arrBuf = (NativeArrayBuffer)args[0];
    switch (args.length) {
    case 1:
        return new NativeDataView(arrBuf);
    case 2:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]));
    default:
        return new NativeDataView(arrBuf, JSType.toInt32(args[1]), JSType.toInt32(args[2]));
    }
}
 
Example 18
Source File: ObjectArrayData.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getInt(final int index) {
    return JSType.toInt32(array[index]);
}
 
Example 19
Source File: LiteralNode.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Fetch int32 value of node.
 *
 * @return Int32 value of node.
 */
public int getInt32() {
    return JSType.toInt32(value);
}
 
Example 20
Source File: LiteralNode.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Fetch int32 value of node.
 *
 * @return Int32 value of node.
 */
public int getInt32() {
    return JSType.toInt32(value);
}