private static double stack_double(CallFrame frame, int i) { Object x = frame.stack[i]; if (x != UniqueTag.DOUBLE_MARK) { return ScriptRuntime.toNumber(x); } else { return frame.sDbl[i]; } }
public static int toInt32(Object arg) { long lv = (long)ScriptRuntime.toNumber(arg); long int32Bit = lv % THIRTYTWO_BIT; return (int)((int32Bit >= (1L << 31L)) ? (int32Bit - THIRTYTWO_BIT) : int32Bit); }
private static double stack_double(CallFrame frame, int i) { Object x = frame.stack[i]; if (x != UniqueTag.DOUBLE_MARK) { return ScriptRuntime.toNumber(x); } else { return frame.sDbl[i]; } }
private static double stack_double(CallFrame frame, int i) { Object x = frame.stack[i]; if (x != UniqueTag.DOUBLE_MARK) { return ScriptRuntime.toNumber(x); } else { return frame.sDbl[i]; } }
/** * * See ECMA 9.4. */ public static double toInteger(Object val) { return toInteger(toNumber(val)); }
/** * * See ECMA 9.5. */ public static int toInt32(Object val) { // short circuit for common integer values if (val instanceof Integer) return ((Integer)val).intValue(); return toInt32(toNumber(val)); }
private static int js_lastIndexOf(String target, Object[] args) { String search = ScriptRuntime.toString(args, 0); double end = ScriptRuntime.toNumber(args, 1); if (end != end || end > target.length()) end = target.length(); else if (end < 0) end = 0; return target.lastIndexOf(search, (int)end); }
private static long toArrayIndex(String id) { long index = toArrayIndex(ScriptRuntime.toNumber(id)); // Assume that ScriptRuntime.toString(index) is the same // as java.lang.Long.toString(index) for long if (Long.toString(index).equals(id)) { return index; } return -1; }
/** * * See ECMA 9.7. */ public static char toUint16(Object val) { double d = toNumber(val); return (char)DoubleConversion.doubleToInt32(d); }
@Override protected void setInstanceIdValue(int id, Object value) { if (id == Id_lastIndex) { lastIndex = ScriptRuntime.toNumber(value); return; } super.setInstanceIdValue(id, value); }
private static int stack_int32(CallFrame frame, int i) { Object x = frame.stack[i]; double value; if (x == UniqueTag.DOUBLE_MARK) { value = frame.sDbl[i]; } else { value = ScriptRuntime.toNumber(x); } return ScriptRuntime.toInt32(value); }
/** * * See ECMA 9.4. */ public static double toInteger(Object val) { return toInteger(toNumber(val)); }
private static int js_lastIndexOf(String target, Object[] args) { String search = ScriptRuntime.toString(args, 0); double end = ScriptRuntime.toNumber(args, 1); if (end != end || end > target.length()) end = target.length(); else if (end < 0) end = 0; return target.lastIndexOf(search, (int)end); }
static Object isFinite(Object val) { double d = ScriptRuntime.toNumber(val); Double nd = Double.valueOf(d); return ScriptRuntime.wrapBoolean(!nd.isInfinite() && !nd.isNaN()); }
/** * * See ECMA 9.5. */ public static int toInt32(Object val) { // short circuit for common integer values if (val instanceof Integer) return ((Integer)val).intValue(); return toInt32(toNumber(val)); }
private static int js_lastIndexOf(String target, Object[] args) { String search = ScriptRuntime.toString(args, 0); double end = ScriptRuntime.toNumber(args, 1); if (end != end || end > target.length()) end = target.length(); else if (end < 0) end = 0; return target.lastIndexOf(search, (int)end); }
private static long toArrayIndex(String id) { long index = toArrayIndex(ScriptRuntime.toNumber(id)); // Assume that ScriptRuntime.toString(index) is the same // as java.lang.Long.toString(index) for long if (Long.toString(index).equals(id)) { return index; } return -1; }
/** * * See ECMA 9.4. */ public static double toInteger(Object val) { return toInteger(toNumber(val)); }
@Override protected Object js_set(int index, Object c) { if (checkIndex(index)) { return Undefined.instance; } double val = ScriptRuntime.toNumber(c); long base = Double.doubleToLongBits(val); ByteIo.writeUint64(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, base, false); return null; }
private Object js_imul(Object[] args) { if ((args == null) || (args.length < 2)) { return ScriptRuntime.wrapNumber(ScriptRuntime.NaN); } long x = Conversions.toUint32(args[0]); long y = Conversions.toUint32(args[1]); long product = (x * y) % Conversions.THIRTYTWO_BIT; long result = (product >= (1L << 31L)) ? (product - Conversions.THIRTYTWO_BIT) : product; return ScriptRuntime.toNumber(result); }