本文整理汇总了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.call方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObjectMirror.call方法的具体用法?Java ScriptObjectMirror.call怎么用?Java ScriptObjectMirror.call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.api.scripting.ScriptObjectMirror
的用法示例。
在下文中一共展示了ScriptObjectMirror.call方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evalFunctionCall
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
public static ScriptValue evalFunctionCall(ScriptObjectMirror som, Object callArg, ScriptContext context) {
// injects the 'karate' variable into the js function body
// also ensure that things like 'karate.get' operate on the latest variable state
som.setMember(ScriptBindings.KARATE, context.bindings.bridge);
Object result;
try {
if (callArg != null) {
result = som.call(som, callArg);
} else {
result = som.call(som);
}
return new ScriptValue(result);
} catch (Exception e) {
String message = "javascript function call failed: " + e.getMessage();
context.logger.error(message);
context.logger.error("failed function body: " + som);
throw new KarateException(message);
}
}
示例2: bindToExpression
import jdk.nashorn.api.scripting.ScriptObjectMirror; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static Object bindToExpression(final Object fn, final Object receiver) {
if (fn instanceof ScriptFunction) {
return bindToExpression((ScriptFunction) fn, receiver);
} else if (fn instanceof ScriptObjectMirror) {
final ScriptObjectMirror mirror = (ScriptObjectMirror)fn;
if (mirror.isFunction()) {
// We need to make sure correct 'this' is used for calls with Ident call
// expressions. We do so here using an AbstractJSObject instance.
return new AbstractJSObject() {
@Override
public Object call(final Object thiz, final Object... args) {
return mirror.call(withFilterExpression(receiver), args);
}
};
}
}
return fn;
}