本文整理汇总了Java中org.mozilla.javascript.BaseFunction类的典型用法代码示例。如果您正苦于以下问题:Java BaseFunction类的具体用法?Java BaseFunction怎么用?Java BaseFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseFunction类属于org.mozilla.javascript包,在下文中一共展示了BaseFunction类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test0
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
/**
* ECMA 11.4.3 says that typeof on host object is Implementation-dependent
*/
public void test0() throws Exception
{
final Function f = new BaseFunction()
{
@Override
public Object call(Context _cx, Scriptable _scope, Scriptable _thisObj,
Object[] _args)
{
return _args[0].getClass().getName();
}
};
final ContextAction action = new ContextAction()
{
public Object run(final Context context)
{
final Scriptable scope = context.initStandardObjects();
scope.put("myObj", scope, f);
return context.evaluateString(scope, "typeof myObj", "test script", 1, null);
}
};
doTest("function", action);
}
示例2: isFunctionVisible
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
protected boolean isFunctionVisible(BaseFunction function) {
String name = function.getFunctionName();
String methodsString = function.toString();
Class<?>[] parameterTypes = parseMethodSignature(methodsString);
if (parameterTypes == null) {
throw new InternalException("Unable to parse method parameters for sandoboxing!");
}
Method method = null;
try {
method = wrappedObjectType.getMethod(name, parameterTypes);
} catch (Exception e) {
throw new InternalException(e);
}
return isFunctionVisible(wrappedObject, method);
}
示例3: createWebkitModulesProvider
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
private InspectorModulesProvider createWebkitModulesProvider() {
return () -> new Stetho.DefaultInspectorModulesBuilder(context).runtimeRepl(
new JsRuntimeReplFactoryBuilder(context)
.addFunction("activity", new BaseFunction() {
@Override
public Object call(org.mozilla.javascript.Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
return activityProvider.getCurrentActivity();
}
}).build()
).finish();
}
示例4: toString
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
private static String toString(Object obj) {
if (obj == null) {
return "null";
}
if (obj instanceof String) {
return (String) obj;
}
if (obj instanceof NativeJavaArray) {
Object array = ((NativeJavaArray) obj).unwrap();
int len = Array.getLength(array);
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < len; i++) {
if (i != 0) {
sb.append(",");
}
sb.append(toString(Array.get(array, i)));
}
return sb.append("]").toString();
}
if (obj instanceof BaseFunction) {
String funcName = ((BaseFunction) obj).getFunctionName();
if (StringUtils.isEmpty(funcName)) {
return "function()";
}
return "function " + funcName + "()";
}
String str = ScriptRuntime.toString(obj);
if (obj instanceof NativeArray) {
return "[" + str + "]";
}
return str;
}
示例5: getFunctionName
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
public static String getFunctionName(Function function) {
if (function instanceof BaseFunction) {
return "function " + ((BaseFunction)function).getFunctionName() + "()";
} else {
return "function ()";
}
}
示例6: setNewFieldValue
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
private void setNewFieldValue(Class<?> fieldType, Object fieldValue,
Exception exception, int recursion) {
this.fieldType = fieldType;
this.fieldValue = fieldValue;
this.fieldTypeStr = (fieldType != null) ? fieldType.getSimpleName()
: null;
this.fieldTypeStr = (fieldType == null && fieldValue != null) ? fieldValue
.getClass().getSimpleName() : this.fieldTypeStr;
if (fieldValue instanceof Function) {
if (fieldValue instanceof BaseFunction) {
BaseFunction baseFunction = (BaseFunction) fieldValue;
this.fieldValueStr = baseFunction.getFunctionName() + "()";
} else {
this.fieldValueStr = "f()";
}
} else if (fieldValue instanceof String) {
this.fieldValueStr = "\"" + (String) fieldValue + "\"";
} else if (fieldTypeStr != null) {
try {
this.fieldValueStr = (fieldValue != null) ? fieldValue
.toString() : "null";
} catch (Exception e) {
// e.printStackTrace();
this.fieldValueStr = "(exceptiono occured)";
}
}
constructObjectTree(this, fieldValue, recursion);
}
示例7: setNewFieldValue
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
private void setNewFieldValue(Class<?> fieldType, Object fieldValue, Exception exception, int recursion) {
this.fieldType = fieldType;
this.fieldValue = fieldValue;
this.fieldTypeStr = (fieldType != null)? fieldType.getSimpleName() : null;
this.fieldTypeStr = (fieldType == null && fieldValue != null)? fieldValue.getClass().getSimpleName() : this.fieldTypeStr;
if (fieldValue instanceof Function) {
if (fieldValue instanceof BaseFunction) {
BaseFunction baseFunction = (BaseFunction)fieldValue;
this.fieldValueStr = baseFunction.getFunctionName() + "()";
} else {
this.fieldValueStr = "f()";
}
} else if (fieldValue instanceof String) {
this.fieldValueStr = "\"" + (String)fieldValue + "\"";
} else if (fieldTypeStr != null) {
try {
this.fieldValueStr = (fieldValue != null)? fieldValue.toString() : "null";
} catch (Exception e) {
//e.printStackTrace();
this.fieldValueStr = "(exceptiono occured)";
}
}
constructObjectTree(this, fieldValue, recursion);
}
示例8: initFunctions
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
private void initFunctions( )
{
Method[] tmpMethods = this.getClass( ).getDeclaredMethods( );
HashMap<String, Method> methods = new LinkedHashMap<String, Method>( );
for ( int i = 0; i < tmpMethods.length; i++ )
{
Method tmpMethod = tmpMethods[i];
String methodName = tmpMethod.getName( );
// must handle special case with long parameter or polymiorphism
if ( "getReportElementByID".equals( methodName ) //$NON-NLS-1$
|| "setUserProperty".equals( methodName ) ) //$NON-NLS-1$
continue;
if ( ( tmpMethod.getModifiers( ) & Modifier.PUBLIC ) != 0 )
methods.put( methodName, tmpMethod );
}
Context.enter( );
try
{
for ( final Entry<String, Method> entry : methods.entrySet( ) )
{
this.defineProperty( entry.getKey( ), new BaseFunction( ) {
public Object call( Context cx, Scriptable scope,
Scriptable thisObj, Object[] args )
{
Object[] convertedArgs = JavascriptEvalUtil
.convertToJavaObjects( args );
try
{
Method method = entry.getValue( );
return method.invoke( ReportDesign.this,
convertedArgs );
}
catch ( Exception e )
{
throw new WrappedException( e );
}
}
}, DONTENUM );
}
}
finally
{
Context.exit( );
}
this.defineProperty( "getReportElementByID", //$NON-NLS-1$
new Function_getReportElementByID( ), DONTENUM );
this.defineProperty( "setUserProperty", //$NON-NLS-1$
new Function_setUserProperty( ), DONTENUM );
}
示例9: getIdentifier
import org.mozilla.javascript.BaseFunction; //导入依赖的package包/类
/**
*
* {@inheritDoc}
*/
@Override
public String getIdentifier(final Object entry)
{
// should be final but cannot be for sake of exception handling
String identifier;
if (entry instanceof Scriptable)
{
final Context cx = Context.enter();
try
{
final Object toString = ScriptableObject.getProperty((Scriptable) entry, "toString");
if (toString instanceof Function)
{
final Object toStringResult = ((Function) toString).call(cx, (Scriptable) entry, (Scriptable) entry, new Object[0]);
identifier = ScriptRuntime.toString(toStringResult);
}
else if (toString != Scriptable.NOT_FOUND)
{
identifier = ScriptRuntime.toString(toString);
}
else if (entry instanceof BaseFunction)
{
final String functionName = ((BaseFunction) entry).getFunctionName();
identifier = functionName != null && functionName.length() != 0 ? functionName : entry.toString();
}
else
{
identifier = entry.toString();
}
}
catch (final RhinoException ex)
{
LOGGER.debug("Exception determining entry identifier via Rhino - falling back to simple toString", ex);
identifier = entry.toString();
}
finally
{
Context.exit();
}
}
else if (entry != null)
{
identifier = entry.toString();
}
else
{
identifier = null;
}
return identifier;
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:57,代码来源:RepositoryExecuteBatchWorker.java