Use Node's memory allocator for ArrayBuffer

For Buffers created in Node, they are usually allocated in Node and
freed by Chromium's allocator, which will cause crashes when Node and
Chromium are using different allocators.

This commit makes Chromium use Node' allocator for ArrayBuffers.
This commit is contained in:
Cheng Zhao 2017-05-09 14:12:39 +09:00
parent 8be4332765
commit efe23b7595
4 changed files with 57 additions and 2 deletions

View file

@ -14,6 +14,14 @@ class Environment;
namespace atom {
// ArrayBuffer's allocator, used on Chromium's side.
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
void* Allocate(size_t length) override;
void* AllocateUninitialized(size_t length) override;
void Free(void* data, size_t length) override;
};
// Manage the V8 isolate and context automatically.
class JavascriptEnvironment {
public:
@ -31,6 +39,7 @@ class JavascriptEnvironment {
bool Initialize();
bool initialized_;
ArrayBufferAllocator allocator_;
gin::IsolateHolder isolate_holder_;
v8::Isolate* isolate_;
v8::Isolate::Scope isolate_scope_;