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

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

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

Context.compileReader介绍

[英]Compiles the source in the given reader.

Returns a script that may later be executed. Will consume all the source in the reader.
[中]编译给定读取器中的源代码。
返回以后可能执行的脚本。将消耗读取器中的所有源。

代码示例

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

/**
 * @deprecated
 * @see #compileReader(Reader in, String sourceName, int lineno,
 *                     Object securityDomain)
 */
@Deprecated
public final Script compileReader(Scriptable scope, Reader in,
                 String sourceName, int lineno,
                 Object securityDomain)
  throws IOException
{
  return compileReader(in, sourceName, lineno, securityDomain);
}

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

throws IOException
Script script = compileReader(scope, in, sourceName, lineno,
               securityDomain);
if (script != null) {

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

/**
 * Evaluate a reader as JavaScript source.
 *
 * All characters of the reader are consumed.
 *
 * @param scope the scope to execute in
 * @param in the Reader to get JavaScript source from
 * @param sourceName a string describing the source, such as a filename
 * @param lineno the starting line number
 * @param securityDomain an arbitrary object that specifies security
 *        information about the origin or owner of the script. For
 *        implementations that don't care about security, this value
 *        may be null.
 * @return the result of evaluating the source
 *
 * @exception IOException if an IOException was generated by the Reader
 */
public final Object evaluateReader(Scriptable scope, Reader in,
                  String sourceName, int lineno,
                  Object securityDomain)
  throws IOException
{
  Script script = compileReader(scope, in, sourceName, lineno,
                 securityDomain);
  if (script != null) {
    return script.exec(this, scope);
  } else {
    return null;
  }
}

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

/**
 * Evaluate a reader as JavaScript source.
 *
 * All characters of the reader are consumed.
 *
 * @param scope the scope to execute in
 * @param in the Reader to get JavaScript source from
 * @param sourceName a string describing the source, such as a filename
 * @param lineno the starting line number
 * @param securityDomain an arbitrary object that specifies security
 *        information about the origin or owner of the script. For
 *        implementations that don't care about security, this value
 *        may be null.
 * @return the result of evaluating the source
 *
 * @exception IOException if an IOException was generated by the Reader
 */
public final Object evaluateReader(Scriptable scope, Reader in,
                  String sourceName, int lineno,
                  Object securityDomain)
  throws IOException
{
  Script script = compileReader(scope, in, sourceName, lineno,
                 securityDomain);
  if (script != null) {
    return script.exec(this, scope);
  } else {
    return null;
  }
}

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

/**
 * Evaluate a reader as JavaScript source.
 *
 * All characters of the reader are consumed.
 *
 * @param scope the scope to execute in
 * @param in the Reader to get JavaScript source from
 * @param sourceName a string describing the source, such as a filename
 * @param lineno the starting line number
 * @param securityDomain an arbitrary object that specifies security
 *        information about the origin or owner of the script. For
 *        implementations that don't care about security, this value
 *        may be null.
 * @return the result of evaluating the source
 *
 * @exception IOException if an IOException was generated by the Reader
 */
public final Object evaluateReader(Scriptable scope, Reader in,
                  String sourceName, int lineno,
                  Object securityDomain)
  throws IOException
{
  Script script = compileReader(scope, in, sourceName, lineno,
                 securityDomain);
  if (script != null) {
    return script.exec(this, scope);
  } else {
    return null;
  }
}

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

/**
 * Evaluate a reader as JavaScript source.
 *
 * All characters of the reader are consumed.
 *
 * @param scope the scope to execute in
 * @param in the Reader to get JavaScript source from
 * @param sourceName a string describing the source, such as a filename
 * @param lineno the starting line number
 * @param securityDomain an arbitrary object that specifies security
 *        information about the origin or owner of the script. For
 *        implementations that don't care about security, this value
 *        may be null.
 * @return the result of evaluating the source
 *
 * @exception IOException if an IOException was generated by the Reader
 */
public final Object evaluateReader(Scriptable scope, Reader in,
                  String sourceName, int lineno,
                  Object securityDomain)
  throws IOException
{
  Script script = compileReader(scope, in, sourceName, lineno,
                 securityDomain);
  if (script != null) {
    return script.exec(this, scope);
  } else {
    return null;
  }
}

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

protected Script compileScript(Context cx, Scriptable scope, Source src)
throws Exception {
  PushbackInputStream is = new PushbackInputStream(src.getInputStream(), ENCODING_BUF_SIZE);
  try {
    String encoding = findEncoding(is);
    Reader reader = encoding == null ? new InputStreamReader(is) : new InputStreamReader(is, encoding);
    reader = new BufferedReader(reader);
    return cx.compileReader(reader, src.getURI(), 1, null);
  } finally {
    is.close();
  }
}

代码示例来源:origin: biz.gabrys.lesscss/compiler

private void initialize() throws InitializationException {
  InputStreamReader reader = null;
  try {
    final Context context = Context.enter();
    context.setLanguageVersion(Context.VERSION_1_8);
    final Global global = new Global();
    global.init(context);
    scope = context.initStandardObjects(global);
    console = new ByteArrayOutputStream();
    global.setOut(new PrintStream(console, false, CHARSET));
    final URL lessFile = LessCompilerImpl.class.getResource("/less/less-rhino-1.7.5.js");
    final URL lesscFile = LessCompilerImpl.class.getResource("/less/lessc-rhino-1.7.5.js");
    final Collection<InputStream> streams = new ArrayList<InputStream>();
    streams.add(lessFile.openConnection().getInputStream());
    streams.add(lesscFile.openConnection().getInputStream());
    reader = new InputStreamReader(new SequenceInputStream(Collections.enumeration(streams)), CHARSET);
    compiler = (Function) context.compileReader(reader, lessFile.toString(), 1, null);
  } catch (final Exception e) {
    throw new InitializationException("Failed to initialize Less compiler", e);
  } finally {
    IOUtils.closeQuietly(reader);
    Context.exit();
  }
}

代码示例来源:origin: org.apache.cocoon/cocoon-forms-impl

/**
 * Build a script with the content of a DOM element.
 *
 * @param element the element containing the script
 * @return the compiled script
 * @throws IOException
 */
public static Script buildScript(Element element) throws IOException {
  String jsText = DomHelper.getElementText(element);
  String sourceName = DomHelper.getSystemIdLocation(element);
  Context ctx = Context.enter();
  Script script;
  try {
    
    script = ctx.compileReader(
      // To use rhino1.5r4-continuations-R26.jar as a workaround for COCOON-1579: Uncomment the next line.
      // getRootScope(null), //scope
      new StringReader(jsText), // in
      sourceName == null ? "<unknown>" : sourceName, // sourceName
      DomHelper.getLineLocation(element), // lineNo
      null // securityDomain
     );
  } finally {
    Context.exit();
  }
  return script;
}

代码示例来源:origin: RPTools/maptool

public static synchronized void init() throws IOException {
  if (jsScope != null)
    return;
  try {
    Context jsContext = ContextFactory.getGlobal().enterContext();
    jsContext.setClassShutter(new SecurityClassShutter());
    jsScope = jsContext.initStandardObjects(null, true);
    Object o = Context.javaToJS(new TokenApi(), jsScope);
    ScriptableObject.putProperty(jsScope, "rptools_global_tokens", o);
    for (String script : JAVASCRIPT_FILES) {
      Reader reader = new InputStreamReader(ScriptManager.class.getClassLoader().getResourceAsStream(script));
      Script compiled = jsContext.compileReader(reader, script, 1, null);
      compiled.exec(jsContext, jsScope);
    }
    // jsScope.sealObject();
  } finally {
    Context.exit();
  }
}

代码示例来源:origin: ca.carleton.gcrc/nunaliit2-javascript

public void addJavascript(Reader reader, String name, int lineno) throws Exception {
  try {
    Script script = cx.compileReader(reader, name, lineno, null);
    script.exec(cx, scope);
    
  } catch(EvaluatorException e) {
    for(JavascriptRunnerListener listener : listeners){
      listener.compileError(e.details(), e.sourceName(), e.lineNumber(), e.columnNumber());
    }
    throw e;
  } catch(Exception e) {
    reportUnexpectedError(e);
    throw e;
  }
}

代码示例来源:origin: rhq-project/rhq

@Override
public CompiledScript compile(java.io.Reader script) throws ScriptException {
  CompiledScript ret = null;
  Context cx = enterContext();
  
  try {
    String filename = (String) get(RhinoScriptEngine.FILENAME);
    if (filename == null) {
      filename = "<Unknown Source>";
    }
    
    Script scr = cx.compileReader(preProcessScriptSource(script), filename, 1, null);
    ret = new RhinoCompiledScript(this, scr);
  } catch (Exception e) {
    if (DEBUG) e.printStackTrace();
    throw new ScriptException(e);
  } finally {
    Context.exit();
  }
  return ret;
}

代码示例来源:origin: io.apisense/rhino-android

public CompiledScript compile(java.io.Reader script) throws ScriptException {
  CompiledScript ret = null;
  Context cx = enterContext();
  try {
    String fileName = (String) get(ScriptEngine.FILENAME);
    if (fileName == null) {
      fileName = "<Unknown Source>";
    }
    Scriptable scope = getRuntimeScope(context);
    Script scr = cx.compileReader(scope, script, fileName, 1, null);
    ret = new RhinoCompiledScript(this, scr);
  } catch (Exception e) {
    if (DEBUG) e.printStackTrace();
    throw new ScriptException(e);
  } finally {
    cx.exit();
  }
  return ret;
}

代码示例来源:origin: cat.inspiracio/rhino-js-engine

public CompiledScript compile(java.io.Reader script) throws ScriptException {
  CompiledScript ret = null;
  Context cx = enterContext();
  
  try {
    String filename = (String) get(ScriptEngine.FILENAME);
    if (filename == null) {
      filename = "<Unknown Source>";
    }
    
    Scriptable scope = getRuntimeScope(context);
    @SuppressWarnings("deprecation")
    Script scr = cx.compileReader(scope, preProcessScriptSource(script), filename, 1, null);
    ret = new RhinoCompiledScript(this, scr);
  } catch (Exception e) {
    if (DEBUG) e.printStackTrace();
    throw new ScriptException(e);
  } finally {
    Context.exit();
  }
  return ret;
}

代码示例来源:origin: com.google.code.scriptengines/scriptengines-javascript

public CompiledScript compile(java.io.Reader script) throws ScriptException {
  CompiledScript ret = null;
  Context cx = enterContext();
  
  try {
    String filename = (String) get(ScriptEngine.FILENAME);
    if (filename == null) {
      filename = "<Unknown Source>";
    }
    
    Scriptable scope = getRuntimeScope(context);
    Script scr = cx.compileReader(scope, preProcessScriptSource(script), filename, 1, null);
    ret = new RhinoCompiledScript(this, scr);
  } catch (Exception e) {
    if (DEBUG) e.printStackTrace();
    throw new ScriptException(e);
  } finally {
    cx.exit();
  }
  return ret;
}

相关文章

微信公众号

Context类方法