Skip to content

Commit

Permalink
🐞 fix: Add locker for inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Feb 27, 2024
1 parent 8bc0ae9 commit 0b42d1e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cpp/jni/javet_jni_core_v8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ JNIEXPORT void JNICALL Java_com_caoccao_javet_interop_V8Native_unregisterGCProlo

JNIEXPORT void JNICALL Java_com_caoccao_javet_interop_V8Native_v8InspectorSend
(JNIEnv* jniEnv, jobject caller, jlong v8RuntimeHandle, jstring mMessage) {
RUNTIME_HANDLES_TO_OBJECTS_WITH_SCOPE(v8RuntimeHandle);
auto v8Runtime = Javet::V8Runtime::FromHandle(v8RuntimeHandle);
auto v8LockerForInspector = v8Runtime->GetSharedV8LockerForInspector();
auto v8IsolateScope = v8Runtime->GetV8IsolateScope();
V8HandleScope v8HandleScope(v8Runtime->v8Isolate);
auto v8Context = v8Runtime->GetV8LocalContext();
auto v8ContextScope = v8Runtime->GetV8ContextScope(v8Context);
char const* umMessage = jniEnv->GetStringUTFChars(mMessage, nullptr);
std::string message(umMessage, jniEnv->GetStringUTFLength(mMessage));
v8Runtime->v8Inspector->send(message);
Expand Down
5 changes: 5 additions & 0 deletions cpp/jni/javet_v8_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ namespace Javet {
return v8Locker ? v8Locker : std::make_shared<v8::Locker>(v8Isolate);
}

inline auto GetSharedV8LockerForInspector() const noexcept {
return v8LockerForInspector ? v8LockerForInspector : std::make_shared<v8::Locker>(v8Isolate);
}

/*
* Unique V8 locker is for explicit mode.
* Application manages the lock.
Expand Down Expand Up @@ -181,6 +185,7 @@ namespace Javet {
std::unique_ptr<v8::SnapshotCreator> v8SnapshotCreator;
std::unique_ptr<v8::StartupData, std::function<void(v8::StartupData*)>> v8StartupData;
std::shared_ptr<v8::Locker> v8Locker;
std::shared_ptr<v8::Locker> v8LockerForInspector;
V8PersistentContext v8PersistentContext;
};
}
Expand Down
3 changes: 2 additions & 1 deletion docs/release_notes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ v0 Maintenance v14 v8.9-v9.4
.. toctree::
:maxdepth: 1

release_notes_3_0
release_notes_3_1

* :doc:`release_notes_3_0`
* :doc:`release_notes_2_2`
* :doc:`release_notes_2_1`
* :doc:`release_notes_2_0`
Expand Down
9 changes: 9 additions & 0 deletions docs/release_notes/release_notes_3_1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
===================
Release Notes 3.1.x
===================

3.1.0 V8 v12.3
--------------

* Added support for Android Node.js mode
* Fixed inspector locking issue

0 comments on commit 0b42d1e

Please sign in to comment.