本文整理匯總了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;
}
示例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);
}
示例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);
}