当前位置: 首页>>代码示例>>Java>>正文


Java Function.call方法代码示例

本文整理汇总了Java中org.mozilla.javascript.Function.call方法的典型用法代码示例。如果您正苦于以下问题:Java Function.call方法的具体用法?Java Function.call怎么用?Java Function.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.Function的用法示例。


在下文中一共展示了Function.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptSignature

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
    Context context = Context.enter();
    context.setOptimizationLevel(-1);
    Object result;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        throw new DecryptException("could not get decrypt signature", e);
    } finally {
        Context.exit();
    }
    return result == null ? "" : result.toString();
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:17,代码来源:YoutubeStreamExtractor.java

示例2: read_file

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
public SheetJSFile read_file(String filename) throws IOException, ObjectNotFoundException {
	/* open file */
	String d = JSHelper.read_file(filename);

	/* options argument */
	NativeObject q = (NativeObject)this.cx.evaluateString(this.scope, "q = {'type':'binary'};", "<cmd>", 2, null);

	/* set up function arguments */
	Object functionArgs[] = {d, q};

	/* call read -> wb workbook */
	Function readfunc = (Function)JSHelper.get_object("XLSX.read",this.scope);
	NativeObject wb = (NativeObject)readfunc.call(this.cx, this.scope, this.nXLSX, functionArgs);

	return new SheetJSFile(wb, this);
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:17,代码来源:SheetJS.java

示例3: call

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * Calls JavaScript native function.
 * 
 * @param function Function to be called.
 * @param args Call arguments.
 */
public static void call(final Function function, final Object... args) {
	Scriptable scope = function.getParentScope();
	ObjectTopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope);
	if (topLevel != null) {
		Context cx = topLevel.getBrowserScriptEngine().enterContext();
		try {
			function.call(cx, scope, scope, args);
		} catch (Exception ex) {
			try {
				JavaScriptEngine.throwWrappedScriptException(ex);
			} catch (ScriptException e) {
				throw new WrappedException(e);
			}
		} finally {
			Context.exit();
		}
	}
}
 
开发者ID:jutils,项目名称:jsen-js,代码行数:25,代码来源:HostedJavaMethod.java

示例4: executeReadyStateChange

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * Execute ready state change.
 */
