Skip to content

Commit

Permalink
📀 Javet v1.0.4 (#113)
Browse files Browse the repository at this point in the history
* Upgraded Node.js to `v16.13.0` ([2021-10-26](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V16.md#16.13.0))
* Upgraded V8 to `v9.6.180.8` ([2021-10-25](https://v8.dev/blog/v8-release-96))
* Added `JavetBridgeConverter` for completely bridging Java and JavaScript
* Fixed a potential core dump issue caused by memory allocation failure in V8
* Added error code 806 and `JavetOutOfMemoryException`
* Upgraded `JavetEnginePool` to get away from busy-wait
* Added `hasPendingException()`, `hasPendingMessage()`, `hasScheduledException()`, `promoteScheduledException()` and `reportPendingMessages()` to `V8Runtime`
  • Loading branch information
caoccao authored Nov 19, 2021
1 parent 7c62548 commit 10f7371
Show file tree
Hide file tree
Showing 419 changed files with 8,550 additions and 3,562 deletions.
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Major Features

* Linux + Mac OS + ️Windows (x86_64)
* Android (arm, arm64, x86 and x86_64)
* Node.js ``v16.12.0`` + V8 ``v9.5.172.22``
* Node.js ``v16.13.0`` + V8 ``v9.6.180.8``
* 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,32 +58,32 @@ Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<!-- Mac OS (x86_64 Only) -->
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet-macos</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
Gradle Kotlin DSL
^^^^^^^^^^^^^^^^^

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

.. code-block:: groovy
implementation 'com.caoccao.javet:javet:1.0.3' // Linux or Windows
implementation 'com.caoccao.javet:javet-macos:1.0.3' // Mac OS (x86_64 Only)
implementation 'com.caoccao.javet:javet:1.0.4' // Linux or Windows
implementation 'com.caoccao.javet:javet-macos:1.0.4' // Mac OS (x86_64 Only)
implementation 'com.caoccao.javet:javet-android:1.0.3' // 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 = "1.0.3"
version = "1.0.4"

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="1.0.3"
android:versionName="1.0.4"
>

</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.0.3</version>
<version>1.0.4</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.0.3</tag>
<tag>1.0.4</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 @@ -25,7 +25,7 @@ repositories {
}

group = "com.caoccao.javet"
version = "1.0.3"
version = "1.0.4"

dependencies {
testImplementation("org.eclipse.jetty.websocket:websocket-server:9.4.38.v20210224")
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.0.3
JAVET_VERSION=1.0.4
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.0.3
JAVET_VERSION=1.0.4
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.0.3
JAVET_VERSION=1.0.4
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.0.3
SET JAVET_VERSION=1.0.4
rd /s/q build
mkdir build
cd build
Expand Down
403 changes: 309 additions & 94 deletions cpp/jni/com_caoccao_javet_interop_V8Native.cpp

Large diffs are not rendered by default.

40 changes: 40 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.

42 changes: 23 additions & 19 deletions cpp/jni/javet_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,30 @@ namespace Javet {
V8ContextScope v8ContextScope(v8Context);
auto v8Array = v8::Array::New(v8Context->GetIsolate(), 1);
auto maybeResult = v8Array->Set(v8Context, 0, propertyValue);
maybeResult.Check();
jboolean isThisObjectRequired = IsThisObjectRequired();
jobject thisObject = isThisObjectRequired ? Javet::Converter::ToExternalV8Value(jniEnv, externalV8Runtime, v8Context, args.This()) : nullptr;
jobject mPropertyValue = Javet::Converter::ToExternalV8Value(jniEnv, externalV8Runtime, v8Context, v8Array);
jobject mResult = jniEnv->CallStaticObjectMethod(
jclassV8FunctionCallback,
jmethodIDV8FunctionCallbackReceiveCallback,
externalV8Runtime,
callbackContext,
thisObject,
mPropertyValue);
if (jniEnv->ExceptionCheck()) {
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in property setter callback");
if (maybeResult.IsNothing()) {
Javet::Exceptions::HandlePendingException(jniEnv, v8Context);
}
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
else {
jboolean isThisObjectRequired = IsThisObjectRequired();
jobject thisObject = isThisObjectRequired ? Javet::Converter::ToExternalV8Value(jniEnv, externalV8Runtime, v8Context, args.This()) : nullptr;
jobject mPropertyValue = Javet::Converter::ToExternalV8Value(jniEnv, externalV8Runtime, v8Context, v8Array);
jobject mResult = jniEnv->CallStaticObjectMethod(
jclassV8FunctionCallback,
jmethodIDV8FunctionCallbackReceiveCallback,
externalV8Runtime,
callbackContext,
thisObject,
mPropertyValue);
if (jniEnv->ExceptionCheck()) {
Javet::Exceptions::ThrowV8Exception(jniEnv, v8Context, "Uncaught JavaError in property setter callback");
}
if (thisObject != nullptr) {
jniEnv->DeleteLocalRef(thisObject);
}
if (mResult != nullptr) {
jniEnv->CallStaticVoidMethod(jclassJavetResourceUtils, jmethodIDJavetResourceUtilsSafeClose, mResult);
jniEnv->DeleteLocalRef(mResult);
}
}
}
}
Expand Down
44 changes: 40 additions & 4 deletions cpp/jni/javet_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "javet_converter.h"
#include "javet_enums.h"
#include "javet_exceptions.h"
#include "javet_logging.h"

// Primitive
Expand Down Expand Up @@ -193,6 +194,10 @@ namespace Javet {
jclassV8ValueWeakSet = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/values/reference/V8ValueWeakSet"));
jmethodIDV8ValueWeakSetConstructor = jniEnv->GetMethodID(jclassV8ValueWeakSet, JAVA_CONSTRUCTOR_AND_SIGNATURE_FROM_HANDLE);
jmethodIDV8ValueWeakSetGetHandle = jniEnv->GetMethodID(jclassV8ValueWeakSet, JAVA_METHOD_AND_SIGNATURE_GET_HANDLE);

// Misc
jclassJavetScriptingError = (jclass)jniEnv->NewGlobalRef(jniEnv->FindClass("com/caoccao/javet/exceptions/JavetScriptingError"));
jmethodIDJavetScriptingErrorConstructor = jniEnv->GetMethodID(jclassJavetScriptingError, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIII)V");
}

jobject ToExternalV8ValueArray(
Expand All @@ -202,8 +207,11 @@ namespace Javet {
if (argLength > 0) {
auto v8Array = v8::Array::New(v8Context->GetIsolate(), argLength);
for (int i = 0; i < argLength; ++i) {
auto maybeResult = v8Array->Set(v8Context, i, args[i]);
maybeResult.Check();
auto v8MaybeBool = v8Array->Set(v8Context, i, args[i]);
if (v8MaybeBool.IsNothing()) {
Javet::Exceptions::HandlePendingException(jniEnv, v8Context);
return nullptr;
}
}
return ToExternalV8Value(jniEnv, externalV8Runtime, v8Context, v8Array);
}
Expand Down Expand Up @@ -380,6 +388,35 @@ namespace Javet {
return jniEnv->CallObjectMethod(externalV8Runtime, jmethodIDV8RuntimeCreateV8ValueUndefined);
}

jobject ToJavetScriptingError(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch) {
jstring jStringExceptionMessage = ToJavaString(jniEnv, v8Context, v8TryCatch.Exception());
jstring jStringScriptResourceName = nullptr, jStringSourceLine = nullptr;
int lineNumber = 0, startColumn = 0, endColumn = 0, startPosition = 0, endPosition = 0;
auto v8LocalMessage = v8TryCatch.Message();
if (!v8LocalMessage.IsEmpty()) {
jStringScriptResourceName = ToJavaString(jniEnv, v8Context, v8LocalMessage->GetScriptResourceName());
jStringSourceLine = ToJavaString(jniEnv, v8Context, v8LocalMessage->GetSourceLine(v8Context).FromMaybe(V8LocalString()));
lineNumber = v8LocalMessage->GetLineNumber(v8Context).FromMaybe(0);
startColumn = v8LocalMessage->GetStartColumn();
endColumn = v8LocalMessage->GetEndColumn();
startPosition = v8LocalMessage->GetStartPosition();
endPosition = v8LocalMessage->GetEndPosition();
}
jobject javetScriptingError = jniEnv->NewObject(
jclassJavetScriptingError,
jmethodIDJavetScriptingErrorConstructor,
jStringExceptionMessage, jStringScriptResourceName, jStringSourceLine,
lineNumber, startColumn, endColumn, startPosition, endPosition);
if (jStringSourceLine != nullptr) {
jniEnv->DeleteLocalRef(jStringSourceLine);
}
if (jStringScriptResourceName != nullptr) {
jniEnv->DeleteLocalRef(jStringScriptResourceName);
}
jniEnv->DeleteLocalRef(jStringExceptionMessage);
return javetScriptingError;
}

std::unique_ptr<v8::ScriptOrigin> ToV8ScriptOringinPointer(JNIEnv* jniEnv, const V8LocalContext& v8Context,
jstring& mResourceName, jint& mResourceLineOffset, jint& mResourceColumnOffset, jint& mScriptId, jboolean& mIsWASM, jboolean& mIsModule) {
return std::make_unique<v8::ScriptOrigin>(
Expand Down Expand Up @@ -407,8 +444,7 @@ namespace Javet {
if (twoByteString.IsEmpty()) {
return V8LocalString();
}
auto localV8String = twoByteString.ToLocalChecked();
return localV8String;
return twoByteString.ToLocalChecked();
}

V8LocalValue ToV8Value(JNIEnv* jniEnv, const V8LocalContext& v8Context, jobject& obj) {
Expand Down
7 changes: 7 additions & 0 deletions cpp/jni/javet_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ namespace Javet {
static jmethodID jmethodIDV8ValueWeakSetConstructor;
static jmethodID jmethodIDV8ValueWeakSetGetHandle;

// Misc

static jclass jclassJavetScriptingError;
static jmethodID jmethodIDJavetScriptingErrorConstructor;

void Initialize(JNIEnv* jniEnv);

static inline jstring ToJavaString(JNIEnv* jniEnv, const char* utfString) {
Expand Down Expand Up @@ -218,6 +223,8 @@ namespace Javet {

jobject ToExternalV8ValueUndefined(JNIEnv* jniEnv, jobject externalV8Runtime);

jobject ToJavetScriptingError(JNIEnv* jniEnv, const V8LocalContext& v8Context, const V8TryCatch& v8TryCatch);

static inline V8LocalBoolean ToV8Boolean(const V8LocalContext& v8Context, jboolean& managedBoolean) {
return v8::Boolean::New(v8Context->GetIsolate(), managedBoolean);
}
Expand Down
Loading

0 comments on commit 10f7371

Please sign in to comment.