Package com.cj.qunit.mojo

Source Code of com.cj.qunit.mojo.Rhino

package com.cj.qunit.mojo;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;

@SuppressWarnings("unchecked")
public class Rhino {
  private final Context cx = Context.enter();
  private final Scriptable scope = cx.initStandardObjects();

  public <T> T eval(String code){
    // workaround for the 64k limit of rhino with enabled optimizations: set the Optimization Level to -1. See https://github.com/jshint/jshint/issues/1333
    cx.setOptimizationLevel(-1);
    return (T)   cx.evaluateString(scope, code, "<cmd>", 1, null);
  }
 
  public <T> T call(String functionName, Object ... args){
      Function f = getFunction(functionName);
      return (T) f.call(cx, scope, scope, args);
  }
 
  private Function getFunction(String name){
    return (Function) scope.get(name, scope);
  }
}
TOP

Related Classes of com.cj.qunit.mojo.Rhino

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.