All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cj.jshintmojo.util.Rhino Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy