public class JSFunction extends JSObject
JSObject instance.
| Modifier and Type | Method and Description |
|---|---|
JSFunction |
asFunction()
Casts the current JavaScript object to
将当前的JavaScript对象转换为JSFunction类型。 JSFunction type.
|
JSValue |
invoke(JSObject instance, java.lang.Object... args)
Executes JavaScript function and returns result of execution as
执行JavaScript函数并以JSValue返回执行结果。 JSValue.
|
java.util.concurrent.Future<JSValue> |
invokeAsync(JSObject instance, java.lang.Object... args)
Executes JavaScript function and returns result of execution as
执行JavaScript函数并以Future
Future<JSValue>.
|
boolean |
isFunction()
Indicates whether JavaScript value is a function.
指示JavaScript值是否为函数。 |
java.lang.String |
toString() |
asJavaObject, asObject, getContext, getOwnPropertyNames, getProperty, getPropertyNames, hasProperty, isJavaObject, isObject, removeProperty, setProperty, setProperty, toJSONStringasArray, asBoolean, asBooleanObject, asNumber, asNumberObject, asString, asStringObject, getBooleanValue, getNumberValue, getStringValue, isArray, isBoolean, isBooleanObject, isNull, isNumber, isNumberObject, isString, isStringObject, isUndefinedpublic JSValue invoke(JSObject instance, java.lang.Object... args)
JSValue. This method blocks current thread execution until JavaScript function finishes its execution. If JavaScript function raises an exception, then
JSFunctionException with error message that describes the reason of the exception will be thrown. Same error message will be printed in JavaScript Console. To get messages from JavaScript Console use
ConsoleListener.
instance - JavaScript object the underlying function is invoked from. Pass
null to invoke function as a global function.
-调用底层函数的JavaScript对象。将调用函数作为全局函数传递。
args - input arguments.
-输入参数。
null.
JavaScript函数执行的结果。永不归还。
JSFunctionException - when exception occurs during function execution.
java.lang.IllegalArgumentException - when
instance is a valid JavaScript object, but it belongs to a different JavaScript execution context. The
instance must be running in the same execution context as the current function.
java.lang.IllegalArgumentException - when
args parameters contain unsupported type.
java.lang.IllegalStateException - when instance is already disposed or its JavaScript execution context isn't available anymore.
public java.util.concurrent.Future<JSValue> invokeAsync(JSObject instance, java.lang.Object... args)
Future<JSValue>. This method doesn't blocks current thread execution and is invoked asynchronously changing result state depending on JavaScript function execution status. If JavaScript function executes successfully, the result status will be set to "Done" and might be checked invoking the
Future.isDone() method of the result instance. If JavaScript function execution has failed due to some reason, then the result status will be set to "Done" and might be checked invoking the
Future.isDone() method of the result instance. In this case invoking the
Future.get() method will throw the
ExecutionException containing information about the failure. The error message that describes the reason of the exception will be printed in JavaScript Console. To get messages from JavaScript Console use
ConsoleListener.
instance - JavaScript object the underlying function is invoked from. Pass
null to invoke function as a global function.
-调用底层函数的JavaScript对象。将调用函数作为全局函数传递。
args - input arguments.
-输入参数。
Future<JSValue> instance that might contain result of JavaScript function execution. Never returns
null.
实例可能包含JavaScript函数执行的结果。永不归还。
java.lang.IllegalStateException - when current context is is already disposed
java.lang.IllegalArgumentException - when the JavaScript context of the given
instance is not the same as current context
public boolean isFunction()
JSValue
true, then the value can be casted to
JSFunction type. For example:
if (value.isFunction()) {
JSFunction function = value.asFunction();
}
isFunction in class
JSValue
true when JavaScript value is a function.
当JavaScript值是一个函数时。
public JSFunction asFunction()
JSValue
JSFunction type. If the current object doesn't represent a function, the
IllegalStateException error is thrown.
asFunction in class
JSValue