use of org.mozilla.javascript.Function in project Osmand by osmandapp.
the class JsCommandBuilder method callVoidJsFunction.
private void callVoidJsFunction(Object function, Object[] params) {
if (function instanceof Function) {
Function jsFunction = (Function) function;
jsFunction.call(jsContext, jsScope, jsScope, params);
}
}
use of org.mozilla.javascript.Function in project candlepin by candlepin.
the class JsRunner method init.
/**
* initialize the javascript rules for the provided namespace. you must run
* this
* before trying to run a javascript rule or method.
*
* @param namespace the javascript rules namespace containing the rules type
* you want
*/
public void init(String namespace) {
this.namespace = namespace;
if (!initialized) {
Context context = Context.enter();
try {
Object func = ScriptableObject.getProperty(scope, namespace);
this.rulesNameSpace = unwrapReturnValue(((Function) func).call(context, scope, scope, Context.emptyArgs));
this.initialized = true;
} catch (RhinoException ex) {
this.initialized = false;
throw new RuleParseException(ex);
} finally {
Context.exit();
}
}
}
use of org.mozilla.javascript.Function in project convertigo by convertigo.
the class Transaction method executeSimpleHandlerCore.
protected void executeSimpleHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
handlerName = "on" + handlerType;
Engine.logBeans.trace("(Transaction) Searching the " + handlerType + " handler (" + handlerName + ")");
Object object = scope.get(handlerName, scope);
Engine.logBeans.trace("(Transaction) Rhino returned: [" + object.getClass().getName() + "] " + object.toString());
if (!(object instanceof Function)) {
Engine.logBeans.debug("(Transaction) No " + handlerType + " handler (" + handlerName + ") found");
return;
} else {
Engine.logBeans.debug("(Transaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
}
function = (Function) object;
Object returnedValue = function.call(myJavascriptContext, scope, scope, null);
if (returnedValue instanceof org.mozilla.javascript.Undefined) {
handlerResult = "";
} else {
handlerResult = returnedValue.toString();
}
}
use of org.mozilla.javascript.Function in project convertigo by convertigo.
the class RequestableObject method synchronize.
public static Object synchronize(org.mozilla.javascript.Context cx, Scriptable thisObj, Object[] args, Function funObj) {
if (args.length < 2) {
return null;
}
Object lock = ((NativeJavaObject) args[0]).unwrap();
Function fun = (Function) args[1];
Object res;
synchronized (lock) {
res = fun.call(cx, thisObj, thisObj, null);
}
return res;
}
use of org.mozilla.javascript.Function in project convertigo by convertigo.
the class UIDynamicElement method getFormatedLabel.
protected String getFormatedLabel() {
if (ionBean != null) {
String source = ionBean.getDisplayFormat();
if (!source.isEmpty()) {
String sourceName = "displayFormat", message = null;
Context javascriptContext = org.mozilla.javascript.Context.enter();
Scriptable scope = javascriptContext.initStandardObjects(null);
for (IonProperty property : ionBean.getProperties().values()) {
String p_name = property.getName();
// Object p_value = property.getValue();
String smartValue = property.getSmartType().getLabel().replace("{{", "").replace("}}", "").replace("?.", ".");
Scriptable jsObject = ((smartValue == null) ? null : org.mozilla.javascript.Context.toObject(smartValue, scope));
scope.put(p_name, scope, jsObject);
}
try {
Object ob = RhinoUtils.evalInterpretedJavascript(javascriptContext, scope, source, sourceName, 1, null);
if (ob instanceof Function) {
Object returnedValue = ((Function) ob).call(javascriptContext, scope, scope, new Object[] {});
return returnedValue.toString();
}
} catch (EcmaError e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript runtime error has occured at line " + e.lineNumber() + ", column " + e.columnNumber() + ": " + e.getMessage() + " \n" + e.lineSource();
} catch (EvaluatorException e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript evaluation error has occured: " + e.getMessage();
} catch (JavaScriptException e) {
message = "Unable to evaluate code for '" + sourceName + "'.\n" + "UIDynamicElement: \"" + getName() + "\"\n" + "A Javascript error has occured: " + e.getMessage();
} finally {
if (javascriptContext != null) {
org.mozilla.javascript.Context.exit();
}
if (message != null) {
System.out.println(message);
Engine.logBeans.warn(message);
}
}
}
}
return null;
}
Aggregations