Skip to content

Commit

Permalink
🎶 Javet v2.1.0 (#232)
Browse files Browse the repository at this point in the history
* Upgraded Node.js to `v18.15.0` ([2023-03-07](https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V18.md#18.15.0))
* Upgraded V8 to `v11.1.277.14` ([2023-03-04](https://v8.dev/blog/v8-release-111))
* Built Node.js with Visual Studio 2022 instead of 2019.
* Added Automatic-Module-Name.
* Stopped storing callback contexts in the JNI global reference table for Android.
  • Loading branch information
caoccao authored Mar 14, 2023
1 parent 2a299a4 commit 6a5b132
Show file tree
Hide file tree
Showing 751 changed files with 1,726 additions and 1,375 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux_build_artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ on:
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_REPO_JAVET: ${{ secrets.DOCKERHUB_REPO_JAVET }}
JAVET_NODE_VERSION: 18.14.0
JAVET_V8_VERSION: 11.0.226.13
JAVET_VERSION: 2.0.4
JAVET_NODE_VERSION: 18.15.0
JAVET_V8_VERSION: 11.1.277.14
JAVET_VERSION: 2.1.0

jobs:
javet_linux_x86_64:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linux_build_node_v8_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ on:
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_REPO_JAVET: ${{ secrets.DOCKERHUB_REPO_JAVET }}
JAVET_NODE_VERSION: 18.14.0
JAVET_V8_VERSION: 11.0.226.13
JAVET_VERSION: 2.0.4
JAVET_NODE_VERSION: 18.15.0
JAVET_V8_VERSION: 11.1.277.14
JAVET_VERSION: 2.1.0

# if we skip a job using a job level `if` condition, then any dependent jobs also don't run.
# we can skip a step of the job, using a step level `if` condition.
Expand Down
12 changes: 6 additions & 6 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 ``v18.14.0`` + V8 ``v11.0.226.13``
* Node.js ``v18.15.0`` + V8 ``v11.1.277.14``
* 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,7 +58,7 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>2.0.4</version>
<version>2.1.0</version>
</dependency>
<!-- Mac OS (x86_64 and arm64) -->
Expand All @@ -73,18 +73,18 @@ Gradle Kotlin DSL

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

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:2.0.4' // Linux and Windows (x86_64)
implementation 'com.caoccao.javet:javet:2.1.0' // Linux and Windows (x86_64)
implementation 'com.caoccao.javet:javet-macos:2.0.4' // Mac OS (x86_64 and arm64)
implementation 'com.caoccao.javet:javet-android:2.0.4' // Android (arm, arm64, x86 and x86_64)
implementation 'com.caoccao.javet:javet-android:2.1.0' // Android (arm, arm64, x86 and x86_64)
Hello Javet
-----------
Expand Down
2 changes: 1 addition & 1 deletion android/javet-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
id("com.android.library")
}

version = "2.0.4"
version = "2.1.0"

android {
compileSdk = 30
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="2.0.4"
android:versionName="2.1.0"
>

</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>2.0.4</version>
<version>2.1.0</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:[email protected]:caoccao/caoccao.git</developerConnection>
<url>https://github.com/caoccao/Javet</url>
<tag>2.0.4</tag>
<tag>2.1.0</tag>
</scm>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022. caoccao.com Sam Cao
* Copyright (c) 2021-2023. 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.
Expand All @@ -25,7 +25,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "2.0.4"
version = "2.1.0"

dependencies {
testImplementation("org.eclipse.jetty.websocket:websocket-server:9.4.49.v20220914")
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=2.0.4
JAVET_VERSION=2.1.0
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=2.0.4
JAVET_VERSION=2.1.0
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=2.0.4
JAVET_VERSION=2.1.0
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=2.0.4
SET JAVET_VERSION=2.1.0
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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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/com_caoccao_javet_interop_V8Native.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
40 changes: 13 additions & 27 deletions cpp/jni/javet_callbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -52,6 +52,7 @@ namespace Javet {
"(Lcom/caoccao/javet/interop/V8Runtime;Lcom/caoccao/javet/interop/callback/JavetCallbackContext;Lcom/caoccao/javet/values/V8Value;Lcom/caoccao/javet/values/reference/V8ValueArray;)Lcom/caoccao/javet/values/V8Value;");

jclassV8Runtime = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/interop/V8Runtime"));
jmethodIDV8RuntimeGetCallbackContext = jniEnv->GetMethodID(jclassV8Runtime, "getCallbackContext", "(J)Lcom/caoccao/javet/interop/callback/JavetCallbackContext;");
jmethodIDV8RuntimeGetV8Module = jniEnv->GetMethodID(jclassV8Runtime, "getV8Module", "(Ljava/lang/String;Lcom/caoccao/javet/values/reference/IV8Module;)Lcom/caoccao/javet/values/reference/IV8Module;");
jmethodIDV8RuntimeReceiveGCEpilogueCallback = jniEnv->GetMethodID(jclassV8Runtime, "receiveGCEpilogueCallback", "(II)V");
jmethodIDV8RuntimeReceiveGCPrologueCallback = jniEnv->GetMethodID(jclassV8Runtime, "receiveGCPrologueCallback", "(II)V");
Expand Down Expand Up @@ -232,10 +233,8 @@ namespace Javet {
}

JavetCallbackContextReference::JavetCallbackContextReference(JNIEnv* jniEnv, jobject callbackContext) {
this->callbackContext = jniEnv->NewGlobalRef(callbackContext);
INCREASE_COUNTER(Javet::Monitor::CounterType::NewGlobalRef);
jniEnv->CallVoidMethod(callbackContext, jmethodIDJavetCallbackContextSetHandle, TO_JAVA_LONG(this));
v8PersistentCallbackContextHandlePointer = nullptr;
SetHandle();
}

void JavetCallbackContextReference::CallFunction(const v8::FunctionCallbackInfo<v8::Value>& args) {
Expand All @@ -258,8 +257,9 @@ namespace Javet {
else {
jobject externalV8Runtime = v8Runtime->externalV8Runtime;
V8ContextScope v8ContextScope(v8Context);
jboolean isReturnResult = IsReturnResult();
jboolean isThisObjectRequired = IsThisObjectRequired();
jobject callbackContext = jniEnv->CallObjectMethod(externalV8Runtime, jmethodIDV8RuntimeGetCallbackContext, TO_JAVA_LONG(this));
jboolean isReturnResult = jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsReturnResult);
jboolean isThisObjectRequired = jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsThisObjectRequired);
jobject externalArgs = Javet::Converter::ToExternalV8ValueArray(jniEnv, v8Runtime, v8Context, args);
jobject thisObject = isThisObjectRequired ? Javet::Converter::ToExternalV8Value(jniEnv, v8Runtime, v8Context, args.This()) : nullptr;
jobject mResult = jniEnv->CallStaticObjectMethod(
Expand Down Expand Up @@ -315,7 +315,8 @@ namespace Javet {
else {
jobject externalV8Runtime = v8Runtime->externalV8Runtime;
V8ContextScope v8ContextScope(v8Context);
jboolean isThisObjectRequired = IsThisObjectRequired();
jobject callbackContext = jniEnv->CallObjectMethod(externalV8Runtime, jmethodIDV8RuntimeGetCallbackContext, TO_JAVA_LONG(this));
jboolean isThisObjectRequired = jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsThisObjectRequired);
jobject thisObject = isThisObjectRequired ? Javet::Converter::ToExternalV8Value(jniEnv, v8Runtime, v8Context, args.This()) : nullptr;
jobject mResult = jniEnv->CallStaticObjectMethod(
jclassV8FunctionCallback,
Expand Down Expand Up @@ -369,13 +370,15 @@ namespace Javet {
Javet::Exceptions::HandlePendingException(jniEnv, v8Runtime, v8Context);
}
else {
jboolean isThisObjectRequired = IsThisObjectRequired();
jobject externalV8Runtime = v8Runtime->externalV8Runtime;
jobject callbackContext = jniEnv->CallObjectMethod(externalV8Runtime, jmethodIDV8RuntimeGetCallbackContext, TO_JAVA_LONG(this));
jboolean isThisObjectRequired = jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsThisObjectRequired);
jobject thisObject = isThisObjectRequired ? Javet::Converter::ToExternalV8Value(jniEnv, v8Runtime, v8Context, args.This()) : nullptr;
jobject mArguments = Javet::Converter::ToExternalV8Value(jniEnv, v8Runtime, v8Context, v8Array);
jobject mResult = jniEnv->CallStaticObjectMethod(
jclassV8FunctionCallback,
jmethodIDV8FunctionCallbackReceiveCallback,
v8Runtime->externalV8Runtime,
externalV8Runtime,
callbackContext,
thisObject,
mArguments);
Expand All @@ -396,26 +399,9 @@ namespace Javet {
}
}

jboolean JavetCallbackContextReference::IsReturnResult() {
FETCH_JNI_ENV(GlobalJavaVM);
return jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsReturnResult);
}

jboolean JavetCallbackContextReference::IsThisObjectRequired() {
FETCH_JNI_ENV(GlobalJavaVM);
return jniEnv->CallBooleanMethod(callbackContext, jmethodIDJavetCallbackContextIsThisObjectRequired);
}

void JavetCallbackContextReference::SetHandle() {
FETCH_JNI_ENV(GlobalJavaVM);
jniEnv->CallVoidMethod(callbackContext, jmethodIDJavetCallbackContextSetHandle, TO_JAVA_LONG(callbackContext));
}

void JavetCallbackContextReference::RemoveCallbackContext(const jobject& externalV8Runtime) {
FETCH_JNI_ENV(GlobalJavaVM);
jniEnv->CallVoidMethod(externalV8Runtime, jmethodIDV8RuntimeRemoveCallbackContext, TO_JAVA_LONG(callbackContext));
jniEnv->DeleteGlobalRef(callbackContext);
INCREASE_COUNTER(Javet::Monitor::CounterType::DeleteGlobalRef);
jniEnv->CallVoidMethod(externalV8Runtime, jmethodIDV8RuntimeRemoveCallbackContext, TO_JAVA_LONG(this));
}

JavetCallbackContextReference::~JavetCallbackContextReference() {
Expand Down
7 changes: 2 additions & 5 deletions cpp/jni/javet_callbacks.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -43,6 +43,7 @@ namespace Javet {
static jmethodID jmethodIDV8FunctionCallbackReceiveCallback;

static jclass jclassV8Runtime;
static jmethodID jmethodIDV8RuntimeGetCallbackContext;
static jmethodID jmethodIDV8RuntimeGetV8Module;
static jmethodID jmethodIDV8RuntimeReceiveGCEpilogueCallback;
static jmethodID jmethodIDV8RuntimeReceiveGCPrologueCallback;
Expand All @@ -68,15 +69,11 @@ namespace Javet {

class JavetCallbackContextReference {
public:
jobject callbackContext;
V8PersistentBigInt* v8PersistentCallbackContextHandlePointer;
JavetCallbackContextReference(JNIEnv* jniEnv, jobject callbackContext);
void CallFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
void CallPropertyGetter(V8LocalName propertyName, const v8::PropertyCallbackInfo<v8::Value>& args);
void CallPropertySetter(V8LocalName propertyName, V8LocalValue propertyValue, const v8::PropertyCallbackInfo<void>& args);
jboolean IsReturnResult();
jboolean IsThisObjectRequired();
void SetHandle();
void RemoveCallbackContext(const jobject& externalV8Runtime);
virtual ~JavetCallbackContextReference();
};
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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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_enums.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 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-2022 caoccao.com Sam Cao
* Copyright (c) 2021-2023 caoccao.com Sam Cao
* All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading

0 comments on commit 6a5b132

Please sign in to comment.