Java Code Examples for org.mozilla.javascript.ScriptRuntime#toBoolean()

The following examples show how to use org.mozilla.javascript.ScriptRuntime#toBoolean() . 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: NativeDataView.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private Object js_getInt(int bytes, boolean signed, Object[] args)
{
    checkOffset(args, 0);

    int pos = ScriptRuntime.toInt32(args[0]);
    rangeCheck(pos, bytes);

    boolean littleEndian =
        (isArg(args, 1) && (bytes > 1) && ScriptRuntime.toBoolean(args[1]));

    switch (bytes) {
    case 1:
        return (signed ? ByteIo.readInt8(arrayBuffer.buffer, offset + pos) :
                         ByteIo.readUint8(arrayBuffer.buffer, offset + pos));
    case 2:
        return (signed ? ByteIo.readInt16(arrayBuffer.buffer, offset + pos, littleEndian) :
                         ByteIo.readUint16(arrayBuffer.buffer, offset + pos, littleEndian));
    case 4:
        return (signed ? ByteIo.readInt32(arrayBuffer.buffer, offset + pos, littleEndian) :
                         ByteIo.readUint32(arrayBuffer.buffer, offset + pos, littleEndian));
    default:
        throw new AssertionError();
    }
}
 
Example 2
Source File: NativeDataView.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private Object js_getFloat(int bytes, Object[] args)
{
    checkOffset(args, 0);

    int pos = ScriptRuntime.toInt32(args[0]);
    rangeCheck(pos, bytes);

    boolean littleEndian =
        (isArg(args, 1) && (bytes > 1) && ScriptRuntime.toBoolean(args[1]));

    switch (bytes) {
    case 4:
        return ByteIo.readFloat32(arrayBuffer.buffer, offset + pos, littleEndian);
    case 8:
        return ByteIo.readFloat64(arrayBuffer.buffer, offset + pos, littleEndian);
    default:
        throw new AssertionError();
    }
}
 
Example 3
Source File: NativeDataView.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
private void js_setFloat(int bytes, Object[] args)
{
    checkOffset(args, 0);
    checkValue(args, 1);

    int pos = ScriptRuntime.toInt32(args[0]);
    rangeCheck(pos, bytes);

    boolean littleEndian =
        (isArg(args, 2) && (bytes > 1) && ScriptRuntime.toBoolean(args[2]));
    double val = ScriptRuntime.toNumber(args[1]);

    switch (bytes) {
    case 4:
        ByteIo.writeFloat32(arrayBuffer.buffer, offset + pos, val, littleEndian);
        break;
    case 8:
        ByteIo.writeFloat64(arrayBuffer.buffer, offset + pos, val, littleEndian);
        break;
    default:
        throw new AssertionError();
    }
}
 
Example 4
Source File: NativeDataView.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private void js_setInt(int bytes, boolean signed, Object[] args)
{
    checkOffset(args, 0);
    checkValue(args, 1);

    int pos = ScriptRuntime.toInt32(args[0]);
    rangeCheck(pos, bytes);

    boolean littleEndian =
        (isArg(args, 2) && (bytes > 1) && ScriptRuntime.toBoolean(args[2]));

    switch (bytes) {
    case 1:
        if (signed) {
            ByteIo.writeInt8(arrayBuffer.buffer, offset + pos, Conversions.toInt8(args[1]));
        } else {
            ByteIo.writeUint8(arrayBuffer.buffer, offset + pos, Conversions.toUint8(args[1]));
        }
        break;
    case 2:
        if (signed) {
            ByteIo.writeInt16(arrayBuffer.buffer, offset + pos, Conversions.toInt16(args[1]), littleEndian);
        } else {
            ByteIo.writeUint16(arrayBuffer.buffer, offset + pos, Conversions.toUint16(args[1]), littleEndian);
        }
        break;
    case 4:
        if (signed) {
            ByteIo.writeInt32(arrayBuffer.buffer, offset + pos, Conversions.toInt32(args[1]), littleEndian);
        } else {
            ByteIo.writeUint32(arrayBuffer.buffer, offset + pos, Conversions.toUint32(args[1]), littleEndian);
        }
        break;
    default:
        throw new AssertionError();
    }
}