org.mozilla.javascript.Context.call()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(11.2k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中org.mozilla.javascript.Context.call()方法的一些代码示例,展示了Context.call()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.call()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:call

Context.call介绍

[英]Call ContextAction#run(Context cx)using the Context instance associated with the current thread. If no Context is associated with the thread, then ContextFactory.getGlobal().makeContext() will be called to construct new Context instance. The instance will be temporary associated with the thread during call to ContextAction#run(Context).
[中]使用与当前线程关联的上下文实例调用ContextAction#run(Context cx)。如果没有与线程关联的上下文,则为ContextFactory。getGlobal()。将调用makeContext()来构造新的上下文实例。在调用ContextAction#run(上下文)期间,该实例将临时与线程关联。

代码示例

代码示例来源:origin: com.sun.phobos/phobos-rhino

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;
    }
  });
}

代码示例来源:origin: com.asual.lesscss/lesscss-engine

private String call(Function fn, Object[] args) {
  return (String) Context.call(null, fn, scope, scope, args);
}

代码示例来源:origin: com.google.code.maven-play-plugin.com.asual.lesscss/lesscss-engine

private synchronized String call(Function fn, Object[] args) {
  return (String) Context.call(null, fn, scope, scope, args);
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

/**
 * 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);
}

代码示例来源:origin: rhino/js

/**
 * 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);
}

代码示例来源:origin: geogebra/geogebra

/**
 * 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);
}

代码示例来源:origin: io.apigee/rhino

/**
 * 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);
}

代码示例来源:origin: ro.isdc.wro4j/rhino

/**
 * 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);
}

代码示例来源:origin: com.github.tntim96/rhino

/**
 * 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);
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

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;
    }
  });
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

/**
 * 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);
}

代码示例来源:origin: rhino/js

/**
 * 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);
}

代码示例来源:origin: io.apigee/rhino

/**
 * 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);
}

代码示例来源:origin: com.github.tntim96/rhino

/**
 * 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);
}

代码示例来源:origin: ro.isdc.wro4j/rhino

/**
 * 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);
}

代码示例来源:origin: geogebra/geogebra

/**
 * 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);
}

代码示例来源:origin: com.asual.lesscss/lesscss-servlet

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();
}

代码示例来源:origin: com.asual.summer/summer-core

public static Object call(String fn, Object... args) {
  return Context.call(null, (Function) getScope().get(fn, getScope()), getScope(), getScope(), args);
}

代码示例来源:origin: asual/summer

public static Object call(String fn, Object... args) {
  return Context.call(null, (Function) getScope().get(fn, getScope()), getScope(), getScope(), args);
}

代码示例来源:origin: rhino/js

/**
 * 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);
  }
}

相关文章

微信公众号

Context类方法