Skip to content

Commit 782004c

Browse files
committed
[test] Pass existing CppHeap to Isolate creation
New V8 API expects a CppHeap to exist for the whole existence of an Isolate. Therefore the APIs for attaching and detaching a CppHeap get deprecated, and an existing CppHeap has to be passed to the isolate during isolate creation. This PR adjusts a test that passes an existing CppHeap too late to the isolate.
1 parent a90af7b commit 782004c

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/api/environment.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,13 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator,
351351
uv_loop_t* event_loop,
352352
MultiIsolatePlatform* platform,
353353
const EmbedderSnapshotData* snapshot_data,
354-
const IsolateSettings& settings) {
354+
const IsolateSettings& settings,
355+
std::unique_ptr<v8::CppHeap> cpp_heap) {
355356
Isolate::CreateParams params;
356357
if (allocator != nullptr) params.array_buffer_allocator = allocator;
358+
if (cpp_heap) {
359+
params.cpp_heap = cpp_heap.release();
360+
}
357361
return NewIsolate(&params,
358362
event_loop,
359363
platform,

src/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ NODE_EXTERN v8::Isolate* NewIsolate(
578578
struct uv_loop_s* event_loop,
579579
MultiIsolatePlatform* platform,
580580
const EmbedderSnapshotData* snapshot_data = nullptr,
581-
const IsolateSettings& settings = {});
581+
const IsolateSettings& settings = {},
582+
std::unique_ptr<v8::CppHeap> cpp_heap = {});
582583
NODE_EXTERN v8::Isolate* NewIsolate(
583584
std::shared_ptr<ArrayBufferAllocator> allocator,
584585
struct uv_loop_s* event_loop,

test/cctest/test_cppgc.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ int CppGCed::kDestructCount = 0;
4646
int CppGCed::kTraceCount = 0;
4747

4848
TEST_F(NodeZeroIsolateTestFixture, ExistingCppHeapTest) {
49-
v8::Isolate* isolate =
50-
node::NewIsolate(allocator.get(), &current_loop, platform.get());
51-
5249
// Create and attach the CppHeap before we set up the IsolateData so that
5350
// it recognizes the existing heap.
5451
std::unique_ptr<v8::CppHeap> cpp_heap =
5552
v8::CppHeap::Create(platform.get(), v8::CppHeapCreateParams{{}});
5653

57-
// TODO(joyeecheung): pass it into v8::Isolate::CreateParams and let V8
58-
// own it when we can keep the isolate registered/task runner discoverable
59-
// during isolate disposal.
60-
isolate->AttachCppHeap(cpp_heap.get());
54+
v8::Isolate* isolate =
55+
node::NewIsolate(allocator.get(), &current_loop, platform.get(),
56+
nullptr, {}, std::move(cpp_heap));
6157

6258
// Try creating Context + IsolateData + Environment.
6359
{
@@ -102,8 +98,6 @@ TEST_F(NodeZeroIsolateTestFixture, ExistingCppHeapTest) {
10298
platform->DrainTasks(isolate);
10399

104100
// Cleanup.
105-
isolate->DetachCppHeap();
106-
cpp_heap->Terminate();
107101
platform->DrainTasks(isolate);
108102
}
109103

0 commit comments

Comments
 (0)