diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 16e46f9dd02409..c659ac06f1d41d 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -132,6 +132,18 @@ MaybeLocal Message::Deserialize(Environment* env, // Attach all transferred ArrayBuffers to their new Isolate. for (uint32_t i = 0; i < array_buffer_contents_.size(); ++i) { + if (!env->isolate_data()->uses_node_allocator()) { + // We don't use Node's allocator on the receiving side, so we have + // to create the ArrayBuffer from a copy of the memory. + AllocatedBuffer buf = + env->AllocateManaged(array_buffer_contents_[i].size); + memcpy(buf.data(), + array_buffer_contents_[i].data, + array_buffer_contents_[i].size); + deserializer.TransferArrayBuffer(i, buf.ToArrayBuffer()); + continue; + } + Local ab = ArrayBuffer::New(env->isolate(), array_buffer_contents_[i].release(), @@ -288,8 +300,10 @@ Maybe Message::Serialize(Environment* env, Local ab = entry.As(); // If we cannot render the ArrayBuffer unusable in this Isolate and // take ownership of its memory, copying the buffer will have to do. - if (!ab->IsNeuterable() || ab->IsExternal()) + if (!ab->IsNeuterable() || ab->IsExternal() || + !env->isolate_data()->uses_node_allocator()) { continue; + } if (std::find(array_buffers.begin(), array_buffers.end(), ab) != array_buffers.end()) { ThrowDataCloneException(