public static int toInt32(Object[] args, int index) { return (index < args.length) ? toInt32(args[index]) : 0; }
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.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)); }
/** * Convert the argument to int32 number. */ public static Object toint32(Context cx, Scriptable thisObj, Object[] args, Function funObj) { Object arg = (args.length != 0 ? args[0] : Undefined.instance); if (arg instanceof Integer) return arg; return ScriptRuntime.wrapInt(ScriptRuntime.toInt32(arg)); }
/** * Call embedding-specific quit action passing its argument as * int32 exit code. * * This method is defined as a JavaScript function. */ public static void quit(Context cx, Scriptable thisObj, Object[] args, Function funObj) { Global global = getInstance(funObj); if (global.quitAction != null) { int exitCode = (args.length == 0 ? 0 : ScriptRuntime.toInt32(args[0])); global.quitAction.quit(cx, exitCode); } }
/** * Sets a chunk of JavaScript to be invoked each time a specified number of milliseconds has elapsed. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval"> * MDN web docs</a> * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created interval */ @JsxFunction public static Object setInterval(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, false, params); }
/** * Sets a chunk of JavaScript to be invoked at some specified time later. * The invocation occurs only if the window is opened after the delay * and does not contain an other page than the one that originated the setTimeout. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout"> * MDN web docs</a> * * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created timer */ @JsxFunction public static Object setTimeout(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, true, params); }
/** * Sets a chunk of JavaScript to be invoked each time a specified number of milliseconds has elapsed. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval"> * MDN web docs</a> * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created interval */ @JsxFunction public static Object setInterval(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, false, params); }
public static Object convertArg(Context cx, Scriptable scope, Object arg, int typeTag) { switch (typeTag) { case JAVA_STRING_TYPE: if (arg instanceof String) return arg; return ScriptRuntime.toString(arg); case JAVA_INT_TYPE: if (arg instanceof Integer) return arg; return Integer.valueOf(ScriptRuntime.toInt32(arg)); case JAVA_BOOLEAN_TYPE: if (arg instanceof Boolean) return arg; return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE : Boolean.FALSE; case JAVA_DOUBLE_TYPE: if (arg instanceof Double) return arg; return new Double(ScriptRuntime.toNumber(arg)); case JAVA_SCRIPTABLE_TYPE: return ScriptRuntime.toObjectOrNull(cx, arg, scope); case JAVA_OBJECT_TYPE: return arg; default: throw new IllegalArgumentException(); } }
int radix = ScriptRuntime.toInt32(args, 1);
private static String num_to(double val, Object[] args, int zeroArgMode, int oneArgMode, int precisionMin, int precisionOffset) { int precision; if (args.length == 0) { precision = 0; oneArgMode = zeroArgMode; } else { /* We allow a larger range of precision than ECMA requires; this is permitted by ECMA. */ precision = ScriptRuntime.toInt32(args[0]); if (precision < precisionMin || precision > MAX_PRECISION) { String msg = ScriptRuntime.getMessage1( "msg.bad.precision", ScriptRuntime.toString(args[0])); throw ScriptRuntime.constructError("RangeError", msg); } } StringBuffer sb = new StringBuffer(); DToA.JS_dtostr(sb, oneArgMode, precision + precisionOffset, val); return sb.toString(); }
int line = ScriptRuntime.toInt32(lineNumber); if (line != 0) { sb.append(", ");
/** * Sets a chunk of JavaScript to be invoked at some specified time later. * The invocation occurs only if the window is opened after the delay * and does not contain an other page than the one that originated the setTimeout. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout"> * MDN web docs</a> * * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created timer */ @JsxFunction public static Object setTimeout(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, true, params); }
private static ObjToIntMap getObjectFunctionNames(Scriptable obj) { Object[] ids = ScriptableObject.getPropertyIds(obj); ObjToIntMap map = new ObjToIntMap(ids.length); for (int i = 0; i != ids.length; ++i) { if (!(ids[i] instanceof String)) continue; String id = (String) ids[i]; Object value = ScriptableObject.getProperty(obj, id); if (value instanceof Function) { Function f = (Function)value; int length = ScriptRuntime.toInt32( ScriptableObject.getProperty(f, "length")); if (length < 0) { length = 0; } map.put(id, length); } } return map; }
? 10 : ScriptRuntime.toInt32(args[0]); return ScriptRuntime.numberToString(value, base);
ScriptableObject.putProperty(obj, "fileName", args[1]); if (arglen >= 3) { int line = ScriptRuntime.toInt32(args[2]); ScriptableObject.putProperty(obj, "lineNumber", Integer.valueOf(line));
case Token.BITNOT: if (childType == Token.NUMBER) { int value = ScriptRuntime.toInt32(child.getDouble()); child.setDouble(~value); return child;