Skip to content

Commit 53c8e7c

Browse files
authored
Provide CppHeap for Isolate initialization (#209)
Isolate::AttachCppHeap is about to be deprecated soon, the CppHeap should be provided during Isolate initialization instead.
1 parent b8204b6 commit 53c8e7c

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/env.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,11 @@ IsolateData::IsolateData(Isolate* isolate,
574574
platform_(platform),
575575
snapshot_data_(snapshot_data),
576576
options_(std::move(options)) {
577-
v8::CppHeap* cpp_heap = isolate->GetCppHeap();
578577

579578
uint16_t cppgc_id = kDefaultCppGCEmbedderID;
580579
// We do not care about overflow since we just want this to be different
581580
// from the cppgc id.
582581
uint16_t non_cppgc_id = cppgc_id + 1;
583-
if (cpp_heap == nullptr) {
584-
cpp_heap_ = CppHeap::Create(platform, v8::CppHeapCreateParams{{}});
585-
// TODO(joyeecheung): pass it into v8::Isolate::CreateParams and let V8
586-
// own it when we can keep the isolate registered/task runner discoverable
587-
// during isolate disposal.
588-
isolate->AttachCppHeap(cpp_heap_.get());
589-
}
590582

591583
{
592584
// GC could still be run after the IsolateData is destroyed, so we store

src/node_main_instance.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ NodeMainInstance::NodeMainInstance(const SnapshotData* snapshot_data,
4444
isolate_params_(std::make_unique<Isolate::CreateParams>()),
4545
snapshot_data_(snapshot_data) {
4646
isolate_params_->array_buffer_allocator = array_buffer_allocator_.get();
47+
isolate_params_->cpp_heap =
48+
v8::CppHeap::Create(platform_, v8::CppHeapCreateParams{{}}).release();
4749

4850
isolate_ =
4951
NewIsolate(isolate_params_.get(), event_loop, platform, snapshot_data);

src/node_worker.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class WorkerThreadData {
162162
SetIsolateCreateParamsForNode(&params);
163163
w->UpdateResourceConstraints(&params.constraints);
164164
params.array_buffer_allocator_shared = allocator;
165+
params.cpp_heap =
166+
v8::CppHeap::Create(w->platform_, v8::CppHeapCreateParams{{}})
167+
.release();
165168
Isolate* isolate =
166169
NewIsolate(&params, &loop_, w->platform_, w->snapshot_data());
167170
if (isolate == nullptr) {

0 commit comments

Comments
 (0)