Binding via Native#
Binding via Proxy#
What if the object converter meets
undefined when target type is primitive? This is a quite famous topic in Java because converting null to primitive type results in
java.lang.NullPointerException. Luckily, Javet object converter is null safe by injecting default primitive values to
JavetConverterConfig and these default primitive values can be overridden.
Functions and Objects#
There are few challenges in the object conversion.
V8 functions cannot be easily represented by Java objects.
V8 objects and maps cannot be easily differentiated in Java.
Sometimes unexpected functions from object conversion may break applications.
So, Javet introduced
IJavetEntityMap so that V8 functions and V8 maps can be precisely represented in Java.
setExtractFunctionSourceCode(boolean) to give application the opportunity to skip functions in objects or extract source code of functions.
If the source code is provided to a user defined function, Javet object converter will inject that function from the source code automatically. That makes sure Java object from V8 object can be smoothly converted back to V8 object at both property and function levels.
It is inefficient and inconvenient for Javet to substantially detect circular structure during object conversion. Instead, Javet converter keeps increasing the depth of recursion and throws
JavetConverterException when maximum depth is reach. Maximum depth can be changed before object conversion is started. This is a cheap operation with high performance.
Please avoid setting maximum depth to an unrealistic number because JVM will throw
StackOverflowError which brings considerable performance overhead. The thing worse than that is there will be memory leak because resource recycling logic written in
finally block sometimes won't be called when stack overflow occurs. Attackers may easily drain the server resource in minutes by sending tiny circular structure data.
When does the Config Take Effect?#
Map can be read-only in V8 when
setProxyMapEnabled(false) is called whereas the next Java
Map can be read-write in V8 when
setProxyMapEnabled(true) is called.
Can Built-in Converter be Ignored?#
Yes. One of the beauties of the built-in converter is it is convenient to bi-directionally convert arbitrary objects. However, sometimes applications want to take fine-grained control over every conversion. E.g.
a needs to use
b needs to use
No worry. Applications may use any converter to convert Java objects to
V8Value objects or vice versa. Javet API is able to accept
V8Value and return
V8Value. In this case, the built-in converter is ignored.