當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptObjectMirror.call方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:20,代碼來源:Script.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:WithObject.java


注:本文中的jdk.nashorn.api.scripting.ScriptObjectMirror.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。