private void executeReadyStateChange() {
	// Not called in GUI thread to ensure consistency of readyState.
	try {
		Function f = XMLHttpRequest.this.getOnreadystatechange();
		if (f != null) {
			Context ctx = Executor.createContext(this.codeSource, this.pcontext);
			try {
				Scriptable newScope = (Scriptable) JavaScript.getInstance().getJavascriptObject(XMLHttpRequest.this,
						this.scope);
				f.call(ctx, newScope, newScope, new Object[0]);
			} finally {
				Context.exit();
			}
		}
	} catch (Exception err) {
		logger.error("Error processing ready state change.", err);
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:22,代码来源:XMLHttpRequest.java

示例5: executeFunction

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * Execute function.
 *
 * @param thisScope
 *            the this scope
 * @param f
 *            the f
 * @param codeSource
 *            the code source
 * @param ucontext
 *            the ucontext
 * @return true, if successful
 */
public static boolean executeFunction(Scriptable thisScope, Function f, URL codeSource, UserAgentContext ucontext) {
	Context ctx = createContext(codeSource, ucontext);
	try {
		try {
			Object result = f.call(ctx, thisScope, thisScope, new Object[0]);
			if (!(result instanceof Boolean)) {
				return true;
			}
			return ((Boolean) result).booleanValue();
		} catch (Throwable err) {
			err.getCause();
			return true;
		}
	} finally {
		Context.exit();
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:31,代码来源:Executor.java

示例6: callFunction

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * call a JS function and return its result as Object
 * 
 * @param functionName
 * @param args
 * @throws ScriptException
 * @return
 */
private Object callFunction(String functionName, Object[] args) throws ScriptException {
	
	Object functionObj = scope.get(functionName, scope);
	if (!(functionObj instanceof Function)) {
		throw new ScriptException(functionName+ " is undefined or not a function");
	}
	Function func = (Function)functionObj;
	
	try {
		Object result = func.call(ctx, scope, scope, args);
		// LOGGER.info("Call to javascript function "+functionName+" returned "+result.toString());
		return result;
	} catch (RhinoException e) {
		throw makeScriptException(e);
	}
}
 
开发者ID:geops,项目名称:trafimage-geoserver-transformations,代码行数:25,代码来源:Script.java

示例7: callJavaScriptFunction

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * Call JavaScript functions with an argument array.
 * 
 * @param f
 *            The function to be executed
 * @param oaArgs
 *            The Java object arguments passed to the function being
 *            executed
 */
private Object callJavaScriptFunction( Function f, Object[] oaArgs )
		throws CrosstabException

{
	final Context cx = Context.enter( );
	Object oReturnValue = null;
	try
	{
		oReturnValue = f.call( cx, scope, scope, oaArgs );
	}
	catch ( RhinoException ex )
	{
		throw convertException( ex );
	}
	finally
	{
		Context.exit( );
	}
	return oReturnValue;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:30,代码来源:CrosstabScriptHandler.java

示例8: executeSimpleHandlerCore

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
protected void executeSimpleHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
	handlerName = "on" + handlerType;

	Engine.logBeans.trace("(Transaction) Searching the " + handlerType + " handler (" + handlerName + ")");
	Object object = scope.get(handlerName, scope);
	Engine.logBeans.trace("(Transaction) Rhino returned: [" + object.getClass().getName() + "] " + object.toString());
       
	if (!(object instanceof Function)) {
		Engine.logBeans.debug("(Transaction) No " + handlerType + " handler (" + handlerName + ") found");
		return;
	}
	else {
		Engine.logBeans.debug("(Transaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
	}

	function = (Function) object;

	Object returnedValue = function.call(myJavascriptContext, scope, scope, null);
	if (returnedValue instanceof org.mozilla.javascript.Undefined) {
		handlerResult = "";
	}
	else {
		handlerResult = returnedValue.toString();
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:26,代码来源:Transaction.java

示例9: runScript

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例10: load

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * load
 * @param response
 */
public void load( WebResponse response ) {
		Function onLoadEvent=null;
    try {
        Context context = Context.enter();
        context.initStandardObjects( null );

        HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument();
        if (!(htmlDocument instanceof HTMLDocumentImpl)) return;

        HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody();
        if (body == null) return;
        onLoadEvent = body.getOnloadEvent();
        if (onLoadEvent == null) return;
        onLoadEvent.call( context, body, body, new Object[0] );
    } catch (JavaScriptException e) {
    	ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString());
    	// HttpUnitUtils.handleException(e);
    } catch (EcmaError ee) {
    	//throw ee;
    	ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString());        	
    } finally {
        Context.exit();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:DomBasedScriptingEngineFactory.java

示例11: invokeFunction

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
public void invokeFunction(String name, Object... parameters) {
    Function func = (Function) globalScope.get(name, globalScope);

    if(func != null) {
        Context.enter();
        try {
            func.call(context, globalScope, globalScope, parameters);
        } catch (EcmaError err) {
            KakaoManager.getInstance().receiveError(err);
        }
        String params = "";
        int i = 0;
        for(Object p : parameters) {
            i++;
            params += " -> " + String.valueOf(p);
            if(i != parameters.length) {
                params += "\n";
            }
        }

        Logger.Log log = new Logger.Log();
        log.type = Logger.Type.APP;
        log.title = "call \"" + name + "\"";
        log.index = "parameters\n" + params;

        Logger.getInstance().add(log);
    }
}
 
开发者ID:Su-Yong,项目名称:NewKakaoBot,代码行数:29,代码来源:ScriptEngine.java

示例12: callJsFunction

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
public void callJsFunction(String name, Object... params) {
    Object obj = getJsFunction(name);
    if (obj instanceof Function) {
        Function function = (Function) obj;
        // NativeObject result = (NativeObject)
        function.call(rhino, scope, scope, params);
        processResult(RESULT_OK, "");
    }
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:10,代码来源:AppRunnerInterpreter.java

示例13: decipherKey

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
/**
 * After finding the decrypted code in the js html5 player code
 * run the code passing the encryptedSig parameter
 *
 * @param encryptedSig
 * @param html5player
 * @return
 * @throws Exception
 */
private static String decipherKey(String encryptedSig, String html5player)
        throws Exception {
    String decipherFunc = loadFunction(html5player);
    Context context = Context.enter();
    // Rhino interpreted mode
    context.setOptimizationLevel(-1);
    Object result = null;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decipherFunc, "decipherFunc", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Context.exit();
    }
    if (result == null) {
        return "";
    } else {
        return result.toString();
    }
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:33,代码来源:YoutubeLinkRetriever.java

示例14: evaluate

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
@Override
public String evaluate(Script script, String func, Object[] args) {
	String resultStr = "";

	try {
		rhino.evaluateString(scope, script.getSourceCode(), script.getHumanName(), 1, null);
		
		Function function = (Function) scope.get(func, scope);
		Object result = function.call(rhino, scope, scope, args);

		if (result != null) {
			resultStr = result.toString();
		}

	} catch (Exception e) {
		e(e);
	}

	return resultStr;
}
 
开发者ID:nmud,项目名称:nmud-demo,代码行数:21,代码来源:JSEnvironment.java

示例15: createFields

import org.mozilla.javascript.Function; //导入方法依赖的package包/类
@Benchmark
@SuppressWarnings("unused")
void createFields(int count)
{
    Function create = (Function)ScriptableObject.getProperty(scope, "createObject");
    create.call(cx, scope, null, new Object[]{count, strings, ints});
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:8,代码来源:CaliperObjectBenchmark.java


注:本文中的org.mozilla.javascript.Function.call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。