diff --git a/src/workerd/jsg/setup.c++ b/src/workerd/jsg/setup.c++ index c5ff1e5778b..8f71eb73ee2 100644 --- a/src/workerd/jsg/setup.c++ +++ b/src/workerd/jsg/setup.c++ @@ -300,9 +300,7 @@ static v8::Isolate* newIsolate(v8::Isolate::CreateParams&& params, v8::CppHeap* // fully utilized. This differs from browser environments, where a user is typically doing // only one thing at a time and thus likely has CPU cores to spare. - // V8 *claims* to take ownership of the v8::CppHeap but actually releases ownership of it - // during v8::Isolate::Dispose. - // TODO(soon): submit a bug report/patch to v8. + // V8 takes ownership of the v8::CppHeap. params.cpp_heap = cppHeap; if (params.array_buffer_allocator == nullptr && @@ -328,7 +326,11 @@ IsolateBase::IsolateBase(const V8System& system, kj::Own observer) : system(system), cppHeap(newCppHeap(const_cast(&system.platformWrapper))), +#if (V8_MAJOR_VERSION == 13 && V8_MINOR_VERSION >= 4) || V8_MAJOR_VERSION > 13 + ptr(newIsolate(kj::mv(createParams), cppHeap.release())), +#else ptr(newIsolate(kj::mv(createParams), cppHeap.get())), +#endif heapTracer(ptr), observer(kj::mv(observer)) { jsg::runInV8Stack([&](jsg::V8StackScope& stackScope) { @@ -395,6 +397,7 @@ IsolateBase::IsolateBase(const V8System& system, IsolateBase::~IsolateBase() noexcept(false) { jsg::runInV8Stack([&](jsg::V8StackScope& stackScope) { ptr->Dispose(); + // TODO(cleanup): meaningless after V8 13.4 is released. cppHeap.reset(); ; }); diff --git a/src/workerd/jsg/setup.h b/src/workerd/jsg/setup.h index 1e45ac67d5a..67e9e90b83d 100644 --- a/src/workerd/jsg/setup.h +++ b/src/workerd/jsg/setup.h @@ -235,6 +235,8 @@ class IsolateBase { using Item = kj::OneOf, RefToDelete>; const V8System& system; + // TODO(cleanup): After v8 13.4 is fully released we can inline this into `newIsolate` + // and remove this member. std::unique_ptr cppHeap; v8::Isolate* ptr; kj::Maybe uuid;