com.cj.jshintmojo.util.Rhino Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jshint-maven-plugin Show documentation
Show all versions of jshint-maven-plugin Show documentation
a maven mojo that integrates the 'jshint' javascript preprocessor
package com.cj.jshintmojo.util;
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 eval(String code){
return (T) cx.evaluateString(scope, code, "", 1, null);
}
public 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);
}
}