src: allocate Buffer memory using ArrayBuffer allocator
This PR allows using an ArrayBuffer
allocator that was not provided by Node.js itself, and may not be malloc()
-compatible.
The target use case are embedders like Electron, which is currently floating patches on top of Node and V8 in order to achieve this (fyi @codebytere).
[The first commit is #26201 in order to avoid conflicts]
deps: V8: cherry-pick d3308d0
Original commit message:
[api] Add
Isolate::GetArrayBufferAllocator()
This allows non-monolithic embedders to always allocate memory for ArrayBuffer instances using the right allocation method.
This is based on a patch that Electron is currently using.
Refs: https://github.com/v8/v8/commit/d3308d042c9637958491333831c33335ab9fc734
src: make IsolateData store ArrayBufferAllocator
This enables us to identify whether we are using an
allocator that we know more about than what the generic
ArrayBuffer::Allocator
API provides, in particular
whether it is malloc()
-compatible.
worker: copy transferList ArrayBuffers on unknown allocator
If the ArrayBuffer::Allocator
used to create ArrayBuffer
s
in the current Isolate
is not a Node.js ArrayBufferAllocator
,
we cannot know that it is malloc()
-based, an in particular it might
not be compatible with the ArrayBuffer::Allocator
on the receiving
end of the connection.
src: add debugging array allocator
Add a subclass of ArrayBufferAllocator
that performs additional
debug checking, which in particular verifies that:
- All
ArrayBuffer
backing stores have been allocated with this allocator, or have been explicitly marked as coming from a compatible source. - All memory allocated by the allocator has been freed once it is destroyed.
src: add allocation utils to env
Add a RAII utility for managing blocks of memory that have
been allocated with the ArrayBuffer::Allocator
for a given
Isolate
.
src: allocate Buffer memory using ArrayBuffer allocator
Always use the right allocator for memory that is turned into
an ArrayBuffer
at a later point.
This enables embedders to use their own ArrayBuffer::Allocator
s,
and is inspired by Electron’s electron/node@f61bae3440e. It should
render their downstream patch unnecessary.
Refs: https://github.com/electron/node/commit/f61bae3440e1bfcc83bba6ff0785adfb89b4045e
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines