Skip to content

Commit

Permalink
🕊️ Javet v1.1.1 (#146)
Browse files Browse the repository at this point in the history
* Upgraded V8 to `v9.9.115.9` [(2022-03-07)](https://v8.dev/blog/v8-release-99)
* Enhanced createV8ValueArrayBuffer with ByteBuffer
* Added support to `Optional`, `Stream`, `ZonedDateTime` for Android
* Fixed a bug in `V8ValueObject.get()` when evaluation fails
  • Loading branch information
caoccao authored Mar 14, 2022
1 parent 17c1aee commit 1ab0321
Show file tree
Hide file tree
Showing 443 changed files with 1,361 additions and 1,185 deletions.
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Major Features

* Linux (x86_64) + Mac OS (x86_64, arm64) + ️Windows (x86_64)
* Android (arm, arm64, x86 and x86_64)
* Node.js ``v16.14.0`` + V8 ``v9.8.177.11``
* Node.js ``v16.14.0`` + V8 ``v9.9.115.9``
* Dynamic switch between Node.js and V8 mode (`Which mode do you prefer? <https://github.com/caoccao/Javet/discussions/92>`_)
* Polyfill V8 mode with `Javenode <https://github.com/caoccao/Javenode>`_
* V8 API exposure in JVM
Expand All @@ -58,33 +58,33 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
<!-- Mac OS (x86_64 and arm64) -->
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet-macos</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

.. code-block:: kotlin
implementation("com.caoccao.javet:javet:1.1.0") // Linux and Windows (x86_64)
implementation("com.caoccao.javet:javet-macos:1.1.0") // Mac OS (x86_64 and arm64)
implementation("com.caoccao.javet:javet-android:1.1.0") // Android (arm, arm64, x86 and x86_64)
implementation("com.caoccao.javet:javet:1.1.1") // Linux and Windows (x86_64)
implementation("com.caoccao.javet:javet-macos:1.1.1") // Mac OS (x86_64 and arm64)
implementation("com.caoccao.javet:javet-android:1.1.1") // Android (arm, arm64, x86 and x86_64)
Gradle Groovy DSL
^^^^^^^^^^^^^^^^^

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:1.1.0' // Linux and Windows (x86_64)
implementation 'com.caoccao.javet:javet-macos:1.1.0' // Mac OS (x86_64 and arm64)
implementation 'com.caoccao.javet:javet-android:1.1.0' // Android (arm, arm64, x86 and x86_64)
implementation 'com.caoccao.javet:javet:1.1.1' // Linux and Windows (x86_64)
implementation 'com.caoccao.javet:javet-macos:1.1.1' // Mac OS (x86_64 and arm64)
implementation 'com.caoccao.javet:javet-android:1.1.1' // Android (arm, arm64, x86 and x86_64)
Hello Javet
-----------
Expand Down
9 changes: 6 additions & 3 deletions android/javet-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ plugins {
id("com.android.library")
}

version = "1.1.0"
version = "1.1.1"

android {
compileSdk = 30

defaultConfig {
minSdk = 21
minSdk = 23
targetSdk = 30

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -46,6 +46,8 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

lintOptions.isAbortOnError = false

sourceSets {
getByName("main") {
java.srcDirs("src/main/java")
Expand All @@ -55,8 +57,9 @@ android {
}

dependencies {
// https://developer.android.com/studio/write/java8-support
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("org.threeten:threetenbp:1.5.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
Expand Down
2 changes: 1 addition & 1 deletion android/javet-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.caoccao.javet"
android:versionCode="1"
android:versionName="1.1.0"
android:versionName="1.1.1"
>

</manifest>
4 changes: 2 additions & 2 deletions android/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-android</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<name>javet</name>
<packaging>aar</packaging>
<description>Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding V8 in Java.</description>
Expand All @@ -29,7 +29,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>1.1.0</tag>
<tag>1.1.1</tag>
</scm>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "1.1.0"
version = "1.1.1"

dependencies {
testImplementation("org.eclipse.jetty.websocket:websocket-server:9.4.44.v20210927")
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-android.sh -DV8_DIR=${HOME}/v8 -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64
# Usage for Node: sh build-android.sh -DNODE_DIR=${HOME}/node -DCMAKE_ANDROID_NDK=${HOME}/android -DCMAKE_ANDROID_ARCH=arm64
JAVET_VERSION=1.1.0
JAVET_VERSION=1.1.1
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-linux.sh -DV8_DIR=${HOME}/v8
# Usage for Node: sh build-linux.sh -DNODE_DIR=${HOME}/node
JAVET_VERSION=1.1.0
JAVET_VERSION=1.1.1
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage for V8: sh build-macos.sh -DV8_DIR=${HOME}/v8
# Usage for Node: sh build-macos.sh -DNODE_DIR=${HOME}/node
JAVET_VERSION=1.1.0
JAVET_VERSION=1.1.1
rm -rf build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-windows.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=1.1.0
SET JAVET_VERSION=1.1.1
rd /s/q build
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/com_caoccao_javet_interop_NodeNative.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
28 changes: 26 additions & 2 deletions cpp/jni/com_caoccao_javet_interop_V8Native.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,6 +35,7 @@
* 2. Methods are expected to be sorted alphabatically except JNI_OnLoad.
*/

#define IS_JAVA_BYTE_BUFFER(jniEnv, obj) jniEnv->IsInstanceOf(obj, Javet::V8Native::jclassByteBuffer)
#define IS_JAVA_INTEGER(jniEnv, obj) jniEnv->IsInstanceOf(obj, Javet::V8Native::jclassV8ValueInteger)
#define IS_JAVA_STRING(jniEnv, obj) jniEnv->IsInstanceOf(obj, Javet::V8Native::jclassV8ValueString)
#define IS_JAVA_SYMBOL(jniEnv, obj) jniEnv->IsInstanceOf(obj, Javet::V8Native::jclassV8ValueSymbol)
Expand Down Expand Up @@ -73,6 +74,8 @@ namespace Javet {
static std::unique_ptr<V8Platform> GlobalV8Platform;
#endif

static jclass jclassByteBuffer;

static jclass jclassV8Host;
static jmethodID jmethodIDV8HostIsLibraryReloadable;

Expand All @@ -98,6 +101,8 @@ namespace Javet {
or runtime memory corruption will take place.
*/
void Initialize(JNIEnv* jniEnv) {
jclassByteBuffer = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("java/nio/ByteBuffer"));

jclassV8Host = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/V8Host"));
jmethodIDV8HostIsLibraryReloadable = jniEnv->GetStaticMethodID(jclassV8Host, "isLibraryReloadable", "()Z");

Expand Down Expand Up @@ -325,6 +330,14 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_createV8Value
if (IS_JAVA_INTEGER(jniEnv, mContext)) {
v8LocalValueResult = v8::ArrayBuffer::New(v8Context->GetIsolate(), TO_JAVA_INTEGER(jniEnv, mContext));
}
else if (IS_JAVA_BYTE_BUFFER(jniEnv, mContext)) {
std::unique_ptr<v8::BackingStore> v8BackingStorePointer = v8::ArrayBuffer::NewBackingStore(
jniEnv->GetDirectBufferAddress(mContext),
static_cast<size_t>(jniEnv->GetDirectBufferCapacity(mContext)),
[](void*, size_t, void*) {},
nullptr);
v8LocalValueResult = v8::ArrayBuffer::New(v8Context->GetIsolate(), std::move(v8BackingStorePointer));
}
}
else if (IS_V8_FUNCTION(v8ValueType)) {
auto javetCallbackContextReferencePointer = new Javet::Callback::JavetCallbackContextReference(jniEnv, mContext);
Expand Down Expand Up @@ -505,6 +518,7 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_get
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
auto v8LocalValueKey = Javet::Converter::ToV8Value(jniEnv, v8Context, key);
V8MaybeLocalValue v8MaybeLocalValueResult;
V8TryCatch v8TryCatch(v8Context->GetIsolate());
if (IS_V8_ARGUMENTS(v8ValueType) || IS_V8_ARRAY(v8ValueType) || v8LocalValue->IsTypedArray()) {
if (IS_JAVA_INTEGER(jniEnv, key)) {
jint integerKey = TO_JAVA_INTEGER(jniEnv, key);
Expand Down Expand Up @@ -552,6 +566,9 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_get
}
}
}
if (v8TryCatch.HasCaught()) {
return Javet::Exceptions::ThrowJavetExecutionException(jniEnv, v8Runtime->externalV8Runtime, v8Context, v8TryCatch);
}
if (v8MaybeLocalValueResult.IsEmpty()) {
if (Javet::Exceptions::HandlePendingException(jniEnv, v8Runtime->externalV8Runtime, v8Context)) {
return nullptr;
Expand Down Expand Up @@ -685,9 +702,13 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getPrivateProp
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jlong v8ValueHandle, jint v8ValueType, jstring mKey) {
RUNTIME_AND_VALUE_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle, v8ValueHandle);
if (v8LocalValue->IsObject()) {
V8TryCatch v8TryCatch(v8Context->GetIsolate());
auto v8LocalStringKey = Javet::Converter::ToV8String(jniEnv, v8Context, mKey);
auto v8LocalPrivateKey = v8::Private::ForApi(v8Context->GetIsolate(), v8LocalStringKey);
auto v8MaybeLocalValue = v8LocalValue.As<v8::Object>()->GetPrivate(v8Context, v8LocalPrivateKey);
if (v8TryCatch.HasCaught()) {
return Javet::Exceptions::ThrowJavetExecutionException(jniEnv, v8Runtime->externalV8Runtime, v8Context, v8TryCatch);
}
if (v8MaybeLocalValue.IsEmpty()) {
if (Javet::Exceptions::HandlePendingException(jniEnv, v8Runtime->externalV8Runtime, v8Context)) {
return nullptr;
Expand Down Expand Up @@ -744,6 +765,7 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getProperty
}
}
if (v8LocalValue->IsObject()) {
V8TryCatch v8TryCatch(v8Context->GetIsolate());
auto v8LocalObject = v8LocalValue.As<v8::Object>();
V8MaybeLocalValue v8MaybeLocalValueValue;
if (IS_JAVA_INTEGER(jniEnv, key)) {
Expand All @@ -761,6 +783,9 @@ JNIEXPORT jobject JNICALL Java_com_caoccao_javet_interop_V8Native_getProperty
v8MaybeLocalValueValue = v8LocalObject->Get(v8Context, v8ValueKey);
}
}
if (v8TryCatch.HasCaught()) {
return Javet::Exceptions::ThrowJavetExecutionException(jniEnv, v8Runtime->externalV8Runtime, v8Context, v8TryCatch);
}
if (v8MaybeLocalValueValue.IsEmpty()) {
if (Javet::Exceptions::HandlePendingException(jniEnv, v8Runtime->externalV8Runtime, v8Context)) {
return nullptr;
Expand Down Expand Up @@ -1520,7 +1545,6 @@ JNIEXPORT void JNICALL Java_com_caoccao_javet_interop_V8Native_setFlags
char const* utfChars = jniEnv->GetStringUTFChars(flags, nullptr);
v8::V8::SetFlagsFromString(utfChars, jniEnv->GetStringUTFLength(flags));
jniEnv->ReleaseStringUTFChars(flags, utfChars);
v8::V8::Initialize();
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_callbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_callbacks.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_constants.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_converter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_converter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
6 changes: 3 additions & 3 deletions cpp/jni/javet_enums.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License"),
Expand Down Expand Up @@ -129,8 +129,8 @@ namespace Javet {
Uint16Array = 37, // 0 to 65535 2 16-bit unsigned integer unsigned short uint16_t
Int32Array = 38, // -2147483648 to 2147483647 4 32-bit two's complement signed integer long int32_t
Uint32Array = 39, // 0 to 4294967295 4 32-bit unsigned integer unsigned long uint32_t
Float32Array = 40, // 1.2¡Á10^-38 to 3.4¡Á10^38 4 32-bit IEEE floating point number (7 significant digits e.g., 1.234567) unrestricted float float
Float64Array = 41, // 5.0¡Á10^-324 to 1.8¡Á10^308 8 64-bit IEEE floating point number (16 significant digits e.g., 1.23456789012345) unrestricted double double
Float32Array = 40, // 1.2��10^-38 to 3.4��10^38 4 32-bit IEEE floating point number (7 significant digits e.g., 1.234567) unrestricted float float
Float64Array = 41, // 5.0��10^-324 to 1.8��10^308 8 64-bit IEEE floating point number (16 significant digits e.g., 1.23456789012345) unrestricted double double
BigInt64Array = 42, // -2^63 to 2^63-1 8 64-bit two's complement signed integer bigint int64_t (signed long long)
BigUint64Array = 43, // 0 to 2^64-1 8 64-bit unsigned integer bigint uint64_t (unsigned long long)
};
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_exceptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_exceptions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_inspector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_inspector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_logging.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_monitor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_monitor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_native.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_native.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion cpp/jni/javet_node.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 caoccao.com Sam Cao
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading

0 comments on commit 1ab0321

Please sign in to comment.