public class V8Scope extends java.lang.Object implements IV8Creatable, IJavetClosable
Usage 1 without V8 runtime
try (V8Scope v8Scope = new V8Scope()) { V8ValueObject v8ValueObject = v8Scope.add(v8Runtime.createV8ValueObject()); // v8ValueObject will be closed automatically if there is an exception thrown. v8Scope.setEscapable(); // v8ValueObject will not be closed. return v8ValueObject; }
Usage 2 with V8 runtime
try (V8Scope v8Scope = v8Runtime.getV8Scope()) { V8ValueObject v8ValueObject = v8Scope.createV8ValueObject(); // v8ValueObject will be closed automatically if there is an exception thrown. v8Scope.setEscapable(); // v8ValueObject will not be closed. return v8ValueObject; }
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed
The Closed.
|
protected static java.lang.String |
ERROR_MESSAGE_V8_RUNTIME_CANNOT_BE_EMPTY
The constant ERROR_MESSAGE_V8_RUNTIME_CANNOT_BE_EMPTY.
|
protected boolean |
escapable
The Escapable.
|
protected V8Runtime |
v8Runtime
The V8 runtime.
|
protected java.util.List<V8Value> |
values
The Values.
|
Constructor and Description |
---|
V8Scope()
Instantiates a new V8 scope.
|
Modifier and Type | Method and Description |
---|---|
<T extends V8Value> |
add(T value)
Add a value.
|
void |
close() |
V8Module |
createV8Module(java.lang.String moduleName,
IV8ValueObject iV8ValueObject)
Create a V8 synthetic module.
|
V8ValueArray |
createV8ValueArray()
Create V8 value array.
|
V8ValueArrayBuffer |
createV8ValueArrayBuffer(java.nio.ByteBuffer byteBuffer)
Create V8 value array buffer from a native byte buffer.
|
V8ValueArrayBuffer |
createV8ValueArrayBuffer(int length)
Create V8 value array buffer from a given length.
|
V8ValueBigInteger |
createV8ValueBigInteger(java.math.BigInteger bigInteger)
Create V8 value big integer.
|
V8ValueBigInteger |
createV8ValueBigInteger(java.lang.String bigIntegerValue)
Create V8 value big integer.
|
V8ValueBoolean |
createV8ValueBoolean(boolean booleanValue)
Create V8 value boolean.
|
V8ValueBooleanObject |
createV8ValueBooleanObject(boolean booleanValue)
Create V8 value boolean object.
|
V8ValueDataView |
createV8ValueDataView(V8ValueArrayBuffer v8ValueArrayBuffer)
Create V8 value data view.
|
V8ValueDouble |
createV8ValueDouble(double doubleValue)
Create V8 value double.
|
V8ValueDoubleObject |
createV8ValueDoubleObject(double doubleValue)
Create V8 value double object.
|
V8ValueError |
createV8ValueError(V8ValueErrorType v8ValueErrorType,
java.lang.String message)
Create V8 value error by type and message.
|
V8ValueFunction |
createV8ValueFunction(JavetCallbackContext javetCallbackContext)
Create V8 value function.
|
V8ValueFunction |
createV8ValueFunction(java.lang.String codeString)
Create V8 value function.
|
V8ValueInteger |
createV8ValueInteger(int integerValue)
Create V8 value integer.
|
V8ValueIntegerObject |
createV8ValueIntegerObject(int intValue)
Create V8 value int object.
|
V8ValueLong |
createV8ValueLong(long longValue)
Create V8 value long.
|
V8ValueLongObject |
createV8ValueLongObject(long longValue)
Create V8 value long object.
|
V8ValueMap |
createV8ValueMap()
Create V8 value map.
|
V8ValueNull |
createV8ValueNull()
Create V8 value null.
|
V8ValueObject |
createV8ValueObject()
Create V8 value object.
|
V8ValuePromise |
createV8ValuePromise()
Create V8 value promise.
|
V8ValueProxy |
createV8ValueProxy(V8Value v8Value)
Create V8 value proxy.
|
V8ValueSet |
createV8ValueSet()
Create V8 value set.
|
V8ValueString |
createV8ValueString(java.lang.String str)
Create V8 value string.
|
V8ValueStringObject |
createV8ValueStringObject(java.lang.String str)
Create V8 value string object from string.
|
V8ValueSymbol |
createV8ValueSymbol(java.lang.String description,
boolean global)
Create V8 value symbol.
|
V8ValueTypedArray |
createV8ValueTypedArray(V8ValueReferenceType type,
int length)
Create V8 value typed array.
|
V8ValueUndefined |
createV8ValueUndefined()
Create V8 value undefined.
|
V8ValueZonedDateTime |
createV8ValueZonedDateTime(long jsTimestamp)
Create V8 value zoned date time.
|
V8ValueZonedDateTime |
createV8ValueZonedDateTime(java.time.ZonedDateTime zonedDateTime)
Create V8 value zoned date time.
|
<T extends V8Value> |
get(int index)
Gets a value by index.
|
boolean |
isClosed()
Is closed.
|
boolean |
isEscapable()
Is escapable.
|
V8Scope |
setEscapable()
Sets escapable to true.
|
V8Scope |
setEscapable(boolean escapable)
Sets escapable.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createV8ValueProxy, createV8ValueSymbol
protected static final java.lang.String ERROR_MESSAGE_V8_RUNTIME_CANNOT_BE_EMPTY
protected boolean closed
protected boolean escapable
protected V8Runtime v8Runtime
protected java.util.List<V8Value> values
public <T extends V8Value> T add(T value)
T
- the type parametervalue
- the valuepublic void close() throws JavetException
close
in interface IJavetClosable
close
in interface java.lang.AutoCloseable
JavetException
public V8Module createV8Module(java.lang.String moduleName, IV8ValueObject iV8ValueObject) throws JavetException
IV8Creatable
createV8Module
in interface IV8Creatable
moduleName
- the module nameiV8ValueObject
- the V8 value object to be exportedJavetException
- the javet exceptionpublic V8ValueArray createV8ValueArray() throws JavetException
IV8Creatable
createV8ValueArray
in interface IV8Creatable
JavetException
- the javet exceptionpublic V8ValueArrayBuffer createV8ValueArrayBuffer(int length) throws JavetException
IV8Creatable
createV8ValueArrayBuffer
in interface IV8Creatable
length
- the lengthJavetException
- the javet exceptionpublic V8ValueArrayBuffer createV8ValueArrayBuffer(java.nio.ByteBuffer byteBuffer) throws JavetException
IV8Creatable
createV8ValueArrayBuffer
in interface IV8Creatable
byteBuffer
- the byte bufferJavetException
- the javet exceptionpublic V8ValueBigInteger createV8ValueBigInteger(java.math.BigInteger bigInteger) throws JavetException
IV8Creatable
createV8ValueBigInteger
in interface IV8Creatable
bigInteger
- the big integerJavetException
- the javet exceptionpublic V8ValueBigInteger createV8ValueBigInteger(java.lang.String bigIntegerValue) throws JavetException
IV8Creatable
createV8ValueBigInteger
in interface IV8Creatable
bigIntegerValue
- the big integer valueJavetException
- the javet exceptionpublic V8ValueBoolean createV8ValueBoolean(boolean booleanValue) throws JavetException
IV8Creatable
createV8ValueBoolean
in interface IV8Creatable
booleanValue
- the boolean valueJavetException
- the javet exceptionpublic V8ValueBooleanObject createV8ValueBooleanObject(boolean booleanValue) throws JavetException
IV8Creatable
createV8ValueBooleanObject
in interface IV8Creatable
booleanValue
- the boolean valueJavetException
- the javet exceptionpublic V8ValueDataView createV8ValueDataView(V8ValueArrayBuffer v8ValueArrayBuffer) throws JavetException
IV8Creatable
createV8ValueDataView
in interface IV8Creatable
v8ValueArrayBuffer
- the V8 value array bufferJavetException
- the javet exceptionpublic V8ValueDouble createV8ValueDouble(double doubleValue) throws JavetException
IV8Creatable
createV8ValueDouble
in interface IV8Creatable
doubleValue
- the double valueJavetException
- the javet exceptionpublic V8ValueDoubleObject createV8ValueDoubleObject(double doubleValue) throws JavetException
IV8Creatable
createV8ValueDoubleObject
in interface IV8Creatable
doubleValue
- the double valueJavetException
- the javet exceptionpublic V8ValueError createV8ValueError(V8ValueErrorType v8ValueErrorType, java.lang.String message) throws JavetException
IV8Creatable
createV8ValueError
in interface IV8Creatable
v8ValueErrorType
- the V8 value error typemessage
- the messageJavetException
- the javet exceptionpublic V8ValueFunction createV8ValueFunction(JavetCallbackContext javetCallbackContext) throws JavetException
IV8Creatable
createV8ValueFunction
in interface IV8Creatable
javetCallbackContext
- the javet callback contextJavetException
- the javet exceptionpublic V8ValueFunction createV8ValueFunction(java.lang.String codeString) throws JavetException
IV8Creatable
createV8ValueFunction
in interface IV8Creatable
codeString
- the code stringJavetException
- the javet exceptionpublic V8ValueInteger createV8ValueInteger(int integerValue) throws JavetException
IV8Creatable
createV8ValueInteger
in interface IV8Creatable
integerValue
- the integer valueJavetException
- the javet exceptionpublic V8ValueIntegerObject createV8ValueIntegerObject(int intValue) throws JavetException
IV8Creatable
createV8ValueIntegerObject
in interface IV8Creatable
intValue
- the int valueJavetException
- the javet exceptionpublic V8ValueLong createV8ValueLong(long longValue) throws JavetException
IV8Creatable
createV8ValueLong
in interface IV8Creatable
longValue
- the long valueJavetException
- the javet exceptionpublic V8ValueLongObject createV8ValueLongObject(long longValue) throws JavetException
IV8Creatable
createV8ValueLongObject
in interface IV8Creatable
longValue
- the long valueJavetException
- the javet exceptionpublic V8ValueMap createV8ValueMap() throws JavetException
IV8Creatable
createV8ValueMap
in interface IV8Creatable
JavetException
- the javet exceptionpublic V8ValueNull createV8ValueNull()
IV8Creatable
createV8ValueNull
in interface IV8Creatable
public V8ValueObject createV8ValueObject() throws JavetException
IV8Creatable
createV8ValueObject
in interface IV8Creatable
JavetException
- the javet exceptionpublic V8ValuePromise createV8ValuePromise() throws JavetException
IV8Creatable
createV8ValuePromise
in interface IV8Creatable
JavetException
- the javet exceptionpublic V8ValueProxy createV8ValueProxy(V8Value v8Value) throws JavetException
IV8Creatable
createV8ValueProxy
in interface IV8Creatable
v8Value
- the V8 valueJavetException
- the javet exceptionpublic V8ValueSet createV8ValueSet() throws JavetException
IV8Creatable
createV8ValueSet
in interface IV8Creatable
JavetException
- the javet exceptionpublic V8ValueString createV8ValueString(java.lang.String str) throws JavetException
IV8Creatable
createV8ValueString
in interface IV8Creatable
str
- the strJavetException
- the javet exceptionpublic V8ValueStringObject createV8ValueStringObject(java.lang.String str) throws JavetException
IV8Creatable
createV8ValueStringObject
in interface IV8Creatable
str
- the strJavetException
- the javet exceptionpublic V8ValueSymbol createV8ValueSymbol(java.lang.String description, boolean global) throws JavetException
IV8Creatable
createV8ValueSymbol
in interface IV8Creatable
description
- the descriptionglobal
- the globalJavetException
- the javet exceptionpublic V8ValueTypedArray createV8ValueTypedArray(V8ValueReferenceType type, int length) throws JavetException
IV8Creatable
createV8ValueTypedArray
in interface IV8Creatable
type
- the typelength
- the lengthJavetException
- the javet exceptionpublic V8ValueUndefined createV8ValueUndefined()
IV8Creatable
createV8ValueUndefined
in interface IV8Creatable
public V8ValueZonedDateTime createV8ValueZonedDateTime(long jsTimestamp) throws JavetException
IV8Creatable
createV8ValueZonedDateTime
in interface IV8Creatable
jsTimestamp
- the js timestampJavetException
- the javet exceptionpublic V8ValueZonedDateTime createV8ValueZonedDateTime(java.time.ZonedDateTime zonedDateTime) throws JavetException
IV8Creatable
createV8ValueZonedDateTime
in interface IV8Creatable
zonedDateTime
- the zoned date timeJavetException
- the javet exceptionpublic <T extends V8Value> T get(int index)
T
- the type parameterindex
- the indexpublic boolean isClosed()
IJavetClosable
isClosed
in interface IJavetClosable
public boolean isEscapable()
public V8Scope setEscapable()
public V8Scope setEscapable(boolean escapable)
escapable
- the escapable