Skip to content

Commit

Permalink
Javet v0.9.4 (#57)
Browse files Browse the repository at this point in the history
* Added `JavetConverterConfig`
* Added `JavetEntityFunction` for `JavetObjectConverter`
* Updated `JavetObjectConverter` to allow skipping functions
* Added `getPrototype()` and `setPrototype()` to `V8Runtime`
* Changed the way that Javet libraries are deployed to be multi-process safe
  • Loading branch information
caoccao authored Jul 13, 2021
1 parent 32ff273 commit e13d5fa
Show file tree
Hide file tree
Showing 39 changed files with 1,030 additions and 243 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

.. code-block:: kotlin
implementation("com.caoccao.javet:javet:0.9.3")
implementation("com.caoccao.javet:javet:0.9.4")
Gradle Groovy DSL
^^^^^^^^^^^^^^^^^

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:0.9.3'
implementation 'com.caoccao.javet:javet:0.9.4'
Hello Javet
-----------
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "0.9.3"
version = "0.9.4"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion cpp/build.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
REM Usage for V8: build -DV8_DIR=C:\v8
REM Usage for Node: build -DNODE_DIR=C:\node
SET JAVET_VERSION=0.9.3
SET JAVET_VERSION=0.9.4
rd /s/q build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: build -DV8_DIR=~/v8
# Usage for Node: build -DNODE_DIR=~/node
JAVET_VERSION=0.9.3
JAVET_VERSION=0.9.4
rm -rf build
mkdir build
cd build
Expand Down
24 changes: 22 additions & 2 deletions cpp/jni/com_caoccao_javet_interop_V8Native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_compile
auto scriptOriginPointer = Javet::Converter::ToV8ScriptOringinPointer(
jniEnv, v8Context, mResourceName, mResourceLineOffset, mResourceColumnOffset, mScriptId, mIsWASM, mIsModule);
if (mIsModule) {
v8::ScriptCompiler::Source scriptSource(umScript, *scriptOriginPointer.get());
V8ScriptCompilerSource scriptSource(umScript, *scriptOriginPointer.get());
auto maybeLocalCompiledModule = v8::ScriptCompiler::CompileModule(v8Runtime->v8Isolate, &scriptSource);
if (v8TryCatch.HasCaught()) {
Javet::Exceptions::ThrowJavetCompilationException(jniEnv, v8Context, v8TryCatch);
Expand Down Expand Up @@ -389,7 +389,7 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_execute
auto scriptOriginPointer = Javet::Converter::ToV8ScriptOringinPointer(
jniEnv, v8Context, mResourceName, mResourceLineOffset, mResourceColumnOffset, mScriptId, mIsWASM, mIsModule);
if (mIsModule) {
v8::ScriptCompiler::Source scriptSource(umScript, *scriptOriginPointer.get());
V8ScriptCompilerSource scriptSource(umScript, *scriptOriginPointer.get());
auto maybeLocalCompiledModule = v8::ScriptCompiler::CompileModule(v8Runtime->v8Isolate, &scriptSource);
if (v8TryCatch.HasCaught()) {
Javet::Exceptions::ThrowJavetCompilationException(jniEnv, v8Context, v8TryCatch);
Expand Down Expand Up @@ -574,6 +574,15 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getProperty
}
return Javet::Converter::ToExternalV8ValueUndefined(jniEnv, v8Runtime->externalV8Runtime);
}
JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getPrototype
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
if (v8LocalObject->IsObject()) {
V8LocalValue v8ValueValue = v8LocalObject->GetPrototype();
return v8Runtime->SafeToExternalV8Value(jniEnv, v8Context, v8ValueValue);
}
return Javet::Converter::ToExternalV8ValueUndefined(jniEnv, v8Runtime->externalV8Runtime);
}

JNIEXPORT jint JNICALL Java_com_caoccao_javet_interop_V8Native_getSize
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType) {
Expand Down Expand Up @@ -1025,6 +1034,17 @@ JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_setProperty
return false;
}

JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_setPrototype
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType, jlong v8ValueHandlePrototype) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
if (v8LocalObject->IsObject()) {
auto v8PersistentObjectPrototypePointer = TO_V8_PERSISTENT_OBJECT_POINTER(v8ValueHandlePrototype);
auto v8LocalObjectPrototype = v8PersistentObjectPrototypePointer->Get(v8Context->GetIsolate());
return v8LocalObject->SetPrototype(v8Context, v8LocalObjectPrototype).ToChecked();
}
return false;
}

JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_setSourceCode
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType, jstring mSourceCode) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
Expand Down
16 changes: 16 additions & 0 deletions cpp/jni/com_caoccao_javet_interop_V8Native.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions cpp/jni/javet_resource_node.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,9,3,0
PRODUCTVERSION 0,9,3,0
FILEVERSION 0,9,4,0
PRODUCTVERSION 0,9,4,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -79,12 +79,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "caoccao.com"
VALUE "FileDescription", "caoccao.com"
VALUE "FileVersion", "0.9.3.0"
VALUE "InternalName", "libjavet-node-windows-x86_64.v.0.9.3.dll"
VALUE "FileVersion", "0.9.4.0"
VALUE "InternalName", "libjavet-node-windows-x86_64.v.0.9.4.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.0.9.3.dll"
VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.0.9.4.dll"
VALUE "ProductName", "Javet Windows"
VALUE "ProductVersion", "0.9.3.0"
VALUE "ProductVersion", "0.9.4.0"
END
END
BLOCK "VarFileInfo"
Expand Down
12 changes: 6 additions & 6 deletions cpp/jni/javet_resource_v8.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,9,3,0
PRODUCTVERSION 0,9,3,0
FILEVERSION 0,9,4,0
PRODUCTVERSION 0,9,4,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -79,12 +79,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "caoccao.com"
VALUE "FileDescription", "caoccao.com"
VALUE "FileVersion", "0.9.3.0"
VALUE "InternalName", "libjavet-v8-windows-x86_64.v.0.9.3.dll"
VALUE "FileVersion", "0.9.4.0"
VALUE "InternalName", "libjavet-v8-windows-x86_64.v.0.9.4.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.0.9.3.dll"
VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.0.9.4.dll"
VALUE "ProductName", "Javet Windows"
VALUE "ProductVersion", "0.9.3.0"
VALUE "ProductVersion", "0.9.4.0"
END
END
BLOCK "VarFileInfo"
Expand Down
1 change: 1 addition & 0 deletions cpp/jni/javet_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ using V8Platform = v8::Platform;
using V8StringUtf8Value = v8::String::Utf8Value;
using V8StringValue = v8::String::Value;
using V8TryCatch = v8::TryCatch;
using V8ScriptCompilerSource = v8::ScriptCompiler::Source;

