From f698522f0ac771e16540d1405b190189e2fa1a38 Mon Sep 17 00:00:00 2001 From: Yauhen Pahrabniak Date: Wed, 30 Oct 2024 17:35:29 +0100 Subject: [PATCH] HandleScope enter/exit callbacks for peoper integration into uv loop --- patches/handle_scope.patch | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 patches/handle_scope.patch diff --git a/patches/handle_scope.patch b/patches/handle_scope.patch new file mode 100644 index 0000000..20aa62b --- /dev/null +++ b/patches/handle_scope.patch @@ -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 g_enterScopeCB; ++static std::function g_leaveScopeCB; ++ ++V8_EXPORT void SetScopeHandler(const std::function& enter, ++ const std::function& 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(v8_isolate); +@@ -908,6 +922,9 @@ void HandleScope::Initialize(Isolate* v8_isolate) { + } + + HandleScope::~HandleScope() { ++ if(g_leaveScopeCB) { ++ g_leaveScopeCB(reinterpret_cast(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(v8_isolate); + escape_slot_ = CreateHandle( + i_isolate, i::ReadOnlyRoots(i_isolate).the_hole_value().ptr());