diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-18 22:58:27 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-25 02:01:11 +0100 |
commit | 84e02b178ad14fae0df2a514e8a39bfa50ffdc2d (patch) | |
tree | ddc0435b6bd0b7811e0bf47687777c56b2857fd0 /src/node_internals.h | |
parent | 6c257cdf271384555d0ced77104a1d6b0480e246 (diff) | |
download | android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.tar.gz android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.tar.bz2 android-node-v8-84e02b178ad14fae0df2a514e8a39bfa50ffdc2d.zip |
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_internals.h')
-rw-r--r-- | src/node_internals.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/node_internals.h b/src/node_internals.h index 9ac2b0a331..82cf5713e9 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -146,10 +146,12 @@ v8::MaybeLocal<v8::Object> New(Environment* env, size_t length, void (*callback)(char* data, void* hint), void* hint); -// Takes ownership of |data|. Must allocate |data| with malloc() or realloc() -// because ArrayBufferAllocator::Free() deallocates it again with free(). -// Mixing operator new and free() is undefined behavior so don't do that. -v8::MaybeLocal<v8::Object> New(Environment* env, char* data, size_t length); +// Takes ownership of |data|. Must allocate |data| with the current Isolate's +// ArrayBuffer::Allocator(). +v8::MaybeLocal<v8::Object> New(Environment* env, + char* data, + size_t length, + bool uses_malloc); // Construct a Buffer from a MaybeStackBuffer (and also its subclasses like // Utf8Value and TwoByteValue). @@ -167,7 +169,7 @@ static v8::MaybeLocal<v8::Object> New(Environment* env, const size_t len_in_bytes = buf->length() * sizeof(buf->out()[0]); if (buf->IsAllocated()) - ret = New(env, src, len_in_bytes); + ret = New(env, src, len_in_bytes, true); else if (!buf->IsInvalidated()) ret = Copy(env, src, len_in_bytes); |