-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated document for the upcoming release. * Added project structure, gradle build config * Added lib deploy and load * Added cmake for Windows build * Added cmake Linux version * Updated build scripts * Added doc for build * Update build scripts and license * Added types: int, long, string, null, undefined * Split test cases to one type per suite * Added exceptions, lock and unlock * Updated lock * Added pre-built zip files, array length * Refactored v8 value collection and reference * Added boolean, value object, getValue, getOwnPropertyNames * Added double, zoneddatetime, fixed long * Added error object * Added containsKey, map, promise, proxy, regex, symbol, arguments * Added set, compilation exception, execution exception * Updated jni so that it consumes Object instead of int/string * Updated native lib on generic types * Added global object, set() * Added add(), delete() to V8 native * Fixed various bugs in handling types in JNI * Added support to reference object * Added protoToString() * Added callObjectFunction(), push(), pop() * Added invoke(), toJsonString() * Switched call() and invoke() to make more sense * Added keys() to Array, Set, Map; values() to Map * Added entries() to Map * Added V8VirtualList * Added createCallback() V1 * Added createCallback() V2 * Added createCallback() V3 * Added createCallback() V4 * Added createCallback() V5 * Added createCallback() V6 * Added createCallback() V7 * Added thisObject to function callback * Updated readme and few other docs * Updated V8 value close() to be lock free * Updated receiveCallback() to be more generic * Added JavetConsoleInterceptor * Added test case for global property accessor * Added decimal.js * Added V8 executors * Added test cases for ES5 and ES6 * Added Javet engine pool and test cases * Fixed 2 minor bugs * Updated logger * Removed synchronized from create and close V8 runtime * Upgraded v8 from 8.3.110.9 to 8.9.255 * Added resetContext() to V8Runtime * Fixed resetContext() in V8Runtime * Added scripts/python/change_javet_version.py * Updated reset() * Added pom.xml * Prepare for release v1 * [maven-release-plugin] prepare release javet-0.7.0 * [maven-release-plugin] prepare for next development iteration * Prepare for release v2 * [maven-release-plugin] prepare release javet-0.7.0 * [maven-release-plugin] prepare for next development iteration * [maven-release-plugin] prepare release javet-0.7.0 * [maven-release-plugin] prepare for next development iteration * [maven-release-plugin] prepare release javet-0.7.0 * [maven-release-plugin] prepare for next development iteration * [maven-release-plugin] prepare release javet-0.7.0 * [maven-release-plugin] prepare for next development iteration * Added doc for 0.7.0 Co-authored-by: Sam Cao <[email protected]>
- Loading branch information
Showing
178 changed files
with
13,294 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
Javet | ||
===== | ||
|
||
Javet is Java + V8 (JAVa + V + EighT). It is yet another way of embedding V8 in Java. It was inspired by J2V8. I'll try to keep up with latest V8 in a slow pace. If you like my work, please **Star** this project. And, you may visit http://caoccao.blogspot.com/. | ||
|
||
Latest version is **0.7.0**. | ||
|
||
Major Features | ||
============== | ||
|
||
* It supports both Windows and Linux with V8 v8.9.255. | ||
* It exposes the majority of V8 API in JVM. | ||
* It allows injecting JS functions into V8. | ||
* It supports ``BigInt <-> Long``, ``Date <-> ZonedDateTime``. | ||
* It supports Javet engine pool like DB connection pool with a huge performance improvement. | ||
|
||
Quick Start | ||
=========== | ||
|
||
Maven | ||
----- | ||
|
||
.. code-block:: xml | ||
<dependency> | ||
<groupId>com.caoccao.javet</groupId> | ||
<artifactId>javet</artifactId> | ||
<version>0.7.0</version> | ||
</dependency> | ||
Gradle Kotlin | ||
------------- | ||
|
||
.. code-block:: kotlin | ||
dependencies { | ||
implementation("com.caoccao.javet:javet:0.7.0") | ||
} | ||
Gradle Groovy | ||
------------- | ||
|
||
.. code-block:: groovy | ||
compile group: 'com.caoccao.javet', name: 'javet', version: '0.7.0' | ||
Hello Javet | ||
=========== | ||
|
||
.. code-block:: java | ||
try (V8Runtime v8Runtime = V8Host.getInstance().createV8Runtime()) { | ||
v8Runtime.lock(); | ||
System.out.println(v8Runtime.getExecutor("'Hello Javet'").executeString()); | ||
} | ||
Documents | ||
========= | ||
|
||
* `Build <docs/build.rst>`_ | ||
* `Development <docs/development.rst>`_ | ||
* `Tutorial <docs/tutorial/index.rst>`_ | ||
* `FAQ <docs/faq/index.rst>`_ | ||
* `TODO List <docs/todo_list.rst>`_ | ||
|
||
Motivation | ||
========== | ||
|
||
I used to take a try of J2V8 and find it's quite compelling. However, J2V8 is slowly dying, with serious memory leak issues, V8 version issue, etc. | ||
|
||
Sometimes starting from scratch implies lower cost than upgrading an existing solution. I think it might be true here in this project. I've learned quite a lot by manually fixing the Windows and Linux build system of J2V8. | ||
|
||
Also, I had got many ideas on how the API will look like. At the end of 2020, I thought I would be able to write a new one from scratch and leave J2V8 behind. Indeed, I made it few months later. | ||
|
||
Please refer to `History with J2V8 <docs/faq/history_with_j2v8.rst>`_ for detail. | ||
|
||
License | ||
======= | ||
|
||
Javet follows `APACHE LICENSE, VERSION 2.0 <LICENSE>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2021. caoccao.com Sam Cao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
plugins { | ||
java | ||
`java-library` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
jcenter() | ||
} | ||
|
||
group = "com.caoccao.javet" | ||
version = "0.7.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") | ||
runtimeOnly(fileTree("libs")) | ||
} | ||
|
||
afterEvaluate { | ||
tasks.withType(JavaCompile::class) { | ||
options.compilerArgs.add("-Xlint:unchecked") | ||
options.compilerArgs.add("-Xlint:deprecation") | ||
} | ||
} | ||
|
||
task<Exec>("buildJNIHeaders") { | ||
mkdir("$buildDir/generated/tmp/jni") | ||
project.exec { | ||
workingDir("$projectDir") | ||
commandLine( | ||
"javac", | ||
"-h", | ||
"cpp/jni", | ||
"-d", | ||
"$buildDir/generated/tmp/jni", | ||
"src/main/java/com/caoccao/javet/interop/V8Native.java" | ||
) | ||
} | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
if(!$ENV{JAVA_HOME}) | ||
message(FATAL_ERROR "JAVA_HOME is not found. Please make sure you have JDK 8 or 11 installed properly.") | ||
endif() | ||
|
||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE) | ||
|
||
# CMP0091 must be set before first project(). | ||
# @see: https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html | ||
if (POLICY CMP0091) | ||
cmake_policy(SET CMP0091 NEW) | ||
endif() | ||
|
||
project(Javet) | ||
aux_source_directory("jni" sourceFiles) | ||
add_library(v8_monolith STATIC IMPORTED) | ||
add_library(Javet SHARED ${sourceFiles} "jni/javet.rc") | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
|
||
set(includeDirs | ||
$ENV{JAVA_HOME}/include | ||
${V8_DIR}/include | ||
${V8_DIR}/include/libplatform) | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) | ||
list(APPEND includeDirs $ENV{JAVA_HOME}/include/win32) | ||
set_property(TARGET Javet APPEND_STRING PROPERTY LINK_FLAGS_RELEASE "") | ||
set_property(TARGET Javet PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
set_target_properties(v8_monolith PROPERTIES IMPORTED_LOCATION ${V8_DIR}/out.gn/x64.release/obj/v8_monolith.lib) | ||
set_target_properties(Javet PROPERTIES OUTPUT_NAME "libjavet-windows-x86_64.v.${JAVET_VERSION}") | ||
target_link_libraries(Javet v8_monolith DbgHelp Winmm) | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
list(APPEND includeDirs $ENV{JAVA_HOME}/include/linux) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 ") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 ") | ||
set_target_properties(v8_monolith PROPERTIES IMPORTED_LOCATION ${V8_DIR}/out.gn/x64.release/obj/libv8_monolith.a) | ||
set_target_properties(Javet PROPERTIES OUTPUT_NAME "javet-linux-x86_64.v.${JAVET_VERSION}") | ||
target_link_libraries(Javet v8_monolith debug "-lrt" optimized "-lrt" "${libgcc}") | ||
else() | ||
message(FATAL_ERROR "OS that is not either Windows or Linux hasn't been supported yet.") | ||
endif() | ||
|
||
include_directories(${includeDirs}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@echo off | ||
REM Usage sample: build -DV8_DIR=C:\v8 | ||
SET JAVET_VERSION=0.7.0 | ||
rd /s/q build | ||
mkdir build | ||
cd build | ||
mkdir ..\..\src\main\resources | ||
cmake ..\ -G "Visual Studio 16 2019" -A x64 -DJAVET_VERSION=%JAVET_VERSION% %* ^ | ||
&& cmake --build . -- /p:CharacterSet=Unicode /p:Configuration=Release /p:Platform=x64 | ||
IF %ERRORLEVEL% EQU 0 ( | ||
del /q ..\..\src\main\resources\*.dll | ||
copy /y Release\*.dll ..\..\src\main\resources | ||
echo Build Completed | ||
) ELSE ( | ||
echo Build Failed | ||
) | ||
cd ..\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
# Usage sample: build -DV8_DIR=~/v8 | ||
JAVET_VERSION=0.7.0 | ||
rm -rf build | ||
mkdir build | ||
cd build | ||
mkdir -p ../../src/main/resources | ||
cmake ../ -DJAVET_VERSION=${JAVET_VERSION} "$@" \ | ||
&& make -j4 \ | ||
&& execstack -c libjavet-linux-x86_64.v.${JAVET_VERSION}.so \ | ||
&& strip --strip-unneeded -R .note -R .comment libjavet-linux-x86_64.v.${JAVET_VERSION}.so | ||
if [ $? -eq 0 ]; then | ||
rm -f ../../src/main/resources/*.so | ||
cp -f *.so ../../src/main/resources | ||
echo Build Completed | ||
else | ||
echo Build Failed | ||
fi | ||
cd ../ | ||
|
Oops, something went wrong.