/** * Calls action on the wrapped RegExp proxy. */ private Object wrappedAction(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args, final int actionType) { // take care to set the context's RegExp proxy to the original one as this is checked // (cf net.sourceforge.htmlunit.corejs.javascript.regexp.RegExpImp:334) try { ScriptRuntime.setRegExpProxy(cx, wrapped_); return wrapped_.action(cx, scope, thisObj, args, actionType); } finally { ScriptRuntime.setRegExpProxy(cx, this); } }
/** * {@inheritDoc} */ @Override protected Object equivalentValues(final Object value) { return ScriptRuntime.eq(getWrappedScriptable(), value); }
private static RegExpImpl getImpl(Context cx) { return (RegExpImpl) ScriptRuntime.getRegExpProxy(cx); }
/** * Call obj.[[Get]](id) */ public static Object getObjectElem(Object obj, Object elem, Context cx) { return getObjectElem(obj, elem, cx, getTopCallScope(cx)); }
private static void reportError(String messageId, String arg) { String msg = ScriptRuntime.getMessage1(messageId, arg); throw ScriptRuntime.constructError("SyntaxError", msg); }
/** * Warning: this doesn't allow to resolve primitive prototype properly when many top scopes are involved */ public static Scriptable toObjectOrNull(Context cx, Object obj) { if (obj instanceof Scriptable) { return (Scriptable)obj; } else if (obj != null && obj != Undefined.instance) { return toObject(cx, getTopCallScope(cx), obj); } return null; }
if (value == DBL_MRK) value = ScriptRuntime.wrapNumber(sDbl[stackTop]); --stackTop; lDbl = stack_double(frame, stackTop); } else if (lhs == DBL_MRK) { rDbl = ScriptRuntime.toNumber(rhs); lDbl = sDbl[stackTop]; } else { valBln = ScriptRuntime.cmp_LE(rhs, lhs); break; case Token.LE: valBln = ScriptRuntime.cmp_LE(lhs, rhs); break; case Token.GT: valBln = ScriptRuntime.cmp_LT(rhs, lhs); break; case Token.LT: valBln = ScriptRuntime.cmp_LT(lhs, rhs); break; default: stack[stackTop] = ScriptRuntime.wrapBoolean(valBln); continue Loop; case Token.INSTANCEOF : { Object rhs = stack[stackTop]; if (rhs == DBL_MRK) rhs = ScriptRuntime.wrapNumber(sDbl[stackTop]); --stackTop;
/** * {@inheritDoc} */ @Override protected Context makeContext() { final TimeoutContext cx = new TimeoutContext(this); // Use pure interpreter mode to get observeInstructionCount() callbacks. cx.setOptimizationLevel(-1); // Set threshold on how often we want to receive the callbacks cx.setInstructionObserverThreshold(INSTRUCTION_COUNT_THRESHOLD); configureErrorReporter(cx); cx.setWrapFactory(wrapFactory_); if (debugger_ != null) { cx.setDebugger(debugger_, null); } // register custom RegExp processing ScriptRuntime.setRegExpProxy(cx, new HtmlUnitRegExpProxy(ScriptRuntime.getRegExpProxy(cx))); return cx; }
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(); } }
if (reImpl != ScriptRuntime.getRegExpProxy(cx)) Kit.codeBug(); RegExpImpl re2 = new RegExpImpl(); re2.multiline = reImpl.multiline; re2.input = reImpl.input; ScriptRuntime.setRegExpProxy(cx, re2); try { Scriptable parent = ScriptableObject.getTopLevelScope(scope); Object result = rdata.lambda.call(cx, parent, parent, args); lambdaStr = ScriptRuntime.toString(result); } finally { ScriptRuntime.setRegExpProxy(cx, reImpl);
if (id == Id_constructor) { double val = (args.length >= 1) ? ScriptRuntime.toNumber(args[0]) : 0.0; if (thisObj == null) { return ScriptRuntime.wrapNumber(val); ? 10 : ScriptRuntime.toInt32(args[0]); return ScriptRuntime.numberToString(value, base); return "(new Number("+ScriptRuntime.toString(value)+"))"; return ScriptRuntime.wrapNumber(value); return ScriptRuntime.numberToString(value, 10);
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(); }
/** * 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); }
/** * @deprecated EcmaError error instances should not be constructed * explicitly since they are generated by the engine. */ public EcmaError(Scriptable nativeError, String sourceName, int lineNumber, int columnNumber, String lineSource) { this("InternalError", ScriptRuntime.toString(nativeError), sourceName, lineNumber, lineSource, columnNumber); }
Scriptable result = ScriptRuntime.newObject(cx, top, "Array", null); if (limited) { limit = ScriptRuntime.toUint32(args[1]); if (limit > target.length()) limit = 1 + target.length(); RegExpProxy reProxy = null; if (args[0] instanceof Scriptable) { reProxy = ScriptRuntime.getRegExpProxy(cx); if (reProxy != null) { Scriptable test = (Scriptable)args[0]; separator = ScriptRuntime.toString(args[0]); matchlen[0] = separator.length();
public static RuntimeException notFunctionError(Object obj, Object value, String propertyName) { // Use obj and value for better error reporting String objString = toString(obj); if (value == Scriptable.NOT_FOUND) { return typeError2("msg.function.not.found.in", propertyName, objString); } return typeError3("msg.isnt.function.in", propertyName, objString, typeof(value)); }
/** * Calls the function. * @param cx the current context * @param scope the scope used for the call * @param thisObj the value of "this" * @param args function arguments. Must not be null. You can use * {@link ScriptRuntime#emptyArgs} to pass empty arguments. * @return the result of the function call. */ @Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!ScriptRuntime.hasTopCall(cx)) { return ScriptRuntime.doTopCall(this, cx, scope, thisObj, args); } return Interpreter.interpret(this, cx, scope, thisObj, args); }
public static Object getObjectIndex(Object obj, double dblIndex, Context cx) { Scriptable sobj = toObjectOrNull(cx, obj); if (sobj == null) { throw undefReadError(obj, toString(dblIndex)); } int index = (int)dblIndex; if (index == dblIndex) { return getObjectIndex(sobj, index, cx); } else { String s = toString(dblIndex); return getObjectProp(sobj, s, cx); } }
public static Object setObjectIndex(Object obj, double dblIndex, Object value, Context cx) { Scriptable sobj = toObjectOrNull(cx, obj); if (sobj == null) { throw undefWriteError(obj, String.valueOf(dblIndex), value); } int index = (int)dblIndex; if (index == dblIndex) { return setObjectIndex(sobj, index, value, cx); } else { String s = toString(dblIndex); return setObjectProp(sobj, s, value, cx); } }
String s = ScriptRuntime.toString(args, 0); int radix = ScriptRuntime.toInt32(args, 1); double d = ScriptRuntime.stringToNumber(s, start, radix); return ScriptRuntime.wrapNumber(negative ? -d : d);