Skip to content

Commit b007f46

Browse files
committed
fixup! src: migrate from deprecated SnapshotCreator constructor
1 parent 7a4984f commit b007f46

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

lib/internal/buffer.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,8 @@ function createUnsafeBuffer(size) {
11021102
if (!zeroFill) {
11031103
zeroFill = getZeroFillToggle();
11041104
if (isBuildingSnapshot()) {
1105+
// Reset the toggle so that after serialization, we'll re-create a real
1106+
// toggle connected to the C++ one via getZeroFillToggle().
11051107
addAfterUserSerializeCallback(() => {
11061108
zeroFill = undefined;
11071109
});
@@ -1115,14 +1117,6 @@ function createUnsafeBuffer(size) {
11151117
}
11161118
}
11171119

1118-
// The connection between the JS land zero fill toggle and the
1119-
// C++ one in the NodeArrayBufferAllocator gets lost if the toggle
1120-
// is deserialized from the snapshot, because V8 owns the underlying
1121-
// memory of this toggle. This resets the connection.
1122-
function reconnectZeroFillToggle() {
1123-
zeroFill = getZeroFillToggle();
1124-
}
1125-
11261120
module.exports = {
11271121
FastBuffer,
11281122
addBufferPrototypeMethods,

src/api/embed_helpers.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ CommonEnvironmentSetup::CommonEnvironmentSetup(
116116
Isolate::CreateParams params;
117117
params.array_buffer_allocator = impl_->allocator.get();
118118
params.external_references = external_references.data();
119+
params.external_references = external_references.data();
120+
params.cpp_heap =
121+
v8::CppHeap::Create(platform, v8::CppHeapCreateParams{{}}).release();
122+
119123
Isolate* isolate;
120124

121125
// Isolates created for snapshotting should be set up differently since
@@ -234,10 +238,10 @@ CommonEnvironmentSetup::~CommonEnvironmentSetup() {
234238
*static_cast<bool*>(data) = true;
235239
}, &platform_finished);
236240
impl_->platform->UnregisterIsolate(isolate);
237-
if (impl_->snapshot_creator.has_value())
241+
if (impl_->snapshot_creator.has_value()) {
238242
impl_->snapshot_creator.reset();
239-
else
240-
isolate->Dispose();
243+
}
244+
isolate->Dispose();
241245

242246
// Wait until the platform has cleaned up all relevant resources.
243247
while (!platform_finished)

src/node_buffer.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,18 +1222,20 @@ void GetZeroFillToggle(const FunctionCallbackInfo<Value>& args) {
12221222
Local<ArrayBuffer> ab;
12231223
// It can be a nullptr when running inside an isolate where we
12241224
// do not own the ArrayBuffer allocator.
1225-
if (allocator == nullptr) {
1225+
if (allocator == nullptr || env->isolate_data()->is_building_snapshot()) {
12261226
// Create a dummy Uint32Array - the JS land can only toggle the C++ land
12271227
// setting when the allocator uses our toggle. With this the toggle in JS
12281228
// land results in no-ops.
1229+
// When building a snapshot, just use a dummy toggle as well to avoid
1230+
// introducing the dynamic external reference. We'll re-initialize the
1231+
// toggle with a real one connected to the C++ allocator after snapshot
1232+
// deserialization.
12291233

12301234
ab = ArrayBuffer::New(env->isolate(), sizeof(uint32_t));
1231-
} else if (env->isolate_data()->is_building_snapshot()) {
1232-
ab = ArrayBuffer::New(env->isolate(), sizeof(uint32_t));
1235+
} else {
12331236
// TODO(joyeecheung): save ab->GetBackingStore()->Data() in the Node.js
12341237
// array buffer allocator and include it into the C++ toggle while the
12351238
// Environment is still alive.
1236-
} else {
12371239
uint32_t* zero_fill_field = allocator->zero_fill_field();
12381240
std::unique_ptr<BackingStore> backing =
12391241
ArrayBuffer::NewBackingStore(zero_fill_field,

0 commit comments

Comments
 (0)