public final class QuickJs
extends java.lang.Object
implements java.io.Closeable
This class is NOT thread safe. If multiple threads access an instance concurrently it must be externally.
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Release the native resources associated with this object.
|
byte[] |
compile(java.lang.String sourceCode,
java.lang.String fileName)
Compile
sourceCode and return the bytecode. |
static QuickJs |
create()
Create a new interpreter instance.
|
java.lang.Object |
evaluate(java.lang.String script)
Evaluate
script and return a result. |
java.lang.Object |
evaluate(java.lang.String script,
java.lang.String fileName)
Evaluate
script and return any result. |
java.lang.Object |
execute(byte[] bytecode)
Load and execute
bytecode and return the result. |
protected void |
finalize() |
<T> T |
get(java.lang.String name,
java.lang.Class<T> type)
Attaches to a global JavaScript object called
name that implements type. |
<T> void |
set(java.lang.String name,
java.lang.Class<T> type,
T object)
Provides
object to JavaScript as a global object called name. |
@NonNull public static QuickJs create()
close() on the returned instance to avoid leaking native memory.@Nullable
public java.lang.Object evaluate(@NonNull
java.lang.String script,
@NonNull
java.lang.String fileName)
script and return any result. fileName will be used in error
reporting.QuickJsException - if there is an error evaluating the script.@Nullable
public java.lang.Object evaluate(@NonNull
java.lang.String script)
script and return a result.QuickJsException - if there is an error evaluating the script.public <T> void set(@NonNull
java.lang.String name,
@NonNull
java.lang.Class<T> type,
@NonNull
T object)
object to JavaScript as a global object called name. type
defines the interface implemented by object that will be accessible to JavaScript.
type must be an interface that does not extend any other interfaces, and cannot define
any overloaded methods.
Methods of the interface may return void or any of the following supported argument
types: boolean, Boolean, int, Integer, double,
Double, String.
@NonNull
public <T> T get(@NonNull
java.lang.String name,
@NonNull
java.lang.Class<T> type)
name that implements type.
type defines the interface implemented in JavaScript that will be accessible to Java.
type must be an interface that does not extend any other interfaces, and cannot define
any overloaded methods.
Methods of the interface may return void or any of the following supported argument
types: boolean, Boolean, int, Integer, double,
Double, String.
@NonNull
public byte[] compile(@NonNull
java.lang.String sourceCode,
@NonNull
java.lang.String fileName)
sourceCode and return the bytecode. fileName will be used in error
reporting.QuickJsException - if the sourceCode could not be compiled.@Nullable
public java.lang.Object execute(@NonNull
byte[] bytecode)
bytecode and return the result.QuickJsException - if there is an error loading or executing the code.public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableprotected void finalize()
finalize in class java.lang.Object