@Retention(value=CLASS) @Target(value={METHOD,CONSTRUCTOR}) public @interface JavaScriptBody
Visit an on-line demo
to play with JavaScriptBody
annotation for real.
Modifier and Type | Required Element and Description |
---|---|
String[] |
args
Names of parameters for the method generated method that can
be referenced from
JavaScriptBody.body() . |
String |
body
The actual body of the method in JavaScript.
|
Modifier and Type | Optional Element and Description |
---|---|
boolean |
javacall
Should a special syntax for calling back into Java object be turned on?
|
boolean |
keepAlive
Controls garbage collection behavior of method parameters.
|
boolean |
wait4js
Should we wait before the JavaScript snippet execution finishes?
|
public abstract String[] args
JavaScriptBody.body()
.public abstract String body
this
.JavaScriptBody.args()
and possibly
this
public abstract boolean javacall
@
followed by fully qualified
package name of the class. Now followed by :: and a method in
the class followed by its parameters enclosed inside (...).
This is the syntax one can use to call run()
method of Runnable
:
r.@java.lang.Runnable::run()(). One can also call static methods. Just use:
var ten = @java.lang.Integer::parseInt(Ljava/lang/String;)("10")
public abstract boolean wait4js
Some implementations that recognize the JavaScriptBody
annotation
need to reschedule the JavaScript execution into different thread and
then it is easier for them to perform the execution asynchronously
and not wait for the result of the execution. This may however be
unexpected (for example when one awaits a callback into Java)
and as such it has to be explicitly allowed by specifying
wait4js = false
. Such methods need to return void
.
Implementations that execute the JavaScript synchronously may ignore this attribute.
Implementations that delay execution of JavaScript need to guarantee the order of snippets. Those that were submitted sooner, need to be executed sooner. Each snippet need to be executed in a timely manner (e.g. by a second, or so) even if there are no other calls made in the main program.
false
in case one allows asynchronous execution
of the JavaScript snippetpublic abstract boolean keepAlive
WebView
),
in some systems this information is not important (like the
Bck2Brwsr VM running
all in JavaScript), but other execution systems just can't find that
out. To prevent memory leaks on such systems and help them manage
memory more effectively, those who define JavaScript interfacing
methods may indicate whether the non-primitive parameters passed
in should be hold only for the time of method invocation or
for the whole application lifetime.
The default value is true
as that is compatible with
previous behavior and also prevents unwanted surprises when something
garbage collects pre-maturaly. Framework developers are however
encouraged to use keepAlive=false
as much as possible.
Copyright © 2018 NetBeans. All rights reserved.