Package com.teamdev.jxbrowser.js
Interface JsFunction
- All Superinterfaces:
JsObject
Represents a JavaScript function that can be passed between Java and JavaScript as a method
argument or a return value. The function lifetime is bound to the lifetime of the frame this
function belongs to. When the owner frame is unloaded, all the JavaScript objects are
automatically disposed. An attempt to access a disposed JavaScript object will result in
IllegalStateException
.- Since:
- 7.7
-
Method Summary
Modifier and TypeMethodDescription<T> T
Invokes this function on the givenobject
with the specifiedargs
.<T> CompletableFuture<T>
invokeAsync
(JsObject object, Object... args) Invokes this function on the givenobject
with the specifiedargs
.Methods inherited from interface com.teamdev.jxbrowser.js.JsObject
call, close, frame, hasProperty, ownPropertyNames, property, propertyNames, putProperty, removeProperty
-
Method Details
-
invoke
Invokes this function on the givenobject
with the specifiedargs
. This method blocks the current thread until the function finishes its execution. If the function raises an exception, then aJsException
with an error message that describes the exception reason will be thrown. The same error message will be printed to the JavaScript console.The rules to convert Java types into JavaScript types and vice versa are the same as for the
JsObject.call(String, Object...)
method.- Type Parameters:
T
- the result of the JavaScript function execution- Parameters:
object
- the JavaScript object to invoke this function on. Passnull
to invoke the function as a global function.args
- the list of input arguments- Throws:
JsException
- when an error occurs during the function executionIllegalArgumentException
- whenargs
contains an unsupported typeObjectClosedException
- when the JavaScript object is already disposed or invalid
-
invokeAsync
Invokes this function on the givenobject
with the specifiedargs
.This method does not block the current thread execution and executes the function asynchronously.
Returns a new
CompletableFuture
that is completed when the function finishes its execution. If the function throws an exception, the future is completed withJsException
with the same error message that will be printed to the JavaScript console. If the browser is closed during the function execution, the future will be canceled.- Type Parameters:
T
- the result of the JavaScript function execution- Parameters:
object
- the JavaScript object to invoke this function on. Passnull
to invoke the function as a global function.args
- the list of input arguments- Throws:
IllegalArgumentException
- whenargs
contains an unsupported typeObjectClosedException
- when the JavaScript object is already disposed or invalid- Since:
- 7.31
-