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


Java Context.jsToJava方法代碼示例

本文整理匯總了Java中org.mozilla.javascript.Context.jsToJava方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.jsToJava方法的具體用法?Java Context.jsToJava怎麽用?Java Context.jsToJava使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mozilla.javascript.Context的用法示例。


在下文中一共展示了Context.jsToJava方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: jsToJava

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
static Object jsToJava(final Object obj) {
    if (obj instanceof Scriptable) {
        final Object javaObj = Context.jsToJava(obj, Object.class);
        if (javaObj instanceof NativeArray) {
            return new ScriptableList((NativeArray) javaObj);
        }
        if (javaObj instanceof Scriptable) {
            return new ScriptableMap((Scriptable) javaObj);
        }
        return javaObj;
    }
    if (obj instanceof Wrapper) {
        return ((Wrapper) obj).unwrap();
    }
    if (obj == Scriptable.NOT_FOUND) {
        return null;
    }
    return obj;
}
 
開發者ID:szegedi,項目名稱:spring-web-jsflow,代碼行數:20,代碼來源:ScriptableConverter.java

示例2: call

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
        Object[] args)
{
    if(args == null || args.length < 1) {
        throw ScriptRuntime.throwError(cx, scope,
                "require() needs one argument");
    }

    String id = (String)Context.jsToJava(args[0], String.class);
    URI uri = null;
    URI base = null;
    if (id.startsWith("./") || id.startsWith("../")) {
        if (!(thisObj instanceof ModuleScope)) {
            throw ScriptRuntime.throwError(cx, scope,
                    "Can't resolve relative module ID \"" + id +
                            "\" when require() is used outside of a module");
        }

        ModuleScope moduleScope = (ModuleScope) thisObj;
        base = moduleScope.getBase();
        URI current = moduleScope.getUri();
        uri = current.resolve(id);

        if (base == null) {
            // calling module is absolute, resolve to absolute URI
            // (but without file extension)
            id = uri.toString();
        } else {
            // try to convert to a relative URI rooted on base
            id = base.relativize(current).resolve(id).toString();
            if (id.charAt(0) == '.') {
                // resulting URI is not contained in base,
                // throw error or make absolute depending on sandbox flag.
                if (sandboxed) {
                    throw ScriptRuntime.throwError(cx, scope,
                        "Module \"" + id + "\" is not contained in sandbox.");
                } else {
                    id = uri.toString();
                }
            }
        }
    }
    return getExportedModuleInterface(cx, id, uri, base, false);
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:46,代碼來源:Require.java

示例3: call

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
        Object[] args)
{
    if(args == null || args.length < 1) {
        throw ScriptRuntime.throwError(cx, scope, 
                "require() needs one argument");
    }

    String id = (String)Context.jsToJava(args[0], String.class);
    URI uri = null;
    if (id.startsWith("./") || id.startsWith("../")) {
        if (!(thisObj instanceof ModuleScope)) {
            throw ScriptRuntime.throwError(cx, scope,
                    "Can't resolve relative module ID \"" + id +
                            "\" when require() is used outside of a module");
        }

        ModuleScope moduleScope = (ModuleScope) thisObj;
        URI base = moduleScope.getBase();
        URI current = moduleScope.getUri();

        if (base == null) {
            // calling module is absolute, resolve to absolute URI
            // (but without file extension)
            uri = current.resolve(id);
            id = uri.toString();
        } else {
            // try to convert to a relative URI rooted on base
            id = base.relativize(current).resolve(id).toString();
            if (id.charAt(0) == '.') {
                // resulting URI is not contained in base,
                // throw error or make absolute depending on sandbox flag.
                if (sandboxed) {
                    throw ScriptRuntime.throwError(cx, scope,
                        "Module \"" + id + "\" is not contained in sandbox.");
                } else {
                    uri = current.resolve(id);
                    id = uri.toString();
                }
            }
        }
    }
    return getExportedModuleInterface(cx, id, uri, false);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:45,代碼來源:Require.java


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