Skip to content

Commit

Permalink
Javet v0.9.8 (#76)
Browse files Browse the repository at this point in the history
* Added `resolve()` and `reject()` to `V8ValuePromise`
* Added `staticClassEnabled` to `JavetProxyConverter`
* Added `construct()` to `JavetUniversalProxyHandler`
* Added Dockerfile for Linux x86-64
* Refactored document for how to build Javet
  • Loading branch information
caoccao authored Aug 9, 2021
1 parent 07df86a commit 37f7739
Show file tree
Hide file tree
Showing 53 changed files with 1,761 additions and 367 deletions.
65 changes: 65 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ------------------------------------------------------------------------------
# Gradle

.gradle
**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

# ------------------------------------------------------------------------------
# Java

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# ------------------------------------------------------------------------------
# IDEA

.idea

# ------------------------------------------------------------------------------
# VS Code

.history
.vscode

# ------------------------------------------------------------------------------
# Node

**/node_modules

# ------------------------------------------------------------------------------
# Misc
docker/*
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>0.9.7</version>
<version>0.9.8</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

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

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:0.9.7'
implementation 'com.caoccao.javet:javet:0.9.8'
Hello Javet
-----------
Expand Down
9 changes: 8 additions & 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.7"
version = "0.9.8"

repositories {
mavenCentral()
Expand Down Expand Up @@ -67,10 +67,17 @@ task<Exec>("buildJNIHeaders") {

tasks.test {
useJUnitPlatform {
excludeTags("manual")
excludeTags("performance")
}
}

tasks.register<Test>("manualTest") {
useJUnitPlatform {
includeTags("manual")
}
}

tasks.register<Test>("performanceTest") {
useJUnitPlatform {
includeTags("performance")
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.7
SET JAVET_VERSION=0.9.8
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.7
JAVET_VERSION=0.9.8
rm -rf build
mkdir build
cd build
Expand Down
36 changes: 36 additions & 0 deletions cpp/jni/com_caoccao_javet_interop_V8Native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_createV8Value
else if (IS_V8_MAP(v8ValueType)) {
v8LocalValue = v8::Map::New(v8Context->GetIsolate());
}
else if (IS_V8_PROMISE(v8ValueType)) {
v8LocalValue = v8::Promise::Resolver::New(v8Context).ToLocalChecked();
}
else if (IS_V8_PROXY(v8ValueType)) {
V8LocalObject v8LocalObjectObject = mContext == nullptr
? v8::Object::New(v8Context->GetIsolate())
Expand Down Expand Up @@ -878,6 +881,39 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_promiseThen
return Javet::Converter::ToExternalV8ValueUndefined(jniEnv, v8Runtime->externalV8Runtime);
}

JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_promiseGetPromise
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
if (IS_V8_PROMISE(v8ValueType)) {
auto v8LocalPromiseResolver = v8LocalObject.As<v8::Promise::Resolver>();
return v8Runtime->SafeToExternalV8Value(jniEnv, v8Context, v8LocalPromiseResolver->GetPromise());
}
return Javet::Converter::ToExternalV8ValueUndefined(jniEnv, v8Runtime->externalV8Runtime);
}

JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_promiseReject
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType, jobject value) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE_WITH_UNIQUE_LOCKER(v8RuntimeHandle, v8ValueHandle);
if (IS_V8_PROMISE(v8ValueType)) {
auto v8LocalPromiseResolver = v8LocalObject.As<v8::Promise::Resolver>();
auto v8MaybeBool = v8LocalPromiseResolver->Reject(v8Context, Javet::Converter::ToV8Value(jniEnv, v8Context, value));
if (v8MaybeBool.IsJust()) {
return v8MaybeBool.ToChecked();
}
}
return false;
}

JNIEXPORT jboolean JNICALL Java_com_caoccao_javet_interop_V8Native_promiseResolve
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType, jobject value) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE_WITH_UNIQUE_LOCKER(v8RuntimeHandle, v8ValueHandle);
if (IS_V8_PROMISE(v8ValueType)) {
auto v8LocalPromiseResolver = v8LocalObject.As<v8::Promise::Resolver>();
return v8LocalPromiseResolver->Resolve(v8Context, Javet::Converter::ToV8Value(jniEnv, v8Context, value)).ToChecked();
}
return false;
}

JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_proxyGetHandler
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
Expand Down
24 changes: 24 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.

10 changes: 10 additions & 0 deletions cpp/jni/javet_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
auto v8ContextScope = v8Runtime->GetV8ContextScope(v8Context); \
auto v8LocalObject = v8PersistentObjectPointer->Get(v8Context->GetIsolate());

#define RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE_WITH_UNIQUE_LOCKER(v8RuntimeHandle, v8ValueHandle) \
auto v8Runtime = Javet::V8Runtime::FromHandle(v8RuntimeHandle); \
auto v8PersistentObjectPointer = TO_V8_PERSISTENT_OBJECT_POINTER(v8ValueHandle); \
auto v8Locker = v8Runtime->GetUniqueV8Locker(); \
auto v8IsolateScope = v8Runtime->GetV8IsolateScope(); \
V8HandleScope v8HandleScope(v8Runtime->v8Isolate); \
auto v8Context = v8Runtime->GetV8LocalContext(); \
auto v8ContextScope = v8Runtime->GetV8ContextScope(v8Context); \
auto v8LocalObject = v8PersistentObjectPointer->Get(v8Context->GetIsolate());

#define RUNTIME_AND_2_VALUES_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle1, v8ValueHandle2) \
auto v8Runtime = Javet::V8Runtime::FromHandle(v8RuntimeHandle); \
auto v8PersistentObjectPointer1 = TO_V8_PERSISTENT_OBJECT_POINTER(v8ValueHandle1); \
Expand Down
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,7,0
PRODUCTVERSION 0,9,7,0
FILEVERSION 0,9,8,0
PRODUCTVERSION 0,9,8,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.7.0"
VALUE "InternalName", "libjavet-node-windows-x86_64.v.0.9.7.dll"
VALUE "FileVersion", "0.9.8.0"
VALUE "InternalName", "libjavet-node-windows-x86_64.v.0.9.8.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.0.9.7.dll"
VALUE "OriginalFilename", "libjavet-node-windows-x86_64.v.0.9.8.dll"
VALUE "ProductName", "Javet Windows"
VALUE "ProductVersion", "0.9.7.0"
VALUE "ProductVersion", "0.9.8.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,7,0
PRODUCTVERSION 0,9,7,0
FILEVERSION 0,9,8,0
PRODUCTVERSION 0,9,8,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.7.0"
VALUE "InternalName", "libjavet-v8-windows-x86_64.v.0.9.7.dll"
VALUE "FileVersion", "0.9.8.0"
VALUE "InternalName", "libjavet-v8-windows-x86_64.v.0.9.8.dll"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.0.9.7.dll"
VALUE "OriginalFilename", "libjavet-v8-windows-x86_64.v.0.9.8.dll"
VALUE "ProductName", "Javet Windows"
VALUE "ProductVersion", "0.9.7.0"
VALUE "ProductVersion", "0.9.8.0"
END
END
BLOCK "VarFileInfo"
Expand Down
89 changes: 89 additions & 0 deletions docker/linux-x86_64/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2021 caoccao.com Sam Cao
# All rights reserved.
#
# 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.

# Usage: docker build -t sjtucaocao/javet:0.9.8 -f docker/linux-x86_64/base.Dockerfile .

FROM ubuntu:20.04
WORKDIR /

# Update Ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install --upgrade -qq -y --no-install-recommends git curl wget build-essential software-properties-common patchelf maven sudo zip unzip
RUN apt-get install --upgrade -qq -y --no-install-recommends python3 python python3-pip python3-distutils python3-testresources
RUN apt-get upgrade -y
RUN pip3 install coloredlogs

# Prepare V8
RUN mkdir google
WORKDIR /google
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
WORKDIR /google/depot_tools
RUN git checkout remotes/origin/master
ENV PATH=/google/depot_tools:$PATH
WORKDIR /google
RUN fetch v8
WORKDIR /google/v8
RUN git checkout 9.2.230.21
RUN sed -i 's/snapcraft/nosnapcraft/g' ./build/install-build-deps.sh
RUN ./build/install-build-deps.sh
RUN sed -i 's/nosnapcraft/snapcraft/g' ./build/install-build-deps.sh
WORKDIR /google
RUN gclient sync
RUN echo V8 preparation is completed.

# Build V8
WORKDIR /google/v8
RUN python tools/dev/v8gen.py x64.release -- v8_monolithic=true v8_use_external_startup_data=false is_component_build=false v8_enable_i18n_support=false v8_enable_pointer_compression=false v8_static_library=true symbol_level=0 use_custom_libcxx=false
RUN ninja -C out.gn/x64.release v8_monolith
RUN echo V8 build is completed.

# Prepare Node.js
WORKDIR /
RUN git clone https://github.com/nodejs/node.git
WORKDIR /node
RUN git checkout v14.17.2
RUN echo Node.js preparation is completed.

# Build Node.js
WORKDIR /node
COPY ./scripts/python/patch_node_build.py .
RUN python3 patch_node_build.py -p ./
RUN ./configure --enable-static --without-intl
RUN python3 patch_node_build.py -p ./
RUN rm patch_node_build.py
RUN make -j4
RUN echo Node.js build is completed.

# Prepare Javet Build Environment
RUN apt-get install --upgrade -qq -y --no-install-recommends execstack
RUN apt-get install --upgrade -qq -y --no-install-recommends openjdk-8-jdk
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
ENV SDKMAN_HOME="/root/.sdkman"
ENV GRADLE_HOME="${SDKMAN_HOME}/candidates/gradle/current"
RUN curl -s https://get.sdkman.io | bash
RUN source ${SDKMAN_HOME}/bin/sdkman-init.sh && sdk install gradle 7.0.2
ENV PATH=$GRADLE_HOME/bin:$PATH

# Shrink
RUN rm -rf ${SDKMAN_HOME}/archives/*
RUN rm -rf ${SDKMAN_HOME}/tmp/*
RUN apt-get clean -y
RUN rm -rf /var/lib/apt/lists/*
WORKDIR /

# Completed
RUN echo Javet build base image is completed.
Loading

0 comments on commit 37f7739

Please sign in to comment.