本文整理汇总了Java中org.mozilla.javascript.Callable.call方法的典型用法代码示例。如果您正苦于以下问题:Java Callable.call方法的具体用法?Java Callable.call怎么用?Java Callable.call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.Callable
的用法示例。
在下文中一共展示了Callable.call方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callWithDomain
import org.mozilla.javascript.Callable; //导入方法依赖的package包/类
/**
* Calls {@link Callable#call(Context, Scriptable, Scriptable, Object[])} of
* <code>callable</code> under restricted security domain where an action is
* allowed only if it is allowed according to the Java stack on the
* moment of the <code>callWithDomain</code> call and
* <code>securityDomain</code>. Any call to
* {@link #getDynamicSecurityDomain(Object)} during execution of
* {@link Callable#call(Context, Scriptable, Scriptable, Object[])}
* should return a domain incorporate restrictions imposed by
* <code>securityDomain</code>.
*/
public Object callWithDomain(Object securityDomain, final Context cx,
final Callable callable,
final Scriptable scope,
final Scriptable thisObj,
final Object[] args) {
AccessControlContext acc;
if (securityDomain instanceof AccessControlContext)
acc = (AccessControlContext)securityDomain;
else {
RhinoClassLoader loader = (RhinoClassLoader)securityDomain;
acc = loader.rhinoAccessControlContext;
}
PrivilegedExceptionAction execAction = new PrivilegedExceptionAction() {
public Object run() {
return callable.call(cx, scope, thisObj, args);
}
};
try {
return AccessController.doPrivileged(execAction, acc);
} catch (Exception e) {
throw new WrappedException(e);
}
}
示例2: callWithDomain
import org.mozilla.javascript.Callable; //导入方法依赖的package包/类
@Override
public Object callWithDomain(Object securityDomain, final Context ctx, final Callable callable,
final Scriptable scope, final Scriptable thisObj, final Object[] args) {
Object obj = null;
try {
if (securityDomain == null) {
obj = callable.call(ctx, scope, thisObj, args);
} else {
PrivilegedAction<Object> action = () -> callable.call(ctx, scope, thisObj, args);
AccessControlContext acctx = new AccessControlContext(
new ProtectionDomain[] { (ProtectionDomain) securityDomain });
return AccessController.doPrivileged(action, acctx);
}
} catch (MissingResourceException err) {
logger.error("Missing Resource");
}
return obj;
}
示例3: evaluate
import org.mozilla.javascript.Callable; //导入方法依赖的package包/类
public synchronized VMValue evaluate( String expression )
{
int currentState = debugger.currentState( );
if ( currentState == VM_TERMINATED )
{
return null;
}
JsValue result = null;
Debugger oldDebugger = cx.getDebugger( );
Object oldContextData = cx.getDebuggerContextData( );
int oldLevel = cx.getOptimizationLevel( );
cx.setDebugger( null, null );
cx.setOptimizationLevel( -1 );
cx.setGeneratingDebug( false );
try
{
Callable script = (Callable) cx.compileString( expression,
EVALUATOR_LITERAL,
0,
null );
Object val = script.call( cx,
scope,
thisObj,
ScriptRuntime.emptyArgs );
if ( val == Undefined.instance )
{
result = new JsValue( UNDEFINED_LITERAL, UNDEFINED_TYPE );
}
else
{
result = new JsValue( val );
}
}
catch ( Exception ex )
{
result = new JsValue( ex.getMessage( ), EXCEPTION_TYPE );
}
finally
{
cx.setGeneratingDebug( true );
cx.setOptimizationLevel( oldLevel );
cx.setDebugger( oldDebugger, oldContextData );
}
return result;
}