当前位置: 首页>>代码示例>>Java>>正文


Java ScriptRuntime.toInt32方法代码示例

本文整理汇总了Java中org.mozilla.javascript.ScriptRuntime.toInt32方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.toInt32方法的具体用法?Java ScriptRuntime.toInt32怎么用?Java ScriptRuntime.toInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.ScriptRuntime的用法示例。


在下文中一共展示了ScriptRuntime.toInt32方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execIdCall

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
@Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
                         Scriptable thisObj, Object[] args)
{
    if (!f.hasTag(CLASS_NAME)) {
        return super.execIdCall(f, cx, scope, thisObj, args);
    }
    int id = f.methodId();
    switch (id) {
    case ConstructorId_isView:
        return (isArg(args, 0) && (args[0] instanceof NativeArrayBufferView));

    case Id_constructor:
        int length = isArg(args, 0) ? ScriptRuntime.toInt32(args[0]) : 0;
        return new NativeArrayBuffer(length);

    case Id_slice:
        NativeArrayBuffer self = realThis(thisObj, f);
        int start = isArg(args, 0) ? ScriptRuntime.toInt32(args[0]) : 0;
        int end = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : self.buffer.length;
        return self.slice(start, end);
    }
    throw new IllegalArgumentException(String.valueOf(id));
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:25,代码来源:NativeArrayBuffer.java

示例2: js_getInt

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:25,代码来源:NativeDataView.java

示例3: js_getFloat

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:20,代码来源:NativeDataView.java

示例4: js_setFloat

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:24,代码来源:NativeDataView.java

示例5: js_setInt

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:38,代码来源:NativeDataView.java

示例6: toInt8

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
public static int toInt8(Object arg)
{
    int iv;
    if (arg instanceof Integer) {
        iv = (Integer)arg;
    } else {
        iv = ScriptRuntime.toInt32(arg);
    }

    int int8Bit = iv % EIGHT_BIT;
    return (int8Bit >= (1 << 7)) ? (int8Bit - EIGHT_BIT) : int8Bit;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:13,代码来源:Conversions.java

示例7: toUint8

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
public static int toUint8(Object arg)
{
    int iv;
    if (arg instanceof Integer) {
        iv = ((Integer)arg);
    } else {
        iv = ScriptRuntime.toInt32(arg);
    }

    return iv % EIGHT_BIT;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:12,代码来源:Conversions.java

示例8: toInt16

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
public static int toInt16(Object arg)
{
    int iv;
    if (arg instanceof Integer) {
        iv = ((Integer)arg);
    } else {
        iv = ScriptRuntime.toInt32(arg);
    }

    int int16Bit = iv % SIXTEEN_BIT;
    return (int16Bit >= (1 << 15)) ? (int16Bit - SIXTEEN_BIT) : int16Bit;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:13,代码来源:Conversions.java

示例9: toUint16

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
public static int toUint16(Object arg)
{
    int iv;
    if (arg instanceof Integer) {
        iv = ((Integer)arg);
    } else {
        iv = ScriptRuntime.toInt32(arg);
    }

    return iv % SIXTEEN_BIT;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:12,代码来源:Conversions.java

示例10: js_set

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
@Override
protected Object js_set(int index, Object c)
{
    if (checkIndex(index)) {
        return Undefined.instance;
    }
    int val = ScriptRuntime.toInt32(c);
    ByteIo.writeInt32(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, val, false);
    return null;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:11,代码来源:NativeInt32Array.java

示例11: execIdCall

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
@Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
                         Scriptable thisObj, Object[] args)
{
    if (!f.hasTag(getClassName())) {
        return super.execIdCall(f, cx, scope, thisObj, args);
    }
    int id = f.methodId();
    switch (id) {
    case Id_constructor:
        if (isArg(args, 0) && (args[0] instanceof NativeArrayBuffer)) {
            NativeArrayBuffer ab = (NativeArrayBuffer)args[0];
            int off = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0;
            int len = isArg(args, 2) ? ScriptRuntime.toInt32(args[2]) : ab.getLength() - off;
            return js_constructor(ab, off, len);
        } else {
            throw ScriptRuntime.constructError("TypeError", "Missing parameters");
        }
    case Id_getInt8:
        return realThis(thisObj, f).js_getInt(1, true, args);
    case Id_getUint8:
        return realThis(thisObj, f).js_getInt(1, false, args);
    case Id_getInt16:
        return realThis(thisObj, f).js_getInt(2, true, args);
    case Id_getUint16:
        return realThis(thisObj, f).js_getInt(2, false, args);
    case Id_getInt32:
        return realThis(thisObj, f).js_getInt(4, true, args);
    case Id_getUint32:
        return realThis(thisObj, f).js_getInt(4, false, args);
    case Id_getFloat32:
        return realThis(thisObj, f).js_getFloat(4, args);
    case Id_getFloat64:
        return realThis(thisObj, f).js_getFloat(8, args);
    case Id_setInt8:
        realThis(thisObj, f).js_setInt(1, true, args);
        return Undefined.instance;
    case Id_setUint8:
        realThis(thisObj, f).js_setInt(1, false, args);
        return Undefined.instance;
    case Id_setInt16:
        realThis(thisObj, f).js_setInt(2, true, args);
        return Undefined.instance;
    case Id_setUint16:
        realThis(thisObj, f).js_setInt(2, false, args);
        return Undefined.instance;
    case Id_setInt32:
        realThis(thisObj, f).js_setInt(4, true, args);
        return Undefined.instance;
    case Id_setUint32:
        realThis(thisObj, f).js_setInt(4, false, args);
        return Undefined.instance;
    case Id_setFloat32:
        realThis(thisObj, f).js_setFloat(4, args);
        return Undefined.instance;
    case Id_setFloat64:
        realThis(thisObj, f).js_setFloat(8, args);
        return Undefined.instance;
    }
    throw new IllegalArgumentException(String.valueOf(id));
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:62,代码来源:NativeDataView.java


注:本文中的org.mozilla.javascript.ScriptRuntime.toInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。