// To Java

Expand Down
9 changes: 7 additions & 2 deletions docs/development/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ Javet packages all the libraries in a single jar file and automatically loads co
:alt: Javet Cross-platform

* Javet calculates the library file name from OS and JS runtime.
* Javet unpacks the library file from resource directory to system temporary directory.
* Javet loads the library using either default classloader or custom classloader.
* Javet unpacks the library files from resource directory to ``system_temporary_directory/javet/pid``.
* Javet loads the library files using either default classloader or custom classloader.

Multi-process Safety
--------------------

Javet is multi-process safe because it deploys the library files to ``system_temporary_directory/javet/pid`` to avoid race conditions during initialization. Also, Javet purges legacy libraries (at least 1 minute old) at the beginning of the initialization.

Memory Leak Detection
=====================
Expand Down
9 changes: 9 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
Release Notes
=============

0.9.4
-----

* Added ``JavetConverterConfig``
* Added ``JavetEntityFunction`` for ``JavetObjectConverter``
* Updated ``JavetObjectConverter`` to allow skipping functions
* Added ``getPrototype()`` and ``setPrototype()`` to ``V8Runtime``
* Changed the way that Javet libraries are deployed to be multi-process safe

0.9.3
-----

Expand Down
Binary file modified docs/resources/images/javet_cross_platform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/todo_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ TODO List

* To upgrade V8 and Node.js periodically.
* To expose more Node.js modules in Javet style.
* To polyfill V8 mode with more API.

[`Home <../README.rst>`_]
6 changes: 3 additions & 3 deletions docs/tutorial/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
</dependency>
Gradle Kotlin DSL
-----------------

.. code-block:: kotlin
implementation("com.caoccao.javet:javet:0.9.3")
implementation("com.caoccao.javet:javet:0.9.4")
Gradle Groovy DSL
-----------------

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:0.9.3'
implementation 'com.caoccao.javet:javet:0.9.4'
OS Compatibility
================
Expand Down
17 changes: 16 additions & 1 deletion docs/tutorial/object_converter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,22 @@ This process is transparent and fully automated once the converter is set to ``V
Null Safety
===========

What if the object converter meets ``null`` or ``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 and the default primitive values can be overridden. Please check out ``com.caoccao.javet.interop.converters.IJavetConverter#getDefault*`` for detail.
What if the object converter meets ``null`` or ``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 ``IJavetEntityFunction`` and ``IJavetEntityMap`` so that V8 functions and V8 maps can be precisely represented in Java.

Also, ``JavetConverterConfig`` exposes ``setSkipFunctionInObject(boolean)`` and ``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.

Circular Structure
==================
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
<name>javet</name>
<description>Javet is Java + V8 (JAVa + V + EighT). It is a way of embedding V8 in Java.</description>
<url>https://github.com/caoccao/Javet</url>
Expand All @@ -28,7 +28,7 @@
<connection>scm:git:git://github.com/caoccao/Javet.git</connection>
<developerConnection>scm:git:git@github.com:caoccao/caoccao.git</developerConnection>
<url>https://github.com/caoccao/Javet</url>
<tag>javet-0.9.3</tag>
<tag>javet-0.9.4</tag>
</scm>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion scripts/node/javet-rebuild/rebuild.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
SET NODE_LIB_FILE="..\..\..\..\..\..\build\libs\libjavet-node-windows-x86_64.v.0.9.3.lib"
SET NODE_LIB_FILE="..\..\..\..\..\..\build\libs\libjavet-node-windows-x86_64.v.0.9.4.lib"
cd %NODE_MODULE_ROOT%
call node-gyp clean
call node-gyp configure --module_name=%NODE_MODULE_NAME% --module_path=%NODE_MODULE_PATH% --node_lib_file=%NODE_LIB_FILE%
Expand Down
2 changes: 1 addition & 1 deletion scripts/node/javet-rebuild/rebuild.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
patchelf --add-needed libjavet-node-linux-x86_64.v.0.9.3.so ${NODE_MODULE_FILE}
patchelf --add-needed libjavet-node-linux-x86_64.v.0.9.4.so ${NODE_MODULE_FILE}
2 changes: 1 addition & 1 deletion scripts/python/change_javet_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _update(self, relative_file_path: str, line_separator: str, *patterns: list)
logging.info(' Updated.')

def main():
change_javet_version = ChangeJavetVersion('0.9.3')
change_javet_version = ChangeJavetVersion('0.9.4')
change_javet_version.update()
return 0

Expand Down
Loading

0 comments on commit e13d5fa

Please sign in to comment.