diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-19 00:58:27 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-25 04:01:11 +0300 |
commit | 84e02b178ad14fae0df2a514e8a39bfa50ffdc2d (patch) | |
tree | ddc0435b6bd0b7811e0bf47687777c56b2857fd0 /src/node_messaging.cc | |
parent | 6c257cdf271384555d0ced77104a1d6b0480e246 (diff) |
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
PR-URL: https://github.com/nodejs/node/pull/26207
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_messaging.cc')
-rw-r--r-- | src/node_messaging.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/node_messaging.cc b/src/node_messaging.cc index c659ac06f1d..34977557c5b 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -144,6 +144,9 @@ MaybeLocal<Value> Message::Deserialize(Environment* env, continue; } + env->isolate_data()->node_allocator()->RegisterPointer( + array_buffer_contents_[i].data, array_buffer_contents_[i].size); + Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), array_buffer_contents_[i].release(), @@ -367,6 +370,11 @@ Maybe<bool> Message::Serialize(Environment* env, // it inaccessible in this Isolate. ArrayBuffer::Contents contents = ab->Externalize(); ab->Neuter(); + + CHECK(env->isolate_data()->uses_node_allocator()); + env->isolate_data()->node_allocator()->UnregisterPointer( + contents.Data(), contents.ByteLength()); + array_buffer_contents_.push_back( MallocedBuffer<char> { static_cast<char*>(contents.Data()), contents.ByteLength() }); |