public static Scriptable toObject(Scriptable scope, Object val) { if (val instanceof Scriptable) { return (Scriptable)val; } return toObject(Context.getContext(), scope, val); }
/** * @deprecated Use {@link #toObject(Scriptable, Object)} instead. */ public static Scriptable toObject(Scriptable scope, Object val, Class<?> staticClass) { if (val instanceof Scriptable) { return (Scriptable)val; } return toObject(Context.getContext(), scope, val); }
@Override public Object getDefaultValue(Class<?> hint) { if (hint == ScriptRuntime.NumberClass) { Context cx = Context.getContext(); if (cx.getLanguageVersion() == Context.VERSION_1_2) return Long.valueOf(length); } return super.getDefaultValue(hint); }
@Override public Object get(int index, Scriptable start) { if (0 <= index && index < length) { Context cx = Context.getContext(); Object obj = Array.get(array, index); return cx.getWrapFactory().wrap(cx, this, obj, cls); } return Undefined.instance; }
/** @deprecated Use {@link Context#getWrapFactory()} together with calling {@link WrapFactory#wrap(Context, Scriptable, Object, Class)} */ public static Object wrap(Scriptable scope, Object obj, Class<?> staticType) { Context cx = Context.getContext(); return cx.getWrapFactory().wrap(cx, scope, obj, staticType); }
public static Class<?> getStaticSecurityDomainClass() { SecurityController sc = Context.getContext().getSecurityController(); return sc == null ? null : sc.getStaticSecurityDomainClassInternal(); }
public static Object[] getArrayElements(Scriptable object) { Context cx = Context.getContext(); long longLen = NativeArray.getLengthProperty(cx, object); if (longLen > Integer.MAX_VALUE) { // arrays beyond MAX_INT is not in Java in any case throw new IllegalArgumentException(); } int len = (int) longLen; if (len == 0) { return ScriptRuntime.emptyArgs; } else { Object[] result = new Object[len]; for (int i=0; i < len; i++) { Object elem = ScriptableObject.getProperty(object, i); result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance : elem; } return result; } }
private InterpretedFunction(InterpreterData idata, Object staticSecurityDomain) { this.idata = idata; // Always get Context from the current thread to // avoid security breaches via passing mangled Context instances // with bogus SecurityController Context cx = Context.getContext(); SecurityController sc = cx.getSecurityController(); Object dynamicDomain; if (sc != null) { dynamicDomain = sc.getDynamicSecurityDomain(staticSecurityDomain); } else { if (staticSecurityDomain != null) { throw new IllegalArgumentException(); } dynamicDomain = null; } this.securityController = sc; this.securityDomain = dynamicDomain; }
@Override public Object getDefaultValue(Class<?> hint) { if (hint == ScriptRuntime.FunctionClass) return this; Object rval; Class<?> type; try { rval = field.get(javaObject); type = field.getType(); } catch (IllegalAccessException accEx) { throw Context.reportRuntimeError1( "msg.java.internal.private", field.getName()); } Context cx = Context.getContext(); rval = cx.getWrapFactory().wrap(cx, this, rval, type); if (rval instanceof Scriptable) { rval = ((Scriptable) rval).getDefaultValue(hint); } return rval; }
Context cx = getContext(); if (cx == null || !cx.hasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS))
/** * The typeof operator that correctly handles the undefined case */ public static String typeofName(Scriptable scope, String id) { Context cx = Context.getContext(); Scriptable val = bind(cx, scope, id); if (val == null) return "undefined"; return typeof(getObjectProp(val, id, cx)); }
@Override public int getLength() { int paramCount = getParamCount(); if (getLanguageVersion() != Context.VERSION_1_2) { return paramCount; } Context cx = Context.getContext(); NativeCall activation = ScriptRuntime.findFunctionActivation(cx, this); if (activation == null) { return paramCount; } return activation.originalArgs.length; }
private Object getArguments() { // <Function name>.arguments is deprecated, so we use a slow // way of getting it that doesn't add to the invocation cost. // TODO: add warning, error based on version Object value = defaultGet("arguments"); if (value != NOT_FOUND) { // Should after changing <Function name>.arguments its // activation still be available during Function call? // This code assumes it should not: // defaultGet("arguments") != NOT_FOUND // means assigned arguments return value; } Context cx = Context.getContext(); NativeCall activation = ScriptRuntime.findFunctionActivation(cx, this); return (activation == null) ? null : activation.get("arguments", activation); }
if (converterObject instanceof Function) { Function f = (Function)converterObject; value = f.call(Context.getContext(), f.getParentScope(), this, ScriptRuntime.emptyArgs); } else {
private void generateRegExpLiterals() { int N = scriptOrFn.getRegexpCount(); if (N == 0) return; Context cx = Context.getContext(); RegExpProxy rep = ScriptRuntime.checkRegExpProxy(cx); Object[] array = new Object[N]; for (int i = 0; i != N; i++) { String string = scriptOrFn.getRegexpString(i); String flags = scriptOrFn.getRegexpFlags(i); array[i] = rep.compileRegExp(cx, string, flags); } itsData.itsRegExpLiterals = array; }
/** * Report a warning using the error reporter for the current thread. * * @param message the warning message to report * @param sourceName a string describing the source, such as a filename * @param lineno the starting line number * @param lineSource the text of the line (may be null) * @param lineOffset the offset into lineSource where problem was detected * @see net.sourceforge.htmlunit.corejs.javascript.ErrorReporter */ public static void reportWarning(String message, String sourceName, int lineno, String lineSource, int lineOffset) { Context cx = Context.getContext(); if (cx.hasFeature(FEATURE_WARNING_AS_ERROR)) reportError(message, sourceName, lineno, lineSource, lineOffset); else cx.getErrorReporter().warning(message, sourceName, lineno, lineSource, lineOffset); }
ClassLoader parent, Object staticDomain) Context cx = Context.getContext(); if (parent == null) { parent = cx.getApplicationClassLoader();
Context cx = Context.getContext(); Scriptable scope = ScriptableObject.getTopLevelScope(start); return cx.getWrapFactory().wrap(cx, scope, javaObject,
} else { Function f = (Function)getterObj; Context cx = Context.getContext(); return f.call(cx, f.getParentScope(), start, ScriptRuntime.emptyArgs);
public static Object nameIncrDecr(Scriptable scopeChain, String id, Context cx, int incrDecrMask) { Scriptable target; Object value; search: { do { if (cx.useDynamicScope && scopeChain.getParentScope() == null) { scopeChain = checkDynamicScope(cx.topCallScope, scopeChain); } target = scopeChain; do { value = target.get(id, scopeChain); if (value != Scriptable.NOT_FOUND) { break search; } target = target.getPrototype(); } while (target != null); scopeChain = scopeChain.getParentScope(); } while (scopeChain != null); throw notFoundError(scopeChain, id); } return doScriptableIncrDecr(target, id, scopeChain, value, incrDecrMask); }