public static Scriptable runScript(final Script script) { return (Scriptable)Context.call(new ContextAction() { public Object run(Context cx) { ScriptableObject global = ScriptRuntime.getGlobal(cx); script.exec(cx, global); return global; } }); }
private String call(Function fn, Object[] args) { return (String) Context.call(null, fn, scope, scope, args); }
private synchronized String call(Function fn, Object[] args) { return (String) Context.call(null, fn, scope, scope, args); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
/** * Call {@link ContextAction#run(Context cx)} * using the {@link Context} instance associated with the current thread. * If no Context is associated with the thread, then * {@link #makeContext()} will be called to construct * new Context instance. The instance will be temporary associated * with the thread during call to {@link ContextAction#run(Context)}. * * @see ContextFactory#call(ContextAction) * @see Context#call(ContextFactory factory, Callable callable, * Scriptable scope, Scriptable thisObj, * Object[] args) */ public final Object call(ContextAction action) { return Context.call(this, action); }
public static void main(final Script script, final String[] args) { Context.call(new ContextAction() { public Object run(Context cx) { ScriptableObject global = getGlobal(cx); // get the command line arguments and define "arguments" // array in the top-level object Object[] argsCopy = new Object[args.length]; System.arraycopy(args, 0, argsCopy, 0, args.length); Scriptable argsObj = cx.newArray(global, argsCopy); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); script.exec(cx, global); return null; } }); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * * @return The result of {@link ContextAction#run(Context)}. */ public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * @deprecated use {@link ContextFactory#call(ContextAction)} instead as * this method relies on usage of a static singleton "global" * ContextFactory. * @return The result of {@link ContextAction#run(Context)}. */ public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * @deprecated use {@link ContextFactory#call(ContextAction)} instead as * this method relies on usage of a static singleton "global" * ContextFactory. * @return The result of {@link ContextAction#run(Context)}. */ public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * @deprecated use {@link ContextFactory#call(ContextAction)} instead as * this method relies on usage of a static singleton "global" * ContextFactory. * @return The result of {@link ContextAction#run(Context)}. */ public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * @deprecated use {@link ContextFactory#call(ContextAction)} instead as * this method relies on usage of a static singleton "global" * ContextFactory. * @return The result of {@link ContextAction#run(Context)}. */ public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
/** * Call {@link ContextAction#run(Context cx)} * using the Context instance associated with the current thread. * If no Context is associated with the thread, then * <tt>ContextFactory.getGlobal().makeContext()</tt> will be called to * construct new Context instance. The instance will be temporary * associated with the thread during call to * {@link ContextAction#run(Context)}. * @deprecated use {@link ContextFactory#call(ContextAction)} instead as * this method relies on usage of a static singleton "global" * ContextFactory. * @return The result of {@link ContextAction#run(Context)}. */ @Deprecated public static Object call(ContextAction action) { return call(ContextFactory.getGlobal(), action); }
protected void compress() throws IOException { URL cssmin = getClass().getClassLoader().getResource( "META-INF/cssmin.js"); Context cx = Context.enter(); cx.setOptimizationLevel(9); Global global = new Global(); global.init(cx); Scriptable scope = cx.initStandardObjects(global); cx.evaluateString(scope, "var exports = {};", "exports", 1, null); cx.evaluateReader(scope, new InputStreamReader(cssmin.openConnection() .getInputStream()), cssmin.getFile(), 1, null); Scriptable exports = (Scriptable) scope.get("exports", scope); Scriptable compressor = (Scriptable) exports.get("compressor", exports); Function fn = (Function) compressor.get("cssmin", compressor); content = ((String) Context.call(null, fn, compressor, compressor, new Object[] { new String(content, charset).replaceFirst( "^/\\*", "/*!") })).getBytes(charset); Context.exit(); }
public static Object call(String fn, Object... args) { return Context.call(null, (Function) getScope().get(fn, getScope()), getScope(), getScope(), args); }
public static Object call(String fn, Object... args) { return Context.call(null, (Function) getScope().get(fn, getScope()), getScope(), getScope(), args); }
/** * Call a method of an object. * @param cx the Context object associated with the current thread. * @param obj the JavaScript object * @param methodName the name of the function property * @param args the arguments for the call */ public static Object callMethod(Context cx, Scriptable obj, String methodName, Object[] args) { Object funObj = getProperty(obj, methodName); if (!(funObj instanceof Function)) { throw ScriptRuntime.notFunctionError(obj, methodName); } Function fun = (Function)funObj; // XXX: What should be the scope when calling funObj? // The following favor scope stored in the object on the assumption // that is more useful especially under dynamic scope setup. // An alternative is to check for dynamic scope flag // and use ScriptableObject.getTopLevelScope(fun) if the flag is not // set. But that require access to Context and messy code // so for now it is not checked. Scriptable scope = ScriptableObject.getTopLevelScope(obj); if (cx != null) { return fun.call(cx, scope, obj, args); } else { return Context.call(null, fun, scope, obj, args); } }