Skip to content

Commit

Permalink
HandleScope enter/exit callbacks for peoper integration into uv loop
Browse files Browse the repository at this point in the history
  • Loading branch information
prikolium-cfx committed Oct 30, 2024
1 parent 9791658 commit f698522
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions patches/handle_scope.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git forkSrcPrefix/deps/v8/src/api/api.cc forkDstPrefix/deps/v8/src/api/api.cc
index 2dd476dda34f1cfe3a75b7895009af24963372f2..6476204733a8aa87c4681dbeb5fee12db54e529d 100644
--- forkSrcPrefix/deps/v8/src/api/api.cc
+++ forkDstPrefix/deps/v8/src/api/api.cc
@@ -883,7 +883,21 @@ void InternalFieldOutOfBounds(int index) {

// --- H a n d l e s ---

-HandleScope::HandleScope(Isolate* v8_isolate) { Initialize(v8_isolate); }
+static std::function<void(Isolate*)> g_enterScopeCB;
+static std::function<void(Isolate*)> g_leaveScopeCB;
+
+V8_EXPORT void SetScopeHandler(const std::function<void(Isolate*)>& enter,
+ const std::function<void(Isolate*)>& exit) {
+ g_enterScopeCB = enter;
+ g_leaveScopeCB = exit;
+}
+
+HandleScope::HandleScope(Isolate* v8_isolate) {
+ if(g_enterScopeCB) {
+ g_enterScopeCB(v8_isolate);
+ }
+ Initialize(v8_isolate);
+}

void HandleScope::Initialize(Isolate* v8_isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
@@ -908,6 +922,9 @@ void HandleScope::Initialize(Isolate* v8_isolate) {
}

HandleScope::~HandleScope() {
+ if(g_leaveScopeCB) {
+ g_leaveScopeCB(reinterpret_cast<Isolate*>(i_isolate_));
+ }
#ifdef V8_ENABLE_CHECKS
CHECK_EQ(scope_level_, i_isolate_->handle_scope_data()->level);
#endif
@@ -938,6 +955,9 @@ i::Address* HandleScope::CreateHandleForCurrentIsolate(i::Address value) {
#endif // V8_ENABLE_DIRECT_LOCAL

EscapableHandleScopeBase::EscapableHandleScopeBase(Isolate* v8_isolate) {
+ if(g_enterScopeCB) {
+ g_enterScopeCB(v8_isolate);
+ }
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
escape_slot_ = CreateHandle(
i_isolate, i::ReadOnlyRoots(i_isolate).the_hole_value().ptr());

0 comments on commit f698522

Please sign in to comment.