本文整理汇总了Java中org.mozilla.javascript.Callable类的典型用法代码示例。如果您正苦于以下问题:Java Callable类的具体用法?Java Callable怎么用?Java Callable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Callable类属于org.mozilla.javascript包,在下文中一共展示了Callable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.mozilla.javascript.Callable; //导入依赖的package包/类
/**
* @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable)
*/
public Object get(String name, Scriptable start)
{
// get the property from the underlying QName map
if ("length".equals(name))
{
return this.size();
}
else if ("hasOwnProperty".equals(name))
{
return new Callable()
{
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
{
return (args.length > 0 ? hasOwnProperty(args[0]) : null);
}
};
}
else
{
return get(name);
}
}
示例2: testJsApi
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
}
示例3: testJsApi
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
Context cx = RhinoAndroidHelper.prepareContext();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileString(TestUtils.readAsset("Bug482203.js"),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
int counter = 0;
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
counter++;
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
assertEquals(counter, 5);
assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
} finally {
Context.exit();
}
}
示例4: 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);
}
}
示例5: testJsApi
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203Test.class.getResourceAsStream("Bug482203.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
int counter = 0;
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
counter++;
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
assertEquals(counter, 5);
assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
} finally {
Context.exit();
}
}
示例6: initializeFunctions
import org.mozilla.javascript.Callable; //导入依赖的package包/类
protected void initializeFunctions() {
functions = new HashMap<>();
functions.put("contains", new Callable() {
@Override
public Object call(Context context, Scriptable scope, Scriptable thisObject, Object[] args) {
if (args==null || args.length!=2 || args[0]==null) {
return false;
}
if (args[0] instanceof String) {
return ((String)args[0]).contains((CharSequence) args[1]);
}
if (args[0] instanceof Collection) {
return ((Collection)args[0]).contains(args[1]);
}
return false;
}
});
}
示例7: 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;
}
示例8: doTopCall
import org.mozilla.javascript.Callable; //导入依赖的package包/类
/**
* Execute top call to script or function. When the runtime is about to
* execute a script or function that will create the first stack frame
* with scriptable code, it calls this method to perform the real call.
* In this way execution of any script happens inside this function.
*/
@Override
protected Object doTopCall(final Callable callable,
final Context cx, final Scriptable scope,
final Scriptable thisObj, final Object[] args) {
AccessControlContext accCtxt = null;
Scriptable global = ScriptableObject.getTopLevelScope(scope);
Scriptable globalProto = global.getPrototype();
if (globalProto instanceof RhinoTopLevel) {
accCtxt = ((RhinoTopLevel) globalProto).getAccessContext();
}
if (accCtxt != null) {
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return superDoTopCall(callable, cx, scope, thisObj, args);
}
}, accCtxt);
} else {
return superDoTopCall(callable, cx, scope, thisObj, args);
}
}
示例9: doTopCall
import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
if (Looper.myLooper() == Looper.getMainLooper()) {
try {
return super.doTopCall(callable, cx, scope, thisObj, args);
} catch (Exception e) {
mUiThreadExceptionHandler.uncaughtException(Thread.currentThread(), e);
return null;
}
}
return super.doTopCall(callable, cx, scope, thisObj, args);
}
示例10: doTopCall
import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable,
Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
MyContext mcx = (MyContext)cx;
mcx.quota = 2000;
return super.doTopCall(callable, cx, scope, thisObj, args);
}
示例11: makeParam
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
if(jsonObject == null) return Undefined.instance;
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
@Override
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
return objects[1];
}
});
return param;
}
示例12: makeParamArray
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
//Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() {
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() {
@Override
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
return objects[1];
}
});
return param;
}
示例13: makeParam
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
@Override
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
return objects[1];
}
});
return param;
}
示例14: get
import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object get( String name, Scriptable scope )
{
ParameterAttribute parameter = getParameterAttribute( name );
if ( FIELD_VALUE.equals( name ) )
{
return parameter.getValue( );
}
else if ( FIELD_DISPLAY_TEXT.equals( name ) )
{
return parameter.getDisplayText( );
}
Object value = parameter.getValue( );
Scriptable jsValue = Context.toObject( value, scope );
Scriptable prototype = jsValue.getPrototype( );
if( prototype != null )
{
Object property = jsValue.getPrototype( ).get( name, jsValue );
if ( property instanceof Callable )
{
Callable callable = (Callable) property;
return new JsValueCallable( callable, jsValue );
}
return jsValue.get( name, jsValue );
}
else
{
return jsValue.get( name, jsValue );
}
}
示例15: doTopCall
import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
TimeBoxedContext mcx = (TimeBoxedContext) cx;
mcx.startTime = System.currentTimeMillis();
return super.doTopCall(callable, cx, scope, thisObj, args);
}