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:
parent
8be4332765
commit
efe23b7595
4 changed files with 57 additions and 2 deletions
|
@ -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_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue